Skip to content

Incorrect hashes generated causing CSP violations #126

@warnyul

Description

@warnyul

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 generated index.html into an online CSP hash generator, I get different hash values. When I manually replace the generated hashes in index.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 [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

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:

  1. Clone the reproduction repository: git clone https://github.com/warnyul/bvarga.dev.git
  2. Install dependencies: npm install
  3. Build the project: npm run build
  4. Open index.html in dist 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions