Skip to content

Only send the document security headers on documents - #1839

Merged
Seldaek merged 1 commit into
mainfrom
perf/scope-security-headers
Sep 8, 2026
Merged

Only send the document security headers on documents#1839
Seldaek merged 1 commit into
mainfrom
perf/scope-security-headers

Conversation

@Seldaek

@Seldaek Seldaek commented Sep 7, 2026

Copy link
Copy Markdown
Member

content_types defaulted to an empty list for both the CSP and clickjacking listeners, which nelmio treats as "every content type" (AbstractContentTypeRestrictableListener::isContentTypeValid). So every JSON API response carried the full ~600 byte Content-Security-Policy plus an X-Frame-Options header. The security-advisory and download-tracking endpoints alone account for ~4.5M responses per APM period.

Neither header does anything for a non-document response: CSP governs document loading and X-Frame-Options governs framing, and a JSON body is neither.

Restricting both listeners to text/html is route-drift-proof, unlike enumerating API path prefixes in clickjacking.paths — new endpoints are covered automatically, and HTML pages are unaffected.

Verification

composer phpstan clean, full suite green. New SecurityHeadersTest asserts both halves: an HTML page still gets X-Frame-Options: DENY and a CSP, and /packages/list.json gets neither. Confirmed the JSON assertion fails against the previous config, so it isn't vacuous.

content_types defaulted to an empty list for both the CSP and clickjacking listeners,
which means "every content type", so every JSON API response carried the full ~600 byte
Content-Security-Policy and an X-Frame-Options header. The security advisory and download
tracking endpoints alone account for around 4.5M responses per APM period.

Neither header does anything for a non-document response: CSP governs document loading
and X-Frame-Options governs framing, and a JSON body is neither. Restricting both
listeners to text/html is route-drift-proof, unlike enumerating API path prefixes.
@Seldaek
Seldaek merged commit f8aa6ad into main Sep 8, 2026
8 checks passed
@Seldaek
Seldaek deleted the perf/scope-security-headers branch September 8, 2026 08:00
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.

2 participants