Why is my Webpack nonce only applied to the first style tag and not all styles in the document?

I’m working with both a basic Webpack setup and a Laravel Mix project that includes React. I’m trying to apply a nonce attribute to all tags to comply with my Content Security Policy (CSP), but I’m encountering an issue where the nonce is only applied to the first tag generated by Webpack and not the subsequent ones.
I first attempted this with my Laravel Mix project, but after failing there, I set up a simple Webpack project to isolate the issue. While I managed to apply the nonce to one style tag in the basic Webpack setup, the rest of the styles generated do not receive the nonce, and multiple tags appear in the without the nonce.

Working Webpack configuration (simplified JS-only setup):

const { merge } = require('webpack-merge');
const common = require('./webpack.common');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = merge(common, {
  mode: 'development',
  devtool: 'inline-source-map',
  devServer: {
    contentBase: './dist',
  },
  module: {
    rules: [
      {
        test: /.(sa|sc|c)ss$/,
        use: [
          {
            loader: 'style-loader',
            options: {
              attributes: {
                nonce: '12345678',  // This is where I add the nonce
              },
            },
          },
          {
            loader: 'css-loader',
            options: {
              sourceMap: true,
            },
          },
          {
            loader: 'postcss-loader',
            options: {
              sourceMap: true,
            },
          },
          {
            loader: 'sass-loader',
            options: {
              sourceMap: true,
            },
          },
        ],
      },
    ],
  },
});

In this setup, the nonce is applied to the first tag, but not to the rest. I’m not sure why only one style tag receives the nonce.

Laravel Mix Setup with React:

const mix = require('laravel-mix');
const webpack = require('webpack');

// Define the nonce value
const STYLE_NONCE = JSON.stringify('your-generated-nonce-value');

mix.webpackConfig({
    module: {
        rules: [
            {
                test: /.css$/,
                use: [
                    {
                        loader: 'style-loader',
                        options: {
                            attributes: {
                                nonce: STYLE_NONCE,
                            },
                        },
                    },
                    'css-loader',
                    'postcss-loader',
                ],
            },
        ],
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env.STYLE_NONCE': STYLE_NONCE,
        }),
    ],
});

mix.sass('resources/sass/app.scss', 'public/css')
    .js('resources/js/app.js', 'public/js').react()
    .js('resources/js/company.js', 'public/js')
    .version();

In both setups (Webpack and Laravel Mix), only the first tag gets the nonce. I’ve tried several approaches, but I’m still stuck. How can I ensure that the nonce is applied to all generated tags? Is there something I might be missing with the style-loader or the Webpack configuration in general?

Any insights or suggestions would be greatly appreciated!

You can post this version of your question on StackOverflow, and hopefully, it will attract attention from developers familiar with Webpack and CSP configurations.

Even though in laravel its giving an error.

[![✖ Mix
  Compiled with some errors in 15.69s

Browserslist: caniuse-lite is outdated. Please run:
  npx update-browserslist-db@latest
  Why you should do it regularly: https://github.com/browserslist/update-db#readme
ERROR in ./node_modules/react-date-range/dist/styles.css (./node_modules/laravel-mix/node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[6].oneOf[1].use[1]!./node_modules/laravel-mix/node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[6].oneOf[1].use[2]!./node_modules/style-loader/dist/cjs.js??ruleSet[1].rules[11].use[0]!./node_modules/css-loader/dist/cjs.js!./node_modules/postcss-loader/dist/cjs.js!./node_modules/react-date-range/dist/styles.css)
Module build failed (from ./node_modules/laravel-mix/node_modules/postcss-loader/dist/cjs.js):
SyntaxError

(2:7) /Users/rudra/Documents/pfiq/pfiq-web-app/node_modules/react-date-range/dist/styles.css Unknown word

  1 | 
> 2 |       import API from "!../../style-loader/dist/runtime/injectStylesIntoStyleTag.js";
    |       ^
  3 |       import domAPI from "!../../style-loader/dist/runtime/styleDomAPI.js";
  4 |       import insertFn from "!../../style-loader/dist/runtime/insertBySelector.js";

ERROR in ./node_modules/react-date-range/dist/theme/default.css (./node_modules/laravel-mix/node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[6].oneOf[1].use[1]!./node_modules/laravel-mix/node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[6].oneOf[1].use[2]!./node_modules/style-loader/dist/cjs.js??ruleSet[1].rules[11].use[0]!./node_modules/css-loader/dist/cjs.js!./node_modules/postcss-loader/dist/cjs.js!./node_modules/react-date-range/dist/theme/default.css)
Module build failed (from ./node_modules/laravel-mix/node_modules/postcss-loader/dist/cjs.js):
SyntaxError

(2:7) /Users/rudra/Documents/pfiq/pfiq-web-app/node_modules/react-date-range/dist/theme/default.css Unknown word

  1 | 
> 2 |       import API from "!../../../style-loader/dist/runtime/injectStylesIntoStyleTag.js";
    |       ^
  3 |       import domAPI from "!../../../style-loader/dist/runtime/styleDomAPI.js";
  4 |       import insertFn from "!../../../style-loader/dist/runtime/insertBySelector.js";][1]][1]

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật