Skip to content

Do not send a policy on a response carrying a dump - #396

Open
Amoifr wants to merge 1 commit into
nelmio:masterfrom
Amoifr:feature-339-disable-csp-when-dumping
Open

Amoifr wants to merge 1 commit into
nelmio:masterfrom
Amoifr:feature-339-disable-csp-when-dumping

Conversation

@Amoifr

@Amoifr Amoifr commented Sep 5, 2026

Copy link
Copy Markdown

Fixes #339, following the pointer you gave there to symfony/symfony@bbb4d9f.

dump() renders as inline scripts and styles, which any policy worth setting blocks, so the dump lands unstyled with dead toggles. The WebDebugToolbarListener solved this for the policy it manages by dropping it when the dump collector has something to show; the listener here now does the same.

data_collector.dump is only declared by the DebugBundle, so the reference is NULL_ON_INVALID_REFERENCE and the behaviour cannot reach an environment without it.

One detail on the DI side: argument 7 (request_matcher) was only set conditionally, so appending argument 8 would have left a hole in the array and the collector would have been passed as the request matcher. It is now passed explicitly as null in setArguments(), which matches the constructor default, and the conditional setArgument(7, ...) below is unchanged.

Tests cover both directions: a response with a dump gets no policy, one without keeps it.

The output of dump() is made of inline scripts and styles, which any policy
worth setting blocks, so the dump comes out unstyled and its toggles do not
work.

The CSP listener now takes the dump data collector, which only the DebugBundle
declares, and skips the headers when the response carries at least one dump.
This is what WebDebugToolbarListener already does for the policy it manages.
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 interferes with var-dumper

1 participant