Skip to content

feat: add insecureUnsafeInline option to CSP middleware#3841

Closed
SisyphusZheng wants to merge 3 commits into
freshframework:mainfrom
SisyphusZheng:feat/csp-insecure-unsafe-inline
Closed

feat: add insecureUnsafeInline option to CSP middleware#3841
SisyphusZheng wants to merge 3 commits into
freshframework:mainfrom
SisyphusZheng:feat/csp-insecure-unsafe-inline

Conversation

@SisyphusZheng

Copy link
Copy Markdown
Contributor

Problem

When useNonce: true, the CSP middleware replaces all 'unsafe-inline' occurrences with 'nonce-{value}'. Users who need both Fresh's nonce-based inline scripts AND third-party inline scripts (analytics, reporting widgets) cannot achieve this — the current middleware completely removes 'unsafe-inline'.

Solution

Add insecureUnsafeInline?: boolean option. When enabled with useNonce: true, retains 'unsafe-inline' alongside the nonce:

script-src 'self' 'unsafe-inline' 'nonce-deadbeef42'

When useNonce is false, the option has no effect.

Changes

  • packages/fresh/src/middlewares/csp.ts — add option, deconstruct it, update nonce replacement logic
  • packages/fresh/src/middlewares/csp_test.tsx — 2 new tests covering both positive and default behavior

Verification

deno test -A packages/fresh/src/middlewares/csp_test.tsx — 13 passed, 0 failed

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.

1 participant