-
Notifications
You must be signed in to change notification settings - Fork 41
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
Incorrect hashes generated causing CSP violations #126
Comments
I investigated further and logged the generated hashes in the |
It seems that removing the following SCSS definitions resolves the issue. With these definitions removed, the CSP plugin and the inline CSS plugin use the same CSS, resulting correct hashes: > * {
// style definition
} |
I think I’ve identified the root cause of the CSP violations. It’s related to cheerio when This transformation causes a mismatch between the original tag content (used to generate the CSP hash) and the altered content in the output, resulting in CSP violations. We’ll need to address this to ensure the CSP matches the actual content of the tags. |
Description
The
CspHtmlWebpackPlugin
generates incorrect hashes, causing issues when trying to use the generated CSP.I have created a GitHub repository to reproduce the issue and deployed the site for reference:
My observations
If I copy the content of the
<style>
or<script>
tags from the generatedindex.html
into an online CSP hash generator, I get different hash values. When I manually replace the generated hashes inindex.html
with these correct values, my site works as expected without CSP violations.I could not prove it but maybe the issue is related to #111
What type of issue is this? (place an
x
in one of the[ ]
)Requirements (place an
x
in each of the[ ]
)Bug Report
Reproducible in:
slackhq/csp-html-webpack-plugin version: 5.1.0
node version: 22.10.0
OS version(s): macOS Sequoia 15.01, Ubuntu 24.04
Steps to reproduce:
git clone https://github.com/warnyul/bvarga.dev.git
npm install
npm run build
index.html
indist
folder using Safari or Google Chrome.Expected result:
The hashes generated by the
CspHtmlWebpackPlugin
should correctly match the content of the built files.Actual result:
The hashes generated by the plugin do not match the content of the files, causing CSP violations in the browser when accessing the deployed site. Manually generated hashes work correctly when applied.
The text was updated successfully, but these errors were encountered: