Skip to content

fix: CSP user directives now override defaults instead of duplicating#3724

Merged
bartlomieju merged 2 commits into
mainfrom
fix/csp-directive-override
Mar 29, 2026
Merged

fix: CSP user directives now override defaults instead of duplicating#3724
bartlomieju merged 2 commits into
mainfrom
fix/csp-directive-override

Conversation

@bartlomieju

Copy link
Copy Markdown
Contributor

Summary

Before

img-src 'self' data:; ... ; img-src 'self' https://firebasestorage.googleapis.com data:

Duplicate img-src — browsers use the first one and ignore the override.

After

... ; img-src 'self' https://firebasestorage.googleapis.com data:

Single img-src with the user's value.

Implementation

Extracts directive names from user-provided CSP strings, filters out defaults that share the same name, then appends the user's directives. New directives not in the defaults (like frame-src) are added as before.

Test plan

  • Existing tests pass
  • New test: verifies img-src override produces exactly one img-src directive
  • Updated test: verifies font-src and style-src overrides don't duplicate

🤖 Generated with Claude Code

bartlomieju and others added 2 commits March 28, 2026 09:58
…#3552)

User-provided CSP directives with the same directive name as a default
(e.g. img-src) were appended alongside the default, producing duplicate
directives in the header. Now user directives replace defaults that
share the same directive name.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…rride

# Conflicts:
#	packages/fresh/src/middlewares/csp.ts
#	packages/fresh/src/middlewares/csp_test.ts
@bartlomieju bartlomieju enabled auto-merge (squash) March 29, 2026 19:48
@bartlomieju bartlomieju merged commit cf73d29 into main Mar 29, 2026
9 checks passed
@bartlomieju bartlomieju deleted the fix/csp-directive-override branch March 29, 2026 19:53
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 directive duplications when trying to override Fresh 2's defaults

1 participant