Skip to content

fix(security): relax CSP for Swagger UI via per-path quarkus.http.filter - #518

Merged
ginccc merged 2 commits into
mainfrom
fix/swagger-ui-csp
Jun 3, 2026
Merged

fix(security): relax CSP for Swagger UI via per-path quarkus.http.filter#518
ginccc merged 2 commits into
mainfrom
fix/swagger-ui-csp

Conversation

@ginccc

@ginccc ginccc commented Jun 3, 2026

Copy link
Copy Markdown
Member

This pull request addresses a bug where the Swagger UI was broken due to an overly strict Content Security Policy (CSP) applied globally. The solution introduces path-based CSP overrides using Quarkus's native filter mechanism, ensuring strong security for the rest of the application while allowing Swagger UI to function properly. The change also documents the root cause and rationale for the chosen approach.

Security header configuration:

  • Replaced the global quarkus.http.header.Content-Security-Policy with two path-based quarkus.http.filter entries in application.properties: a strict default CSP for all paths and a relaxed CSP for /q/swagger-ui/.* that adds 'unsafe-inline' and 'unsafe-eval' to script-src for Swagger UI compatibility.
  • Documented the filter override approach and rationale (including why a Java filter was not used) in the changelog, providing clear guidance for future maintenance and audits.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed Swagger UI rendering (previously blank) by adjusting content security rules so the UI can load while preserving strict defaults for the rest of the app.
  • Documentation
    • Added a changelog entry documenting the security configuration adjustment and its effect on Swagger UI.

Swagger UI was blocked by the global Content-Security-Policy header (script-src 'self'). Replaced the global quarkus.http.header.Content-Security-Policy with two quarkus.http.filter entries: a strict default (order=10) for the entire app, and a relaxed override (order=20) for /q/swagger-ui/* that adds 'unsafe-inline' + 'unsafe-eval' to script-src.
@ginccc
ginccc requested a review from rolandpickl as a code owner June 3, 2026 20:51
@ginccc
ginccc requested a review from Copilot June 3, 2026 20:52
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1a12219e-ce29-4e1b-9c4e-b7771cd0b27c

📥 Commits

Reviewing files that changed from the base of the PR and between 1a62a64 and 64123e0.

📒 Files selected for processing (1)
  • src/main/resources/application.properties

📝 Walkthrough

Walkthrough

Content-Security-Policy is refactored from a single global header to two Quarkus HTTP filters with path matching: a strict default for all routes and a higher-precedence relaxed policy for Swagger UI that permits inline and eval scripts. The change is recorded in the changelog.

Changes

CSP Configuration Fix

Layer / File(s) Summary
CSP filter rules (implementation)
src/main/resources/application.properties
Adds quarkus.http.filter.csp-default (strict, global) and quarkus.http.filter.csp-swagger (relaxed script-src including 'unsafe-inline' and 'unsafe-eval', higher precedence for /q/swagger-ui(/.*)?). Both retain shared directives like frame-ancestors 'none' and connect-src referencing ${eddi.keycloak.public.url:}.
Documentation update
docs/changelog.md
New changelog entry "Fix: Swagger UI Broken by CSP — Per-Path Filter Override" describing the issue and the per-path filter solution; references application.properties.
sequenceDiagram
  participant Client
  participant QuarkusFilterChain
  participant CspSwaggerFilter
  participant CspDefaultFilter
  participant ServerResponse
  Client->>QuarkusFilterChain: HTTP request (/q/swagger-ui/* or other)
  QuarkusFilterChain->>CspSwaggerFilter: path match check (/q/swagger-ui(/.*)?)
  alt matches
    CspSwaggerFilter->>ServerResponse: apply relaxed CSP (unsafe-inline, unsafe-eval)
  else does not match
    QuarkusFilterChain->>CspDefaultFilter: apply strict CSP
    CspDefaultFilter->>ServerResponse: apply strict CSP
  end
  ServerResponse-->>Client: response with selected CSP header
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • rolandpickl
  • Copilot

Poem

🐰 A tiny rabbit hops on keys,
CSP guards bent by gentle breeze.
Two filters hum, by path they part,
Swagger wakes with beating heart.
Puff of joy — the UI sees!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: fixing a security issue by relaxing CSP specifically for Swagger UI using per-path Quarkus HTTP filters. It directly reflects the core modifications in both application.properties and the changelog.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/swagger-ui-csp

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
src/main/resources/application.properties (1)

152-152: ⚡ Quick win

Widen CSP-match to cover /q/swagger-ui without trailing slash (edge cases)
quarkus.http.filter.csp-swagger.matches=/q/swagger-ui/.* only matches requests to /q/swagger-ui/…; in typical Quarkus behavior /q/swagger-ui is redirected to /q/swagger-ui/, so Swagger UI assets still get the relaxed CSP, but reverse-proxy/URL-normalization edge cases can bypass that redirect—consider updating the match to /q/swagger-ui(/.*)? to be safe.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/main/resources/application.properties` at line 152, The CSP match
property quarkus.http.filter.csp-swagger.matches currently only matches paths
with a trailing slash; update its regex to cover both /q/swagger-ui and
/q/swagger-ui/... (e.g. change to a pattern like /q/swagger-ui(/.*)? ) so the
CSP rule applies whether the trailing slash is present or not; modify the value
of quarkus.http.filter.csp-swagger.matches accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/main/resources/application.properties`:
- Line 152: The CSP match property quarkus.http.filter.csp-swagger.matches
currently only matches paths with a trailing slash; update its regex to cover
both /q/swagger-ui and /q/swagger-ui/... (e.g. change to a pattern like
/q/swagger-ui(/.*)? ) so the CSP rule applies whether the trailing slash is
present or not; modify the value of quarkus.http.filter.csp-swagger.matches
accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 195326d5-deb4-4666-a1fe-3fa0692a0af6

📥 Commits

Reviewing files that changed from the base of the PR and between e915f25 and 1a62a64.

📒 Files selected for processing (2)
  • docs/changelog.md
  • src/main/resources/application.properties

…ng slash

Changed regex from /q/swagger-ui/.* to /q/swagger-ui(/.*)? to cover reverse-proxy edge cases where the redirect to /q/swagger-ui/ is bypassed.
@ginccc
ginccc merged commit 0f40181 into main Jun 3, 2026
6 of 8 checks passed
@ginccc
ginccc deleted the fix/swagger-ui-csp branch June 3, 2026 20:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes Swagger UI rendering being blocked by an overly strict global Content Security Policy (CSP) by moving CSP configuration to path-based Quarkus HTTP filters, keeping a strict CSP for most endpoints while relaxing script-src specifically for Swagger UI.

Changes:

  • Replaced global quarkus.http.header.Content-Security-Policy with two quarkus.http.filter-based CSP header configurations (default + Swagger override).
  • Added changelog documentation explaining the root cause and why the filter-based approach was chosen.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/main/resources/application.properties Switches CSP from global header to per-path Quarkus HTTP filters (strict default + relaxed Swagger UI policy).
docs/changelog.md Documents the CSP/Swagger UI breakage root cause and the filter-based override rationale.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

font-src 'self'; frame-ancestors 'none';
# Swagger UI: relaxed CSP (order=20, higher priority — overrides default)
# Swagger UI requires 'unsafe-inline' + 'unsafe-eval' for inline scripts and JSON schema rendering.
quarkus.http.filter.csp-swagger.matches=/q/swagger-ui(/.*)?
Comment thread docs/changelog.md
### Fix
Replaced the global `quarkus.http.header.Content-Security-Policy` with two `quarkus.http.filter` entries using Quarkus's native path-based filter mechanism:
- **`csp-default`** (order=10, matches `/.*`): Strict CSP for the entire application — `script-src 'self'`
- **`csp-swagger`** (order=20, matches `/q/swagger-ui/.*`): Relaxed CSP — adds `'unsafe-inline' 'unsafe-eval'` to `script-src`
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