-
Notifications
You must be signed in to change notification settings - Fork 17
feat: Enable CSP with nonce for Helix 5 - 2nd try #816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #816 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 45 46 +1
Lines 3671 3914 +243
==========================================
+ Hits 3671 3914 +243 ☔ View full report in Codecov by Sentry. |
Two important changes as opposed to #773, which wasn't working in the CloudFlare:
npm install adobe/helix-html-pipeline#csp-nonce
npm run build
helix-aem-pipeline-worker tuicu$ npm run build
> helix-aem-pipeline-worker@1.1.81 build
> node build.js
bundled worker in 59 ms |
# [6.20.0](v6.19.1...v6.20.0) (2025-02-12) ### Features * Enable CSP with nonce for Helix 5 ([#816](#816)) ([3f4895f](3f4895f))
🎉 This PR is included in version 6.20.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
1. Description
'nonce-aem'
.Meta:
Header
nonce="aem"
on:head.html
Example:
move-as-header
attribute for the meta based CSP, where the Helix Pipeline will that tag as a headerNote: if this feature is premature, I can remove it and file it as a separate PR
Example:
aem
part of thenonce-aem
CSP and on each trusted script where it findsnonce="aem"
2. Implementation choice
After some back and forth between:
'nonce'
vs'nonce-aem'
as a keyword in the CSP'nonce="aem"
or not to the scripts, to make it as friction-less and transparent as possible for devs.I chose for the moment
'nonce-aem'
and needing to add'nonce="aem"
to the scripts, because in this implementation if there's any reason to deactivate/remove or if the hlx pipeline fails to render the nonce, customers that have this enabled will still have a valid page that is rendered by the browser.In the other variants, if for any reason
'nonce'
is returned the browser will show just a white page.3. Expected level of protection with a nonce cached on the CDN
1. Protected even if the nonce is cached
✅
.innerHTML
for XSS✅
.outerHTML
for XSS✅
.insertAdjecentHTML
for XSS✅
.setHTMLUnsafe
for XSS✅
eval
/setTimeout
/setInterval
/ Function for XSS✅
javascript:
protocol in the href/src attributes✅
location.href
/location.assign()
/location.replace
for XSS✅ attribute event handlers (
onclick
,onblur
,onload
,onerror
etc.) for XSS✅ stored/reflected XSS
2. not protected, because the nonce is cached
❌
document.write
/document.writeln
-> because you could get the nonce and use it in the exploit3.not protected for other reasons
❌
document.createRange().createContextualFragment
-> whether the nonce is cached/known is irrelevant, scripts are always executed withstrict-dynamic
. (needs ticket in https://github.com/w3c/webappsec-csp - awaiting OSS approval)❌
src
attribute of a<script>
tag created bydocument.createElement('script')
/ text content of a<script>
tag created bydocument.createElement('script')
/import
-> permitted bystrict-dynamic
4. not protected by CSPs in general
Script-less attacks
❌ HTML injection
❌ DOM clobbering
5. unknown status
❓
element.style
orcssText
-> still researching, can’t find a working exploit even without CSP4. Still TODO
5.x
branch.hlx-pipeline-version
)