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

Right script-src parameter in Content-Security-Policy #136

Closed
alexbidenko opened this issue Apr 1, 2023 · 12 comments · Fixed by #171
Closed

Right script-src parameter in Content-Security-Policy #136

alexbidenko opened this issue Apr 1, 2023 · 12 comments · Fixed by #171
Labels
enhancement New feature or request

Comments

@alexbidenko
Copy link
Contributor

Problem description

At the moment, Content-Security-Policy header do not include script-src parameter. It means, that every script can be executives in user browser - and it is not secured. As a minimal solution I can propose: 'script-src': ["'self'", "'unsafe-inline'"] - it will be blocking eval and unsecured scripts from other recourses, but it is not right.

More secured solution is do not use unsafe-inline. But for this nuxt-data must be resolved by means of nonce or sha-***. But I do not know how do it.

Describe the solution you'd like

In ideal world script-src should include 'sha-***' of nuxt-data and automatically calculate it in every html rendering on server side.

As alternative script-src can include 'nonce-***' and the nonce must be injected as an attribute in nuxt-data script (for better security nonce must be randomize on every request, do not be constant).

Additional context

In Next.js framework we just can add <NextData nonce="next-data" /> component and inject nonce-next-data in script-src - it is simple correct solution.

@alexbidenko alexbidenko added the enhancement New feature or request label Apr 1, 2023
@Baroshem
Copy link
Owner

Baroshem commented Apr 2, 2023

Hey,

Thank you for reporting this issue! I will take a look at it in the upcoming days :)

@Baroshem
Copy link
Owner

Baroshem commented Apr 7, 2023

I just talked about this during Nuxt Insiders meeting and we came up with some ideas on how this can be implemented. I will be working on it next week probably :)

@sfase3
Copy link

sfase3 commented May 10, 2023

hello, did you fix that issue?

@Baroshem
Copy link
Owner

Hey, not yet.

I am working on it. Have been quite busy recently with other topics.

If anyone would like to contribute to it, feel free to open a PR with the change :)

@royvzoelen
Copy link

Any updates on "As alternative script-src can include 'nonce-***' and the nonce must be injected as an attribute in nuxt-data script (for better security nonce must be randomize on every request, do not be constant)."

@Baroshem
Copy link
Owner

Hey, not really.

Recently, I did not have time to work on this feature. It is open for contributions for anyone who would like to tackle this. I will be able to come back to this earliest next week or the week after

@royvzoelen
Copy link

Thats no problem i cant contribute myself so i will wait for updates on this one.
Keep us posted :)

@trijpstra-fourlights
Copy link
Contributor

I've implemented nonce support for CSP in #171

You can test this directly from github by using:
"nuxt-security": "github:trijpstra-fourlights/nuxt-security#build/nonce",
in your package.json.

Then in your nuxt.config.ts add:

security: {
  // ...
  nonce: true,    // <-- add to enable nonce
  headers: {
      contentSecurityPolicy: {
        // ... other csp settings
        'script-src': [
          "'self'", // backwards compatibility for older browsers that don't support strict-dynamic
          "'nonce-{{nonce}}'",
          "'strict-dynamic'",
        ],
        'script-src-attr': ["'self'", "'nonce-{{nonce}}'", "'strict-dynamic'"],
        // ... other csp settings
      },
   }
}

For more information, refer to the updated documentation in the PR.

@alexbidenko
Copy link
Contributor Author

@trijpstra-fourlights , your PR is super, thanks!

I have written some comments in PR. What do you think about my suggestions?

@trijpstra-fourlights
Copy link
Contributor

trijpstra-fourlights commented Jul 13, 2023

@alexbidenko1998 I've addressed your feedback and added a commit regarding your inline literal comment.

@Baroshem
Copy link
Owner

@alexbidenko1998 @trijpstra-fourlights The feature has been merged and released in version 0.14.0. Thanks so much for this amazing contribution 💚

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants