Fix Swagger /docs page blocked by CSP#12
Merged
Conversation
Relax CSP for /docs and /openapi.json paths only, allowing cdn.jsdelivr.net for Swagger UI scripts and styles. All other paths retain the strict nonce-based CSP. The docs page serves no user data so the relaxed policy is safe.
Contributor
Greptile SummaryThis PR fixes Swagger UI being blocked by the application's Content-Security-Policy by introducing per-path CSP branching in Key changes:
Issues found:
Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Incoming Request] --> B[Generate request_id & csp_nonce]
B --> C[call_next — route handler]
C --> D[Apply common headers\nHSTS, X-Frame-Options, etc.]
D --> E{request.url.path\nin _SWAGGER_PATHS?}
E -- Yes\n/docs or /openapi.json --> F["Relaxed CSP\nscript-src 'self' 'unsafe-inline' cdn.jsdelivr.net\nstyle-src 'self' 'unsafe-inline' cdn.jsdelivr.net\nimg-src 'self' data: cdn.jsdelivr.net"]
E -- No\nall other paths --> G["Strict CSP\nscript-src 'self' 'nonce-{csp_nonce}'\nstyle-src 'self' 'unsafe-inline'\nimg-src 'self' data:"]
F --> H[Apply Cache-Control & Permissions-Policy]
G --> H
H --> I[Return Response]
Reviews (1): Last reviewed commit: "Fix Swagger /docs page blocked by CSP" | Re-trigger Greptile |
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.
Summary
/docsand/openapi.jsonpaths only, allowingcdn.jsdelivr.netfor Swagger UI scripts/stylesTest plan
make checkpasses (275 tests, 95.50% coverage)/docsin browser, verify Swagger UI renders and is interactive