-
Notifications
You must be signed in to change notification settings - Fork 367
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
Content-Security-Policy: reimplement directive values as functions #243
Comments
Out of curiosity: Why was it removed in the first place? |
This will be fixed in @einfallstoll It was removed for a few reasons. Again, I regret the removal, but here was my thought process:
Again, you can test this out in |
This has been released in |
I'm also still getting problems with this: package.json ...
"helmet": "^4.1.1",
"helmet-csp": "^3.1.0",
...
import { Injectable, NestMiddleware } from '@nestjs/common'
import { Request, Response } from 'express'
import { v4 as uuidv4 } from 'uuid'
import helmet from 'helmet'
@Injectable()
export class CspNonceMiddleware implements NestMiddleware {
use (
request: Request,
response: Response,
next: CallableFunction
) {
response.locals.nonce = uuidv4()
next()
}
}
@Injectable()
export class HelmetMiddleware implements NestMiddleware {
use = helmet({
contentSecurityPolicy: {
directives: {
scriptSrc: [
"'self'",
(req, res) => `'nonce-${res.locals.nonce}'`
]
}
}
})
} |
That error is happening because Helmet types (req: Request, res: Response) => `'nonce-${res.locals.nonce}'` If that doesn't work, Helmet might want to add some kind of override to let you say that |
In Helmet version 4, I removed the ability to use functions in Content Security Policy directive values. Several issues (#240, fastify/fastify-helmet#89) arose as a result of this, and I don't think the deprecation was worth it.
I plan to re-add this feature in the next few days.
The text was updated successfully, but these errors were encountered: