Replies: 8 comments 30 replies
-
Hey buddy! This is an amazing feature idea! I really like it and I totally think this could be part of the module itself. I looked at the code and in general I have only one comment so far. I will be releasing quite a big new version in the next few days (1.0.0-rc.1) and there, few things have changed. Most importantly, I have introduced a new configuration property object called ssg. For now, it includes only the It would be a good idea to start your feature request from this branch or from main after wednesday as this will be a new develooment branch. |
Beta Was this translation helpful? Give feedback.
-
Ok, I will definitely re-fork from rc.1 1 - On how I designed the SRI feature:
2 - On how I designed the CSP complementary feature:
As a result, I would think
What I'm trying to say, is that it should be the responsibility of the module to handle SSR vs SSG, and it would be preferable not to give the user the possibility to mess up with this via options. |
Beta Was this translation helpful? Give feedback.
-
Just want to give a quick update here based on rc1. The security issue is partially resolved in rc1, because now the However please note that this is only a TypeScript check based on the type definition. In other words, we are relying on people to follow the instructions of their linter (assuming they did set it up properly). If they don't, the hole is still open. In order to separate concerns properly, I will make a first PR aiming at improving the TypeScript config in the repo, as we have several type mismatches and imports misconfigured, and I believe it will help spotting these issues. |
Beta Was this translation helpful? Give feedback.
-
No that's not correct. The aforementioned hypothetical external service has
nothing to do with the nonce or csp. It's essentially out of our control
for the sake of argument.
The nonce is set by the nuxt server, and is persisted using a cookie with
same site and secure. This allows the `useNonce` composable to access the
current nonce value in the frontend and allows nitro to reuse it (again,
only in these advanced use cases of mode:check) when applicable.
Within the same request, nitro/the nuxt server can access the h3 event
context which is a tiny bit quicker than using the cookie.
This is how SSR works with Nuxt. It's not applicable for SSG as nonce
values add no security benefit in a static context.
To better explain (one of the) potential advanced use cases:
Imagine an api backend which exposes an endpoint which returns a runtime
generated stylesheet which you want to include on your app, while keeping
strict csp in place. Using a Nuxt api route to proxy this runtime generated
endpoint allows you to do that, while also not exposing the underlying api
to the frontend.
I use this succesfully in production similarly to this example.
Op do 19 okt 2023 10:10 schreef vejja ***@***.***>:
… Ok I can see the use case now, thanks
Looks like you are extracting the external server's nonce from either
event.context or a nonce cookie.
How do you know these variables are set by the external server ?
—
Reply to this email directly, view it on GitHub
<#241 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A25JEPRVEP45ZPHUTR6P6B3YADOANAVCNFSM6AAAAAA6ALXWFSVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM3TGMRTHAZDC>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
CSP nonce implementationI wanted to reflect upon the discussion related to the implementation of CSP nonces. In a nutshell, it is currently possible to entirely bypass CSP.
Security Analysis
I do understand the use case where the user needs to generate scripts on the fly. However a strict CSP does not prevent this. CSP only ensures that you have identified the script and have authorized it explicitely via nonce. In summary, the current implementation does not enforce CSP, but allows to bypass CSP. Proposed modificationsAs a result, I would like to propose the following critical modifications:
This will allow the module to become CSP-compliant. |
Beta Was this translation helpful? Give feedback.
-
Guys, I really dont like where this discussion went. We started from sharing opinions about this topic to a point where we are trying to convince each other that the other person is wrong. And this is the last thing that I would like to see here as I really value how both of you have contributed to this discussion and the module in general. The changes @vejja is proposing are extremely destructive (especially considering the fact that yesterday I have released a version that is supposed to be stable and only include bug fixes not breaking changes). I appreciate your work here Vejja but even from the maintainer perspective I cannot agree to do these changes even if we could all agree that they are necessary. Users are expecting stability right now. I understand your concerns but as @trijpstra-fourlights suggested, it would be useful to see some examples why the current solution is wrong. Since the release of current implementation of nonce, there were several people who have tried it, asked questions and got responses usually from @trijpstra-fourlights (thanks for that!). And not to mention @trijpstra-fourlights himself who is using this solution as he mentioned. So I think that the current solution is not bad. @vejja is there maybe a way to address your concerns in a form of a documentation section rather than removing functionality that is already there? I think this solution would be the best right now considering the recent release and this whole discussion. And finally, please remember that both of you want to make this module better. I am really, really grateful for that. You just have different opinions and ideas and I will do my best to find the common path and let you both contribute in most appriopriate way possible. |
Beta Was this translation helpful? Give feedback.
-
I do have a POC now with a stackblitz here Update: You can also now test the POC live on Vercel here: https://nuxt-security-sraffray.vercel.app/ This is based on https://github.com/vejja/nuxt-security/tree/poc/strict-csp-nocookie The POC shows that you can load external scripts and stylesheets, and inject inline scripts and stylesheets with strict CSP |
Beta Was this translation helpful? Give feedback.
-
@Baroshem I think that based on this POC we can now close this discussion. |
Beta Was this translation helpful? Give feedback.
-
Hi @Baroshem
I am planning to propose a PR introducing SRI (sub resource integrity) injection.
This will also allow support of CSP 'strict-dynamic' policy for SSG.
I still have a few things to finalize but I already did the bulk of the work.
Can you please have a look at my wip code at : https://github.com/vejja/nuxt-security ?
It would be very helpful to have your feedback on my fork before issuing the final PR.
Many thanks
Beta Was this translation helpful? Give feedback.
All reactions