Skip to content

fix(csp): warn when useNonce falls back to unsafe-inline#3881

Open
sanjibani wants to merge 1 commit into
freshframework:mainfrom
sanjibani:fix/csp-nonce-fallback-warning
Open

fix(csp): warn when useNonce falls back to unsafe-inline#3881
sanjibani wants to merge 1 commit into
freshframework:mainfrom
sanjibani:fix/csp-nonce-fallback-warning

Conversation

@sanjibani

Copy link
Copy Markdown

Route handlers returning ctx.html() / ctx.json() / ctx.text() instead of ctx.render() never set the nonce, so the CSP middleware silently serves the default 'unsafe-inline' directives. The user opted into useNonce to lock the policy down — silently getting 'unsafe-inline' is a real security regression they can't detect.

Emit a console.warn with the offending pathname so the developer knows which handler needs to switch to ctx.render(). Two new tests assert the warning fires on the fallback path and stays silent on the rendered path.

Fixes #3859.

A route handler that returns ctx.html(), ctx.json(), or ctx.text()
instead of ctx.render() never sets the nonce on the response, so the
CSP middleware silently falls back to the default directives with
'unsafe-inline' in script-src / style-src. The user opted into
useNonce to lock the policy down — getting 'unsafe-inline' instead
is a real security regression and they have no way to tell.

Emit a console.warn with the route path so the developer knows the
handler needs to switch to ctx.render(). Two new tests cover the
warning in both the fallback and no-fallback cases.
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

Successfully merging this pull request may close these issues.

CSP nonce silently degrades to unsafe-inline without warning

1 participant