One of my clients has a CSP policy that is VERY tight. And it makes it so all inline scripts are declined.
So i'm looking in adding a hash or nonce to all scripts on the page, whatever is their origin (I've got some coming from things like WPML and Litespeed cache, so I can't really just manually go add it with a hook every time)
One of my clients has a CSP policy that is VERY tight. And it makes it so all inline scripts are declined.
So i'm looking in adding a hash or nonce to all scripts on the page, whatever is their origin (I've got some coming from things like WPML and Litespeed cache, so I can't really just manually go add it with a hook every time)
In case you need to add SRI to script file resources, this great approach should do the trick.
https://joshuatz.com/posts/2020/adding-extra-attributes-to-style-and-script-tags-in-wordpress/
It provides a tool to add any attribute to script and style elements added by wp_enqueue_, and has a good example there, with exactly this thought in mind.
One caveat is it works for scripts in the head and maybe not in the body right now.
*For inline scripts, I am still looking for a good solution myself.
I have been trying to do the same thing and recently stumbled across this wordpress plugin that claims to support the creation of a Strict CSP.
https://wordpress.org/plugins/no-unsafe-inline/
It looks to still be in the early stages of development, but the reviews are positive. I will be testing on a non production server shortly.