Skip to content

Commit

Permalink
Change csp
Browse files Browse the repository at this point in the history
- Add allowinline = False
- Add scriptdomains
  • Loading branch information
MrKampf committed Jun 7, 2023
1 parent 7928f7c commit 5d906d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 0 additions & 1 deletion lib/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ public function getTrustedFontUrls(){
public function getTrustedImageUrls(){
return $this->config->getSystemValue('trusted_image_urls');
}

}
11 changes: 7 additions & 4 deletions lib/Listener/CSPListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@ public function handle(Event $event): void {
}

$policy = new EmptyContentSecurityPolicy();
$policy->allowInlineScript(false);
$policy->useStrictDynamic(true);

$trustedImageUrls= $this->config->getTrustedFontUrls();
foreach ($trustedImageUrls as $trusted_url) {
foreach ($this->config->getSystemValue('trusted_script_urls') as $trusted_url) {
$policy->addAllowedScriptDomain($trusted_url);
}

foreach ($this->config->getTrustedFontUrls() as $trusted_url) {
$policy->addAllowedFontDomain($trusted_url);
}

$trustedFontUrls = $this->config->getTrustedImageUrls();
foreach ($trustedFontUrls as $image_url) {
foreach ($this->config->getTrustedImageUrls() as $image_url) {
$policy->addAllowedImageDomain($image_url);
}
$event->addPolicy($policy);
Expand Down

0 comments on commit 5d906d2

Please sign in to comment.