Skip to content
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

Angular 18.1.1 is not adding CSP nonce attribute to script tags generated during build(main.ts,polyfills.js etc...) #28102

Closed
1 task
sagartalaviya91 opened this issue Jul 23, 2024 · 2 comments · Fixed by #28114
Assignees

Comments

@sagartalaviya91
Copy link

Command

build

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

I want to implement strict CSP policy for my project, so replaced unsafe-eval and unsafe-inline with nonce-dynamicnonce.
But Angular version 18.1.1 is not adding nonce to script tags of main.js, polyfills.js etc.
Because of that it is considering this scripts tags as unsafe and browser is blocking its execution.
In below stackblitz I used 18.1.1 and added nonce using CSP_NONCE and ngCspNonce. But it is not adding nonce to script tags. Please inspect and check in Dom.
Stackblitz URL: https://stackblitz.com/edit/stackblitz-starters-wr9a9h?file=src%2Fapp%2Fapp.config.ts

As per below merged Issue, It should work in 18.1.1. But it is not working.
#27875

Kindly check!!
Thanks in advanced!

Minimal Reproduction

  1. apply nonce using ngCspNonce and CSP_NONCE provider
  2. using dev tools check script tags in DOM.
  3. It is not adding nonce to script tags of main.js,polyfills.js etc..

Exception or Error

No response

Your Environment

18.1.1

Anything else relevant?

No response

@JoostK
Copy link
Member

JoostK commented Jul 23, 2024

When running ng build, it does copy the ngCspNonce attribute value to style and script elements as nonce attribute. This is unlike ng serve, which doesn't at the moment.

Note that using both ngCspNonce and providing CSP_NONCE is superfluous; the former will be used to provide CSP_NONCE by default.

alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Jul 26, 2024
…line critical CSS is disabled

Prior to this change when inline critical CSS is disabled CSP `nonce` was not added to script tags.

Closes angular#28102
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Jul 26, 2024
…line critical CSS is disabled

Prior to this change when inline critical CSS is disabled CSP `nonce` was not added to script tags.

Closes angular#28102
@alan-agius4 alan-agius4 added freq1: low Only reported by a handful of users who observe it rarely severity3: broken area: @angular/build labels Jul 26, 2024
@alan-agius4 alan-agius4 self-assigned this Jul 26, 2024
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Jul 29, 2024
…line critical CSS is disabled

Prior to this change when inline critical CSS is disabled CSP `nonce` was not added to script tags.

Closes angular#28102
alan-agius4 added a commit that referenced this issue Jul 29, 2024
…line critical CSS is disabled

Prior to this change when inline critical CSS is disabled CSP `nonce` was not added to script tags.

Closes #28102

(cherry picked from commit 636cb69)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants