fix(@angular/build): normalize line endings for CSP hash generation#32712
Merged
clydin merged 1 commit intoangular:mainfrom Mar 6, 2026
Merged
fix(@angular/build): normalize line endings for CSP hash generation#32712clydin merged 1 commit intoangular:mainfrom
clydin merged 1 commit intoangular:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request addresses an issue with Content Security Policy (CSP) hash generation for files using CRLF line endings by normalizing script content to LF before hashing. However, the current approach misses standalone carriage returns (CR), which also require robust normalization to prevent potential CSP violations. Additionally, a security vulnerability was identified in the shouldDynamicallyLoadScriptTagBasedOnType function, allowing for potential Cross-Site Scripting (XSS) via malicious type attributes in script tags; tightening the validation of script types is recommended to mitigate this risk. The pull request also includes several beneficial refactorings in the test suite.
When `autoCsp` reads an `index.html` with CRLF line endings, it generates hashes based on the CRLF content. However, the transformed file is always written with LF line endings, causing CSP violations. This commit ensures that script content line endings are normalized to LF before hashing to match the output file. Closes angular#32709
clydin
approved these changes
Mar 6, 2026
Member
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.
When
autoCspreads anindex.htmlwith CRLF line endings, it generates hashes based on the CRLF content. However, the transformed file is always written with LF line endings, causing CSP violations.This commit ensures that script content line endings are normalized to LF before hashing to match the output file.
Closes #32709