fix: SecurityHeadersMiddleware の CSP を OpenAPI パスで除外する (#112)#116
Merged
Conversation
Content-Security-Policy: default-src 'self' が /docs・/redoc・/openapi.json に 付与されると、CDN からアセットを読み込む Swagger UI と ReDoc が動作しなくなる問題を修正。 OpenAPI ドキュメントパスでは CSP ヘッダーのみスキップし、 X-Content-Type-Options 等の他のセキュリティヘッダーは引き続き付与する。 テスト1件追加: /docs・/redoc・/openapi.json への CSP 不付与を確認 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
Content-Security-Policy: default-src 'self'が/docs・/redoc・/openapi.jsonに付与されると Swagger UI / ReDoc が CDN アセットを読み込めず壊れる問題を修正_OPENAPI_PATHS = frozenset({"/docs", "/redoc", "/openapi.json"})で対象パスを定義Closes #112
Test plan
uv run pytest tests/nene2/middleware/test_security_headers.py -vが全パスすることhttp://localhost:8080/docsで Swagger UI が正常表示されること🤖 Generated with Claude Code