#54214 closed enhancement (duplicate)
Make it posible to add custom attribute to inline script
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Script Loader | Keywords: | close |
Focuses: | Cc: |
Description
Currently All wordpress sites in the world will not pass Google LightHouse 'best practice' test. It will always fail "Ensure CSP is effective against XSS attacks"
The problem is. To enable CSP we need to add 'nonce' attributes to all <script> tag. (https://web.dev/csp-xss/?utm_source=lighthouse&utm_medium=devtools)
We can only add this to external script by hooking into 'script_loader_tag'.
But for inline script (which added using 'wp_add_inline_script') its not possible to add nonce attribute because its hardcoded by WP (https://github.com/WordPress/WordPress/blob/2cb4ebefe2ee98fc36a5962e92590cb0451ad2a6/wp-includes/class.wp-scripts.php#L365)
So currently no way for wordpress sites to apply CSP other than modifying core wp files directly.
Change History (4)
#2
@
3 years ago
Those functions were added specifically because of CSP.
The goal is to eventually convert all usage in WP core to use these functions.
Related: #51124