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

Fix #2423: Add CSP NONCE to inline style elements if found #2442

Merged
merged 1 commit into from
Nov 18, 2021

Conversation

melloware
Copy link
Member

@melloware melloware commented Nov 17, 2021

###Defect Fixes
Fix #2423: Add CSP NONCE to inline style elements if found

This is a very important fix for security. This checks if the downstream application using PrimeReact has set a CSP NONCE environment variable process.env.REACT_APP_CSS_NONCE. This can be hardcoded in their .env file or if they are using a dynamic NONCE generator like CRA CSP WebPack Plugin: https://github.com/slackhq/csp-html-webpack-plugin.

If you do dynamically generate your NONCE you can easily set it in your application like this for PrimeReact to pick it up and use it in all its inline styling efforts.

// attempt to read an existing NONCE from a  CSS link on the page
let nonce;
let cssLink = document.querySelector('link[nonce]') as HTMLScriptElement;
if (cssLink) {
    nonce = cssLink?.nonce!;
}

// now set the environment variable for PrimeReact to read
if (nonce) {
    process.env.REACT_APP_CSS_NONCE= nonce;
}

@mertsincan mertsincan merged commit bbb8795 into primefaces:master Nov 18, 2021
@mertsincan
Copy link
Member

Thanks a lot!

@melloware melloware deleted the PR2423 branch November 18, 2021 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CSP: Violating Inline Style Policy
2 participants