Repository navigation
fix: drop style-src 'unsafe-inline' from the CSP - #23
Merged
Merged
Conversation
Five style attributes in each home page and one in the demo's step icon markup kept 'unsafe-inline' in the CSP. They are now classes in sanad.css, so the CSP can use style-src 'self'. - Home pages (uz, en, ru): the chain traveller, the demo meta line and the Telegram heading and lead use classes; the computed styles are unchanged. - sanad-core.js: the step "x" icon gets position:absolute from .st .i-x. - favicon.svg keeps its <style> (it switches colours for dark mode); the CSP allows exactly that block by its sha256 hash. - tools/check-site.mjs fails on a style attribute or <style> in a page, a style attribute in script markup, and an SVG <style> whose hash is not in the CSP, so an inline style cannot come back unnoticed. - ASSURANCE.md: the residual risk is closed; CONTRIBUTING and CHANGELOG describe the stricter policy. Closes #7 Signed-off-by: ismoilovdevml <ismoilovdevarchlinux@gmail.com>
main already has the same CSP change from #22. This keeps main's version and adds what is new here: check-site also fails on setAttribute('style', ...) in scripts. Signed-off-by: xnosir <283333996+xnosir@users.noreply.github.com>
xnosir
approved these changes
Nov 14, 2026
xnosir
left a comment
Member
There was a problem hiding this comment.
Thank you! main already had the same CSP change from #22, so I merged main into your branch (you allowed maintainer edits) and kept what is new here: check-site now also fails on setAttribute('style', ...). Checked with a negative test; CI green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
The CSP allowed
style-src 'unsafe-inline'because of fivestyleattributes in each home page and one in the step-icon markup built bysanad-core.js(residual risk indocs/ASSURANCE.md). They are now classes insanad.css, and the CSP isstyle-src 'self'plus the hash of the favicon's<style>.opacity:0, rect fill), the demo meta line, and the Telegram heading and lead use CSS rules instead ofstyleattributes.main.jsstill animates the traveller through CSSOM (style.opacity), which the CSP allows.sanad-core.js: the step "x" icon getsposition: absolutefrom.steps .st .i-x.favicon.svgkeeps its<style>(it switches colours for dark mode). The CSP allows exactly that block by its sha256 hash:'sha256-y8K55UD19BmUb/68u/uDinnnnZwD4JjBVgr61zWsTLw='.tools/check-site.mjsnow fails on:styleattribute or<style>element in a page,styleattribute in markup built in a script, orsetAttribute('style', …),<style>whose hash is not in the CSP (the message prints the hash to add).ASSURANCE.md; CONTRIBUTING and CHANGELOG describe the stricter policy.Verification
node tools/check-site.mjscheck-sitenegative tests:style=inen/index.html,style=back insanad-core.js, a colour changed infavicon.svgnpm run lintnpm test(43 unit + 29 e2e under the Caddyfile CSP + coverage gate)/,/en/,/ru/at 1280px and 390px, main vs this branchChecklist
node tools/check-site.mjsandnpm testpasscheck-site.mjsrules, run in CI)/,/en/,/ru/) are updated where neededCHANGELOG.mdunder [Unreleased]git commit -s, DCO)innerHTMLwith data (docs/ASSURANCE.md)Related issue: Closes #7