I'm confused about Jenkins Content Security Policy.
I know these sites:
I have a html page shown via Jenkins Clover Plugin. This html page uses inline style, e.g.:
<div class='greenbar' style='width:58px'>
The div-element visualizes a progressbar. Using the default Jenkins CSP configuration leads to the following result: Progressbar_FAIL
The result i want to have looks like this: Progressbar_WORKS
I tried to relax the CSP rules, adding different combinations of parameters (script-src, style-src) with different levels (self, unsafe-inline,..) but nothing works.
So my questions for now:
Update
1. Try: -Dhudson.model.DirectoryBrowserSupport.CSP="default-src 'self'
in the jenkins.xml file. Then the following error occurs:
Refused to apply inline style because it violates the following Content Security Policy directive: "default-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-'), or a nonce ('nonce-...') is required to enable inline execution. Note also that 'style-src' was not explicitly set, so 'default-src' is used as a fallback.
2. Try -Dhudson.model.DirectoryBrowserSupport.CSP="default-src 'self'; style-src 'self'
in the jenkins.xml file. Then the following error occurs:
Refused to apply inline style because it violates the following Content Security Policy directive: "style-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-'), or a nonce ('nonce-...') is required to enable inline execution
I understand that this try can not solve my problem, because default-src includes style-src
3. Try -Dhudson.model.DirectoryBrowserSupport.CSP="default-src 'self'; style-src 'unsafe-inline'
in the jenkins.xml file. Then the following error occurs:
Refused to load the stylesheet s://jenkins/andsomedir/stylesheet.css [its https://... not allowed to post more than two links :(] because it violates the following Content Security Policy directive: "style-src 'unsafe-inline'".
The Jenkins default Content Security Policy is: sandbox; default-src 'none'; img-src 'self'; style-src 'self'; The above rules do not allow to run JavaScript, use of inline CSS or of web fonts. The Web Report is generated dynamically through JavaScript code based on tests results stored in the file data/results-v1.
While experimenting, I recommend using the Script Console to adjust the CSP parameter dynamically as described on the Configuring Content Security Policy page. (There's another note in the Jenkins wiki page that indicates you may need to Force Reload the page to see the new settings.)
In order to use both inline styles and local stylesheets, you need to add both self and unsafe-inline:
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "default-src 'self'; style-src 'self' 'unsafe-inline';")
Depending on how the progressbar is manipulated, you may need to adjust 'script-src' in the same way as well.
Once you find a setting that works, you can adjust the Jenkins startup script to add the CSP parameter definition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With