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

[CSP] providePrimeNG csp nonce does not solve all csp issues when "theme" property is defined #17048

Closed
tom-vism opened this issue Dec 13, 2024 · 5 comments
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@tom-vism
Copy link

Describe the bug

Not all CSP issues are fixed when providing the CSP nonce into the PrimeNG config when the "theme" property is an empty object or "preset" is null.
While debugging, the first nonce value is passed undefined.

Environment

strict csp policy, no unsafe-inline, we are using nonces.

Reproducer

https://stackblitz.com/edit/azxstcmm?file=src%2Fmain.ts

Angular version

^18.2.11

PrimeNG version

^18.0.0

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

v20.18.1

Browser(s)

Chrome 131.0.6778.140

Steps to reproduce the behavior

image

image

image|

image

Expected behavior

Nonce attribute is set correctly and no csp issues are thrown in the console when "theme" is defined in the primeng config

@tom-vism tom-vism added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Dec 13, 2024
@SavGRY
Copy link

SavGRY commented Dec 13, 2024

Yep, this is also happening to me with the rc 19.0.0-rc.1 with Angular 19.

Although it's not a stable release, it's the same problem.

Angular version
19

PrimeNG version
19.0.0-rc.1

Browser(s)
Firefox 133.0.3

@Jonathazn
Copy link

Wondering if I have the same issue, but in my case, the nonces are empty strings like so:
<style type="text/css" nonce="" data-primeng-style-id="global-style">...</style>

Nonce gets set in providePrimeNG like this:
csp: {nonce: 'angularNonce'}

Nonce is correctly set in the ngcspnonce attribute of app-root (server is nginx), but all other nonce values are empty strings.
Locally the nonces are set to the same default value the ngcspnonce has, but in production they are empty.

Angular version
19.0.1

PrimeNG version
19.0.0-rc.1

@tom-vism
Copy link
Author

Wondering if I have the same issue, but in my case, the nonces are empty strings like so: <style type="text/css" nonce="" data-primeng-style-id="global-style">...</style>

Nonce gets set in providePrimeNG like this: csp: {nonce: 'angularNonce'}

Nonce is correctly set in the ngcspnonce attribute of app-root (server is nginx), but all other nonce values are empty strings. Locally the nonces are set to the same default value the ngcspnonce has, but in production they are empty.

Angular version 19.0.1

PrimeNG version 19.0.0-rc.1

For security reasons, nonce attribute is hidden. In devtools you can try to access it with document.querySelector('style[nonce]')?.nonce.
https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce#accessing_nonces_and_nonce_hiding

@tom-vism tom-vism reopened this Dec 16, 2024
Qui-mey pushed a commit to Qui-mey/primeng that referenced this issue Dec 16, 2024
@mertsincan mertsincan added Status: Pending Review Issue or pull request is being reviewed by Core Team and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Dec 16, 2024
@mertsincan mertsincan added this to the 19.0.0.Final milestone Dec 16, 2024
@mertsincan mertsincan self-assigned this Dec 16, 2024
@github-project-automation github-project-automation bot moved this to Review in PrimeNG Dec 16, 2024
@Jonathazn
Copy link

Jonathazn commented Dec 16, 2024

Wondering if I have the same issue, but in my case, the nonces are empty strings like so: <style type="text/css" nonce="" data-primeng-style-id="global-style">...</style>
Nonce gets set in providePrimeNG like this: csp: {nonce: 'angularNonce'}
Nonce is correctly set in the ngcspnonce attribute of app-root (server is nginx), but all other nonce values are empty strings. Locally the nonces are set to the same default value the ngcspnonce has, but in production they are empty.
Angular version 19.0.1
PrimeNG version 19.0.0-rc.1

For security reasons, nonce attribute is hidden. In devtools you can try to access it with document.querySelector('style[nonce]')?.nonce. https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce#accessing_nonces_and_nonce_hiding

The console is full of errors saying the csp header is violated... unless the issue is that nonce is different on every request, but I don't see why you wouldn't want that...

Edit: The log i get (more than a 100 times)
Screenshot 2024-12-16 125522

The only thing I can think of is that the hash being sent from the server is set correctly, but it's different than the one in ngcspnonce, which is a different issue. But not even the slightest clue how to resolve that.

Edit 2: Running document.querySelector('style[nonce]')?.nonce shows angularNonce, which is not correct or is it?

Edit 3: In chrome i get the same error as tom-vism
Screenshot 2024-12-16 162647
Which means it's the same issue, mozilla just shows it differently than chrome i guess

mertsincan added a commit that referenced this issue Dec 17, 2024
@mertsincan mertsincan added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Status: Pending Review Issue or pull request is being reviewed by Core Team labels Dec 17, 2024
@mertsincan mertsincan moved this from Review to Done in PrimeNG Dec 17, 2024
@mertsincan mertsincan closed this as completed by moving to Done in PrimeNG Dec 17, 2024
@Jonathazn
Copy link

The same happens in 19.0.0, does anything configuration wise need to change? @mertsincan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
Status: Done
Development

No branches or pull requests

4 participants