You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks a lot for building and maintaining Astro-Shield! It has helped me integrating CSP into my static websites.
I recently came across a very specific issue where CSP is at odds with inline style of code syntax highlighting in Astro. Here's the breakdown:
Astro's code syntax highlighting (such as pre-bundled shiki or astro-expressive-code) produces the HTML output where <span> tokens that contains inline styles.
I use Astro-Shield to generate SRI hashes and also use its Netlify integration to generate _headers file which, according to my understanding, contains generated CSP headers for each of the pages.
For completeness, my configuration looks like the following:
Deploying this website (minimal example) on Netlify results in syntax highlighting missing their colors. The browser tells me that 'unsafe-inline' under style-src is ignored because SRI hashes (or nonce) exist. That's obvious my website contains <style> tags in other parts of the page, thus the hash was generated.
Obviously, everything is working as intended. However, I wish that Astro-Shield provides some more granular control via config over how SRI hashes are injected into CSP headers. Particularly
An option to leave style-src untouched when generating CSP headers so that my website can use 'unsafe-inline'. For example:
I know that 'unsafe-inline' is not the best settings to use, but using it only for style-src: but not script-src: is an acceptable risk for me. (HTTP Observatory also seems to strongly concern more about script-src:.)
Any tips, suggestions, or workaround is also appreciated.
The text was updated successfully, but these errors were encountered:
Hi Astro-Shield Maintainers!
Thanks a lot for building and maintaining Astro-Shield! It has helped me integrating CSP into my static websites.
I recently came across a very specific issue where CSP is at odds with inline style of code syntax highlighting in Astro. Here's the breakdown:
Astro's code syntax highlighting (such as pre-bundled shiki or astro-expressive-code) produces the HTML output where
<span>
tokens that contains inline styles.Here is one example:
I use Astro-Shield to generate SRI hashes and also use its Netlify integration to generate
_headers
file which, according to my understanding, contains generated CSP headers for each of the pages.For completeness, my configuration looks like the following:
and the generated
_headers
(partial):The only thing to note from the above is this part:
Deploying this website (minimal example) on Netlify results in syntax highlighting missing their colors. The browser tells me that
'unsafe-inline'
understyle-src
is ignored because SRI hashes (or nonce) exist. That's obvious my website contains<style>
tags in other parts of the page, thus the hash was generated.Obviously, everything is working as intended. However, I wish that Astro-Shield provides some more granular control via config over how SRI hashes are injected into CSP headers. Particularly
I know that
'unsafe-inline'
is not the best settings to use, but using it only forstyle-src:
but notscript-src:
is an acceptable risk for me. (HTTP Observatory also seems to strongly concern more aboutscript-src:
.)Any tips, suggestions, or workaround is also appreciated.
The text was updated successfully, but these errors were encountered: