Skip to content

Commit

Permalink
PLANET-7675: Add vwo expection to CSP list (#2482)
Browse files Browse the repository at this point in the history
Ref: https://jira.greenpeace.org/browse/PLANET-7675

Add vwo expection to CSP list

- Add it into the Content Security Policy list and used to run A/B testing with VWO
- New p4 option variable
  • Loading branch information
GP-Dan-Tovbein authored Dec 18, 2024
1 parent bad7c6a commit c5b779c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/HttpHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public function send_content_security_policy_header(array $headers): array
'frame-ancestors ' . implode(' ', $allowed_frame_ancestors),
];

// Add VWO exception to CSP list
$enable_vwo = planet4_get_option('enable_vwo') === 'on';
if ($enable_vwo) {
// phpcs:disable Generic.Files.LineLength.MaxExceeded
$directives[0] = $directives[0] . ' blob: *.visualwebsiteoptimizer.com *visualwebsiteoptimizer.com app.vwo.com useruploads.vwo.io';
}

$csp_header = implode('; ', $directives);
$csp_header = preg_replace("/\r|\n/", '', $csp_header);

Expand Down
9 changes: 9 additions & 0 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,15 @@ public function __construct()
'id' => 'about_us_page',
'type' => $is_new_ia ? 'about_us_page_dropdown' : 'hidden',
],
[
'name' => __('VWO A/B testing', 'planet4-master-theme-backend'),
'desc' => __(
'Adds a Content Security Policy exception for VWO.',
'planet4-master-theme-backend'
),
'id' => 'enable_vwo',
'type' => 'checkbox',
],
],
],
'planet4_settings_features' => Features::get_options_page(),
Expand Down

0 comments on commit c5b779c

Please sign in to comment.