-
-
Notifications
You must be signed in to change notification settings - Fork 353
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
CSP nonce support #1554
Comments
I agree that'd be nice. I think the following would be a simple solution.
Contribution welcome. |
Idea: also alow the user to set @JonWatkins What do you use to generate the nonce? Is |
The way that I was generating the nonce was with the crypto module, not sure that Math.random would be enough. But this also ensures that the value changes for every request. app.use((req: Request, res: Response, next: NextFunction) => {
res.locals.cspNonce = crypto.randomBytes(16).toString("hex");
next();
}); |
👍 And I guess If it's relatively slow, I'd be inclined for going for something faster albeit less secure. |
I don't have any issues with it in our app. it's such a negligable amount of time, even when the server is under heavy load. I think the implementation of the generated nonce might be best left to who ever is implementing it, as other people may have different requirements for it, but having support and docs would be super helpful. We are using helmet for the handling the CSP headers like this so that it is able to use the app.use(helmet({
contentSecurityPolicy: {
directives: {
objectSrc: ["'none'"],
scriptSrc: [
"'self'",
(req, res) => `'nonce-${res.locals.cspNonce}'`,
],
},
},
}); |
Hey all! I am looking to help contribute to Vike, and I started working on this issue. I created a draft PR with some small changes. I wanted to post and see if I am on the right path before I continue forward. @brillout, I see that you proposed to add the Thanks in advance! |
Description
It would be good if the
renderPage
was able to apply CSP nonce to the relevent tags. We are using helmet with express in our application, and i have managed to get it to work by doing something linke thisIm aware, that I would be able to include a meta tag in the HTML easy enough, but applying a nonce to tags generated by Vike is a little more awkward currently.
The text was updated successfully, but these errors were encountered: