Skip to content

Commit d7f145d

Browse files
committed
feat: Add script-src-elem option to CSP options.
1 parent 6e98ce5 commit d7f145d

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

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
@@ -47,6 +47,7 @@ class ContentSecurityPolicy
4747
'object-src' => 'objectSrc',
4848
'plugin-types' => 'pluginTypes',
4949
'script-src' => 'scriptSrc',
50+
'script-src-elem' => 'scriptSrcElem',
5051
'style-src' => 'styleSrc',
5152
'manifest-src' => 'manifestSrc',
5253
'sandbox' => 'sandbox',
@@ -144,6 +145,13 @@ class ContentSecurityPolicy
144145
*/
145146
protected $scriptSrc = [];
146147

148+
/**
149+
* Used for security enforcement
150+
*
151+
* @var array|string
152+
*/
153+
protected $scriptSrcElem = [];
154+
147155
/**
148156
* Used for security enforcement
149157
*
@@ -641,6 +649,23 @@ public function addScriptSrc($uri, ?bool $explicitReporting = null)
641649
return $this;
642650
}
643651

652+
/**
653+
* Adds a new valid endpoint for javascript file sources. Can be either
654+
* a URI class or a simple string.
655+
*
656+
* @see https://www.w3.org/TR/CSP/#directive-script-src-elem
657+
*
658+
* @param array|string $uri
659+
*
660+
* @return $this
661+
*/
662+
public function addScriptSrcElem($uri, ?bool $explicitReporting = null)
663+
{
664+
$this->addOption($uri, 'scriptSrcElem', $explicitReporting ?? $this->reportOnly);
665+
666+
return $this;
667+
}
668+
644669
/**
645670
* Adds a new valid endpoint for CSS file sources. Can be either
646671
* a URI class or a simple string.

0 commit comments

Comments
 (0)