@@ -46,6 +46,10 @@ class ContentSecurityPolicy
4646 'sandbox ' => 'sandbox ' ,
4747 'manifest-src ' => 'manifestSrc ' ,
4848 'script-src-elem ' => 'scriptSrcElem ' ,
49+ 'script-src-attr ' => 'scriptSrcAttr ' ,
50+ 'style-src-elem ' => 'styleSrcElem ' ,
51+ 'style-src-attr ' => 'styleSrcAttr ' ,
52+ 'worker-src ' => 'workerSrc ' ,
4953 ];
5054
5155 /**
@@ -191,7 +195,38 @@ class ContentSecurityPolicy
191195 *
192196 * @var array<string, bool>|string
193197 */
194- protected $ scriptSrcElem = [];
198+ protected array |string $ scriptSrcElem = [];
199+
200+ /**
201+ * The `script-src-attr` directive applies to event handlers and, if present,
202+ * it will override the `script-src` directive for relevant checks.
203+ *
204+ * @var array<string, bool>|string
205+ */
206+ protected array |string $ scriptSrcAttr = [];
207+
208+ /**
209+ * The `style-src-elem` directive governs the behaviour of styles except
210+ * for styles defined in inline attributes.
211+ *
212+ * @var array<string, bool>|string
213+ */
214+ protected array |string $ styleSrcElem = [];
215+
216+ /**
217+ * The `style-src-attr` directive governs the behaviour of style attributes.
218+ *
219+ * @var array<string, bool>|string
220+ */
221+ protected array |string $ styleSrcAttr = [];
222+
223+ /**
224+ * The `worker-src` directive restricts the URLs which may be loaded as a `Worker`,
225+ * `SharedWorker`, or `ServiceWorker`.
226+ *
227+ * @var array<string, bool>|string
228+ */
229+ protected array |string $ workerSrc = [];
195230
196231 /**
197232 * Instructs user agents to rewrite URL schemes by changing HTTP to HTTPS.
@@ -678,16 +713,28 @@ public function addScriptSrc($uri, ?bool $explicitReporting = null)
678713 * @see https://www.w3.org/TR/CSP/#directive-script-src-elem
679714 *
680715 * @param list<string>|string $uri
681- *
682- * @return $this
683716 */
684- public function addScriptSrcElem ($ uri , ?bool $ explicitReporting = null )
717+ public function addScriptSrcElem (array | string $ uri , ?bool $ explicitReporting = null ): static
685718 {
686719 $ this ->addOption ($ uri , 'scriptSrcElem ' , $ explicitReporting ?? $ this ->reportOnly );
687720
688721 return $ this ;
689722 }
690723
724+ /**
725+ * Adds a new value to the `script-src-attr` directive.
726+ *
727+ * @see https://www.w3.org/TR/CSP/#directive-script-src-attr
728+ *
729+ * @param list<string>|string $uri
730+ */
731+ public function addScriptSrcAttr (array |string $ uri , ?bool $ explicitReporting = null ): static
732+ {
733+ $ this ->addOption ($ uri , 'scriptSrcAttr ' , $ explicitReporting ?? $ this ->reportOnly );
734+
735+ return $ this ;
736+ }
737+
691738 /**
692739 * Adds a new value to the `style-src` directive.
693740 *
@@ -704,6 +751,48 @@ public function addStyleSrc($uri, ?bool $explicitReporting = null)
704751 return $ this ;
705752 }
706753
754+ /**
755+ * Adds a new value to the `style-src-elem` directive.
756+ *
757+ * @see https://www.w3.org/TR/CSP/#directive-style-src-elem
758+ *
759+ * @param list<string>|string $uri
760+ */
761+ public function addStyleSrcElem (array |string $ uri , ?bool $ explicitReporting = null ): static
762+ {
763+ $ this ->addOption ($ uri , 'styleSrcElem ' , $ explicitReporting ?? $ this ->reportOnly );
764+
765+ return $ this ;
766+ }
767+
768+ /**
769+ * Adds a new value to the `style-src-attr` directive.
770+ *
771+ * @see https://www.w3.org/TR/CSP/#directive-style-src-attr
772+ *
773+ * @param list<string>|string $uri
774+ */
775+ public function addStyleSrcAttr (array |string $ uri , ?bool $ explicitReporting = null ): static
776+ {
777+ $ this ->addOption ($ uri , 'styleSrcAttr ' , $ explicitReporting ?? $ this ->reportOnly );
778+
779+ return $ this ;
780+ }
781+
782+ /**
783+ * Adds a new value to the `worker-src` directive.
784+ *
785+ * @see https://www.w3.org/TR/CSP/#directive-worker-src
786+ *
787+ * @param list<string>|string $uri
788+ */
789+ public function addWorkerSrc ($ uri , ?bool $ explicitReporting = null ): static
790+ {
791+ $ this ->addOption ($ uri , 'workerSrc ' , $ explicitReporting ?? $ this ->reportOnly );
792+
793+ return $ this ;
794+ }
795+
707796 /**
708797 * Sets whether the user agents should rewrite URL schemes, changing HTTP to HTTPS.
709798 *
0 commit comments