You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think I’ve identified the root cause of the CSP violations. It’s related to cheerio when _useHtmlParser2 is set to true. In this mode, cheerio modifies the content of <style> and <script> tags by replacing special characters like <, >, and & with their HTML entities (<, >, &).
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.
What type of issue is this? (place an x in one of the [ ])
bug
enhancement (feature request)
question
documentation related
testing related
discussion
Bug Report
Reproducible in:
@melloware/csp-webpack-plugin version: 6.0.4
node version: 22.10.0
OS version(s): macOS Sequoia 15.01, Ubuntu 24.04
Steps to reproduce:
Clone the reproduction repository: git clone https://github.com/warnyul/bvarga.dev.git
Checkout csp-2 branch: git checkout csp-2
Install dependencies: npm install
Build the project: npm run build
Open index.html in dist folder using Safari or Google Chrome.
Expected result:
The hashes generated by the @melloware/csp-webpack-plugin 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:
Description
The
@melloware/csp-webpack-plugin
generates incorrect hashes, resulting in CSP violations when using the generatedindex.html
file.This issue mirrors the problem described in the original issue raised for
slackhq/csp-html-webpack-plugin
:To help reproduce and diagnose the problem, I have created a GitHub repository and deployed the site for reference:
Observations
I think I’ve identified the root cause of the CSP violations. It’s related to cheerio when
_useHtmlParser2
is set totrue
. In this mode, cheerio modifies the content of<style>
and<script>
tags by replacing special characters like<
,>
, and&
with their HTML entities (<
,>
,&
).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.
What type of issue is this? (place an
x
in one of the[ ]
)Bug Report
Reproducible in:
@melloware/csp-webpack-plugin
version: 6.0.4node 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
csp-2
branch:git checkout csp-2
npm install
npm run build
index.html
indist
folder using Safari or Google Chrome.Expected result:
The hashes generated by the
@melloware/csp-webpack-plugin
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: