Skip to content

Instantly share code, notes, and snippets.

View m-lukas's full-sized avatar
:octocat:
Again more curious

Lukas Müller m-lukas

:octocat:
Again more curious
View GitHub Profile
@m-lukas
m-lukas / swagger_ui_content_security_policy.md
Created March 9, 2023 16:46
Content-Security-Policy with Swagger UI (e.g. for FastAPI)

How to enable Content-Security-Policy with Swagger UI

Swagger UI includes an inline-script which makes it more difficult to enforce the Content-Security-Policy header. This Gist shows a way to add an exception for Swagger UI in order to be able to enforce the policy to an effectiv level. This is useful for example in FastAPI where Swagger UI is added automatically for API documentation.

Adding the header