fix: relax CSP for Swagger UI /docs route - #573
Open
Henrypave wants to merge 3 commits into
Open
Conversation
|
@Henrypave Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Overview
This PR fixes the blank/non-functional Swagger UI at
/docsby preventing the globalscript-src 'self'CSP from blocking the inline bootstrap script generated byswagger-ui-express. The strict security header policy remains active for every other route, and the raw OpenAPI spec at/docs.jsoncontinues to work unchanged.Related Issue
Closes the reported issue: Swagger UI at
/docsis broken by the samescript-src 'self'CSP.Changes
🛡️ Per-Route CSP Relaxation for
/docs[MODIFY]
src/middleware/securityHeaders.ts/docsis served withoutscript-src 'self'(or with a nonce-free relaxed policy that allows the Swagger bootstrap inline script)./docsroutes, including/graphql-playgroundbehavior unchanged.[MODIFY]
src/index.tsapp.use("/docs", swaggerUi.serve, swaggerUi.setup(openApiSpec))./docs.jsonremains accessible and is not affected by the global or relaxed CSP.[ADD] Browser-level verification step
/docswith devtools and confirm no CSP violation errors for inline scripts./docs.json.Verification Results
/docsrenders a functional Swagger UIscript-src 'self'is bypassed only for/docs/docs.jsonremains available/docsroutes retainscript-src 'self'Closes #519