Repository navigation
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1660
Problem
In development mode,
WebApplication.internalInit()sets up the CSP like this:reportBack()adds areport-uridirective, butstrict()starts withclear(), so itremoves that directive again a line later. As a result, the
Content-Security-Policyheader in development mode never contains a
report-uri, and CSP violations are notreported 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 andreportBack()then adds thereport-urion top of it. It's a one-line move ininternalInit(); nothing else changes.What changes for applications
report-uri, so the browserreports violations to the application again. All other directives are the same as before.
report-uri(the
reportBack()Javadoc warns against enabling it in production).init()aren't affected, sinceinit()runs after
internalInit().Tests
Added
CspReportUriTest, which starts an application in each mode and checks theblocking CSP settings, as suggested in the issue:
report-uriand the strict directives (e.g.default-src)report-uriThe development test fails before the change (the settings have every strict directive
except
report-uri) and passes after it.The test uses a plain
WebApplicationinstead ofWicketTestCase, becauseMockApplicationcallsgetCspSettings().blocking().disabled()at the end of its setup,which would hide the problem.
I also ran
ContentSecurityPolicySettingsTest,CSPDirectiveTest,CSPHeaderWriterTest,CSPTrustedTypesTestandWebApplicationTest; they all still pass.Other branches
The issue mentions the same code on
wicket-10.x. I've only changedmasterGenerated-by: Claude Code (Claude Opus 5.5)