fix(admin): normalize line endings before hashing CSP script - #526
Open
SomSamantray wants to merge 1 commit into
Open
fix(admin): normalize line endings before hashing CSP script#526SomSamantray wants to merge 1 commit into
SomSamantray wants to merge 1 commit into
Conversation
Browsers normalize \r\n and bare \r to \n before hashing an inline <script>'s content for CSP purposes. The admin server was hashing the raw extracted script bytes, so a CRLF checkout (e.g. Windows with core.autocrlf=true) produced a script-src hash that never matched what the browser computed, blocking the admin shell's inline script. Extract the hashing into hashAdminScript(), which normalizes line endings before hashing, and add a regression test proving CRLF/CR/LF variants of the same script hash identically and that the live server's CSP header matches the on-disk script. Fixes yc-software#232
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.
Summary
core.autocrlf=true) breaks the admin shell's inline script, because the server hashes the raw on-disk bytes of the script for its CSPscript-src 'sha256-...'header, while browsers normalize\r\n/\rto\nbefore hashing inline script content per spec — the two hashes never match, so the CSP silently blocks the script.hashAdminScript()helper (plugins/admin/src/index.ts) that normalizes line endings before hashing, so the computed CSP hash always matches what a browser will compute regardless of on-disk line-ending style.Test plan
plugins/admin/test/csp-hash.test.ts:content-security-policyresponse header'sscript-srchash matcheshashAdminScript()computed over the real on-disk script.NODE_ENV=test ALLOW_UNSIGNED_TEST_IDENTITY=1 npm test→ 83/83 passing, no regressions.npm run typecheck→ clean.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.