Skip to content

Commit cee9ac5

Browse files
mark-unwinpaulbalandan
authored andcommitted
feat: Add script-src-elem option to CSP options.
Signed-off-by: Mark Unwin <[email protected]>
1 parent 7b48592 commit cee9ac5

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

app/Config/ContentSecurityPolicy.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ class ContentSecurityPolicy extends BaseConfig
5656
*/
5757
public $scriptSrc = 'self';
5858

59+
/**
60+
* Lists allowed scripts' URLs.
61+
*
62+
* @var list<string>|string
63+
*/
64+
public $scriptSrcElem = 'self';
65+
5966
/**
6067
* Lists allowed stylesheets' URLs.
6168
*

system/HTTP/ContentSecurityPolicy.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class ContentSecurityPolicy
4242
'object-src' => 'objectSrc',
4343
'plugin-types' => 'pluginTypes',
4444
'script-src' => 'scriptSrc',
45+
'script-src-elem' => 'scriptSrcElem',
4546
'style-src' => 'styleSrc',
4647
'manifest-src' => 'manifestSrc',
4748
'sandbox' => 'sandbox',
@@ -153,6 +154,13 @@ class ContentSecurityPolicy
153154
*/
154155
protected $scriptSrc = [];
155156

157+
/**
158+
* Used for security enforcement
159+
*
160+
* @var array|string
161+
*/
162+
protected $scriptSrcElem = [];
163+
156164
/**
157165
* The `style-src` directive restricts which styles the user may applies to the protected resource.
158166
*
@@ -649,6 +657,23 @@ public function addScriptSrc($uri, ?bool $explicitReporting = null)
649657
return $this;
650658
}
651659

660+
/**
661+
* Adds a new valid endpoint for javascript file sources. Can be either
662+
* a URI class or a simple string.
663+
*
664+
* @see https://www.w3.org/TR/CSP/#directive-script-src-elem
665+
*
666+
* @param array|string $uri
667+
*
668+
* @return $this
669+
*/
670+
public function addScriptSrcElem($uri, ?bool $explicitReporting = null)
671+
{
672+
$this->addOption($uri, 'scriptSrcElem', $explicitReporting ?? $this->reportOnly);
673+
674+
return $this;
675+
}
676+
652677
/**
653678
* Adds a new value to the `style-src` directive.
654679
*

0 commit comments

Comments
 (0)