Skip to content

Keep the CSP report-uri in development mode - #2006

Open
0-two wants to merge 1 commit into
apache:masterfrom
0-two:csp-report-uri-in-development
Open

0-two wants to merge 1 commit into
apache:masterfrom
0-two:csp-report-uri-in-development

Conversation

@0-two

@0-two 0-two commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Closes #1660

Problem

In development mode, WebApplication.internalInit() sets up the CSP like this:

if (getConfigurationType() == RuntimeConfigurationType.DEVELOPMENT)
{
	...
	getCspSettings().blocking().reportBack();
}
getCspSettings().blocking().strict();

reportBack() adds a report-uri directive, but strict() starts with clear(), so it
removes that directive again a line later. As a result, the Content-Security-Policy
header in development mode never contains a report-uri, and CSP violations are not
reported back to the application, even though that's clearly what this code intends.

Change

I moved strict() above the development block, so the strict policy is set up first and
reportBack() then adds the report-uri on top of it. It's a one-line move in
internalInit(); nothing else changes.

What changes for applications

  • Development mode: the CSP header now includes report-uri, so the browser
    reports violations to the application again. All other directives are the same as before.
  • Deployment mode: nothing changes, and there is still no report-uri
    (the reportBack() Javadoc warns against enabling it in production).
  • Applications that configure CSP themselves in init() aren't affected, since init()
    runs after internalInit().

Tests

Added CspReportUriTest, which starts an application in each mode and checks the
blocking CSP settings, as suggested in the issue:

  • development mode: contains report-uri and the strict directives (e.g. default-src)
  • deployment mode: contains the strict directives but no report-uri

The development test fails before the change (the settings have every strict directive
except report-uri) and passes after it.

The test uses a plain WebApplication instead of WicketTestCase, because
MockApplication calls getCspSettings().blocking().disabled() at the end of its setup,
which would hide the problem.

I also ran ContentSecurityPolicySettingsTest, CSPDirectiveTest, CSPHeaderWriterTest,
CSPTrustedTypesTest and WebApplicationTest; they all still pass.

Other branches

The issue mentions the same code on wicket-10.x. I've only changed master

Generated-by: Claude Code (Claude Opus 5.5)

In development mode internalInit() called reportBack() and then
strict(), but strict() starts by clearing every directive, so the
report-uri was removed again and CSP violations were never reported
back to the application. strict() now runs first and reportBack()
after it. Deployment mode is unchanged and still sends no report-uri.

GitHub issue apache#1660
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.

The CSP report-uri is lost in development mode because strict() clears it

1 participant