Skip to content

Commit

Permalink
Add CSP frame-ancestors for #537
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Feb 21, 2023
1 parent 2daa4f9 commit 66fafd3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion snappymail/v/0.0.0/app/libraries/snappymail/http/csp.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class CSP
$img = ["'self'", 'data:'],
$style = ["'self'", "'unsafe-inline'"],
$frame = [],
$frame_ancestors = [],

$report = false,
$report_to = [],
Expand All @@ -29,7 +30,7 @@ function __construct(string $default = '')
if ($default) {
foreach (\explode(';', $default) as $directive) {
$values = \explode(' ', $directive);
$name = \preg_replace('/-.+/', '', \trim(\array_shift($values)));
$name = \str_replace('-', '_', \preg_replace('/-(src)$/D', '', \trim(\array_shift($values))));
$this->$name = \array_unique(\array_merge($this->$name, $values));
}
}
Expand All @@ -53,6 +54,9 @@ function __toString() : string
if ($this->frame) {
$params[] = 'frame-src ' . \implode(' ', \array_unique($this->frame));
}
if ($this->frame_ancestors) {
$params[] = 'frame-ancestors ' . \implode(' ', \array_unique($this->frame_ancestors));
}

// Deprecated
if ($this->report) {
Expand Down

0 comments on commit 66fafd3

Please sign in to comment.