Skip to content

feat: centralize CSP handling and add controller decorators to support customization#22980

Open
amcgee wants to merge 41 commits intomasterfrom
feat/security-csp-csrf
Open

feat: centralize CSP handling and add controller decorators to support customization#22980
amcgee wants to merge 41 commits intomasterfrom
feat/security-csp-csrf

Conversation

@amcgee
Copy link
Copy Markdown
Contributor

@amcgee amcgee commented Feb 17, 2026

This PR centralizes and standardizes CSP handling. All CSP headers (except certain Tracker exceptions) are set in the new CspInterceptor, which applies the default CSP policy to all endpoints and can be overridden with the new annotation @CspUserUploadedContent or @CustomCsp.

Previously these headers were inconsistently set, inconsistently overridable in configuration, and difficult to audit since they were often set manually in individual controllers. See this doc for current state analysis.

Future improvements: system setting overrides for these settings, per-application Csp settings declared in manifest and able to be approved/denied by app admins.

@amcgee amcgee changed the title feat: centralize CSP handling to CspFilter and add controller decorators to support customization feat: centralize CSP handling and add controller decorators to support customization Feb 19, 2026
@amcgee amcgee marked this pull request as ready for review February 25, 2026 09:42
@amcgee amcgee requested a review from a team as a code owner February 25, 2026 09:42
@sonarqubecloud
Copy link
Copy Markdown


// Verify custom policy directives are in the CSP header
assertTrue(
cspHeader.contains("default-src 'self'"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertEquals gives better error messages in case this breaks. Right now you just get expected true got false

Comment on lines 55 to 57
@Component
@RequiredArgsConstructor
public class RequestHandler {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public class RequestHandler {

this class can now be a utility one with static methods as it has no dependencies

Comment thread docker-compose.yml
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_DB: ${DB_NAME:-dhis}
POSTGRES_PASSWORD: &postgres_password ${DB_USERNAME}
POSTGRES_PASSWORD: &postgres_password ${DB_PASSWORD}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this relevant for this PR?

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.

3 participants