diff --git a/lib/Constants.php b/lib/Constants.php index 5debb548b..72d1a0259 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -110,9 +110,11 @@ class Constants { public const ANSWER_TYPE_LONG = 'long'; public const ANSWER_TYPE_MULTIPLE = 'multiple'; public const ANSWER_TYPE_MULTIPLEUNIQUE = 'multiple_unique'; + public const ANSWER_TYPE_IMAGE = 'image'; public const ANSWER_TYPE_RANKING = 'ranking'; public const ANSWER_TYPE_SHORT = 'short'; public const ANSWER_TYPE_TIME = 'time'; + public const ANSWER_TYPE_VIDEO = 'video'; public const ANSWER_GRID_TYPE_CHECKBOX = 'checkbox'; public const ANSWER_GRID_TYPE_NUMBER = 'number'; @@ -149,9 +151,11 @@ class Constants { self::ANSWER_TYPE_LONG, self::ANSWER_TYPE_MULTIPLE, self::ANSWER_TYPE_MULTIPLEUNIQUE, + self::ANSWER_TYPE_IMAGE, self::ANSWER_TYPE_RANKING, self::ANSWER_TYPE_SHORT, self::ANSWER_TYPE_TIME, + self::ANSWER_TYPE_VIDEO, ]; // AnswerTypes, that need/have predefined Options @@ -276,6 +280,32 @@ class Constants { 'next' => ['integer', 'string'], ]; + /** + * Display-only blocks carry no answer; they reference something to show and may jump on with `next`. + */ + public const EXTRA_SETTINGS_MEDIA = [ + 'url' => ['string', 'NULL'], + 'alt' => ['string', 'NULL'], + 'next' => ['integer', 'string'], + ]; + + /** + * Origins of the video players a video block may load after the respondent agrees. + */ + public const VIDEO_PLAYER_ORIGINS = [ + 'https://www.youtube-nocookie.com', + 'https://player.vimeo.com', + ]; + + /** + * Question types that are shown but never answered, so they are skipped when + * validating a submission and left out of exports. + */ + public const ANSWER_TYPES_DISPLAY_ONLY = [ + self::ANSWER_TYPE_IMAGE, + self::ANSWER_TYPE_VIDEO, + ]; + public const EXTRA_SETTINGS_RANKING = [ 'shuffleOptions' => ['boolean'], 'next' => ['integer', 'string'], diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index ef0b54e5b..4aa105fa4 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -85,10 +85,13 @@ public function index(?string $hash = null): TemplateResponse { } } - return new TemplateResponse($this->appName, self::TEMPLATE_MAIN, [ + $response = new TemplateResponse($this->appName, self::TEMPLATE_MAIN, [ 'id-app-content' => '#app-content-vue', 'id-app-navigation' => '#app-navigation-vue', ]); + $response->setContentSecurityPolicy($this->createPolicy()); + + return $response; } /** @@ -219,7 +222,10 @@ protected function createPublicSubmitView(Form $form, string $hash): TemplateRes $this->initialState->provideInitialState('isLoggedIn', $this->userSession->isLoggedIn()); $this->initialState->provideInitialState('shareHash', $hash); $this->initialState->provideInitialState('maxStringLengths', Constants::MAX_STRING_LENGTHS); - return $this->provideTemplate(self::TEMPLATE_MAIN, $form, ['id-app-navigation' => null]); + $response = $this->provideTemplate(self::TEMPLATE_MAIN, $form, ['id-app-navigation' => null]); + $response->setContentSecurityPolicy($this->createPolicy()); + + return $response; } /** @@ -293,13 +299,25 @@ protected function insertHeaderOnIos(): void { } } + /** + * Create the CSP for pages showing a form, allowing the players of video blocks as frames + */ + protected function createPolicy(): ContentSecurityPolicy { + $policy = new ContentSecurityPolicy(); + foreach (Constants::VIDEO_PLAYER_ORIGINS as $origin) { + $policy->addAllowedFrameDomain($origin); + } + + return $policy; + } + /** * Set CSP options to allow the page be embedded using