ngCspNonce broken since domutils
v3.2.1
#29256
Labels
area: @angular/build
freq1: low
Only reported by a handful of users who observe it rarely
severity5: regression
type: bug/fix
Command
build
Is this a regression?
The previous version in which this bug was not present was
any
Description
After regenerating our
package-lock.json
file we ran into an issue wherengCspNonce
is no longer working. After debugging we figured out that it is caused with an update ofdomutils
package to v3.2.1. Since downgrading that package to v3.1.0 seems to fix the issue. For this we were able to find these probably related Github issues on external repositories for indirect dependencies of@angular/build
:fb55/htmlparser2#1987
fb55/domutils#1855
However since this actually breaks the
ngCspNonce
functionality we thought it would be good to also report the issue here.The issue happens when creating a new Angular app with
ngCspNonce
attribute added, after building the app, the<style>
tags are not generated. Seems likengCspNonce
is ignored?See comparison of "excepted" (left) and "actual" (right) of the
index.html
from thedist
folder after runningbuild
![Image](https://github.com/user-attachments/assets/c0107736-f0a3-4dfc-b080-35094640690c
Dependency tree:
@angular/build
>beasties
>htmlparser2
>domutils
Minimal Reproduction
See Stackblitz:
https://stackblitz.com/edit/ng-csp-nonce?file=src%2Findex.html
Or take full reproduction steps:
ng new
(latest v19, but also reproducable with v18)styles.scss
ngCspNonce="randomNonceGoesHere"
to<app-root>
as described in https://angular.dev/best-practices/security#content-security-policynpm install
&npm run build
dist
directory and lookup the generatedindex.html
find this line<link rel="stylesheet" href="styles-RP5GNS3S.css" media="print" onload="this.media='all'"><noscript><link rel="stylesheet" href="styles-RP5GNS3S.css"></noscript></head>
. Notice that it containsonload="this.media='all'"
which should actually have been prevented by thengCspNonce
attribute.To work-around:
package.json
addnode_modules
&package-lock.json
to be sure.npm install
&npm run build
index.html
find this lineException or Error
Your Environment
Anything else relevant?
No response
The text was updated successfully, but these errors were encountered: