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

Code Execution Error after Applying Content Security Policy (CSP) #1645

Open
santaku-plcp opened this issue May 20, 2023 · 0 comments
Open

Comments

@santaku-plcp
Copy link

santaku-plcp commented May 20, 2023

This is my first submission.
Thank you in advance for your cooperation.
I am not good at English, Sorry if it is hard to read in my poor English.

I apologize for any confusion. It's appropriate to provide the details here since you were unsure whether to create an issue or start a discussion. If there is an issue, please let me know, and I'll assist you accordingly.

Expected behavior:
I expected the code to execute without errors after applying the nonce to the Style tags.

Describe the bug:
When setting the nonce and attempting to execute the code, I encountered the following errors:

※I am attaching a screenshot of the error being displayed. We would appreciate it if you could check it.

Error:
Refused to apply inline style because it violates the following Content Security Policy directive: "style-src-elem 'self' 'nonce-474cd72a-68a6-4c73-ab04-3be566102f8f'". Either the 'unsafe-inline' keyword, a hash ('sha256-AbpHGcgLb+kRsJGnwFEktk7uzpZOCcBY74+YBdrKVGs='), or a nonce ('nonce-...') is required to enable inline execution.

Reproduction:
We are in the process of applying the Content Security Policy (CSP).
CSP support: https://cssinjs.org/csp/?v=v10.8.2

To reproduce the issue, follow these steps:
1.set the following csp header
property="csp-nonce"

<meta property="csp-nonce" content="nonce-cfcac59c-bf9c-46ca-b77f-b92896466042" data-react-helmet="true">

http-equiv="Content-Security-Policy"

<meta http-equiv="Content-Security-Policy" content="connect-src 'self' https://as3-web-temporary.s3.ap-northeast-1.amazonaws.com; default-src 'self' ; img-src 'self'; manifest-src 'self'; script-src 'self'; style-src-elem 'self' 'nonce-cfcac59c-bf9c-46ca-b77f-b92896466042' ; font-src 'self';" data-react-helmet="true">
  1. Set the nonce for the Style tags.
  2. Execute the code containing the following snippets:

Snippet 1:

jsxCopy code
function insertStyle(style, options) {
  var insertionPoint = options.insertionPoint;
  var nextNode = findPrevNode(options);

  if (nextNode !== false && nextNode.parent) {
    nextNode.parent.insertBefore(style, nextNode.node); // Error occurs here
    return;
  }

  if (insertionPoint && typeof insertionPoint.nodeType === 'number') {
    var insertionPointElement = insertionPoint;
    var parentNode = insertionPointElement.parentNode;
    if (parentNode) parentNode.insertBefore(style, insertionPointElement.nextSibling);
    else process.env.NODE_ENV !== "production" ? warning(false, '[JSS] Insertion point is not in the DOM.') : void 0;
    return;
  }

  getHead().appendChild(style); // Error occurs here
}

Snippet 2:

jsxCopy code
_proto.deploy = function deploy() {
    var sheet = this.sheet;
    if (!sheet) return;

    if (sheet.options.link) {
      this.insertRules(sheet.rules);
      return;
    }
    this.element.textContent = "\n" + sheet.toString() + "\n"; // Error occurs here
}

Versions (please complete the following information):

  • jss:10.9.0
  • Browser [e.g. chrome, safari]:Microsoft edge、chrome
  • OS [e.g. Windows, macOS]: Windows 10、Windows 11、macOS
  • Material-ui : v4
  • Server Side Rendering(SSR):not use

Managing expectations:

Is there a solution, and if so, can you please tell me how to deal with it?
If it seems difficult to deal with, can we enroll in commercial support and you will be able to help us?

screenshot codesnipet2-error
screenshot codesnipet1-error

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

No branches or pull requests

1 participant