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

How to set dynamic nonce value to scriptSrc by reading the nonce value from script #7

Open
HareeshYHY opened this issue Aug 27, 2020 · 0 comments

Comments

@HareeshYHY
Copy link

HareeshYHY commented Aug 27, 2020

Hi Team,

Problem Description

  1. am generating a uuid and setting the value as script.nonce = uuid(); from my angular componet.ts
          this.uuid = uuid();
          const script = document.createElement('script');
          script.id = this.modelName + '-script';
          script.type = 'text/javascript';
          script.nonce = uuid();
          script.innerHTML = data;
          document.body.appendChild(script);
  1. we are using express nodejs and helmet to set the contentSecurityPolicy(CSP). Now i want to read the nonce value which was generated in angular component.ts in step1 and set to scriptSrc.
  app.use(helmet.contentSecurityPolicy({
        directives: {
            defaultSrc: ["'self'"],
            scriptSrc: ["'self'", "https://www.google-analytics.com/analytics.js", "'unsafe-eval'", "'???? How to set dynamic nonce??'"],
            
        }
    }));
  1. am setting dynamic uuid value to nonce but unable to read the value and set it contentSecurityPolicy(CSP) nonce. getting error while loading the page.

  2. is there any way to read the dynamically generated nonce value in angular component.ts and set it not the helmet.contentSecurityPolicy for the scriptSrc as "nonce-uuid"?

Expected behavior
The helmet.contentSecurityPolicy should set the dynamic nonce value to the scriptSrc.

Error Details
Refused to run the JavaScript URL because it violates the following Content Security Policy directive: "script-src 'self' https://www.google-analytics.com/analytics.js 'unsafe-eval' ". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.

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