With the update to A12 2022-06 & the migration to styled components several projects where faced with the following issue when deploying on secured environments:
If a ContentSecurityPolicy is used, the shift to Styled components requires the CSP to allow inline styles. Otherwise the BAP Client won’t run in the dedicated environments and break with an error.
The current “shortcut” used by the projects I mentioned was to set the CSP directive ‘style-src’ to 'unsafe-inline` which is only a quick workaround - We need a general solution (using nonce) that should be added to the A12 documentation in order to prepare and give guidance to upcoming projects.
Currently the requirement for the CSP cannot be found in the A12 documentation / migration notes
thanks for pointing on that issue. Please keep in mind that a12 discourse is meant as platform for problem specific exchange. If you think you have found an issue or a gap in a12 please create an a12 ticket for that.
For CSP problem i already created the ticket body in A12-13965. I will continue to file the details but please feel free to extend the ticket with anything in interest for you or your project.
The hash calculation and CSP validation is only done when loading the page. Dynamically changed CSS does not change the hash and therefore does not interfere with the CSP. The styled-components CSS is only affecting the CSS Object Model (CSSOM).
From security point of view, having the hash of an empty style tag whitelisted in the CSP is not an issue.
It was verified that it is working on Chrome, Edge, Firefox on Windows, Chrome on Android, and Safari on macOS.
The solution by whitelisting the Empty styled tag is not sufficient for us. It works properly on Safari 16 and on Chrome, Firefox. But we still face the issue on Safari mobile - iOS 14.4 and Safari version 15 on MacOS (Catalina) (I don’t have a chance to test older versions)
After investigating on the issue, we can whitelist a style tag with content inside but not the empty tag.
I recently read that article Can you get pwned with CSS? and wonder based on its information if it will be enough for your project to set the style-src to unsafe-inline.
Since the issues with older versions of safari regarding the hashing of empty tags will not be resolved (at least in near future) i guess this could be a valid idea.