fix: add 'unsafe-inline' to script-src CSP

swagger-ui uses inline javascript to bootstrap itself, so we need to
allow unsafe inline because we can't give swagger-ui a nonce to embed.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2022-09-12 12:28:42 -07:00
parent 37c7dee099
commit adc3a21863
No known key found for this signature in database
GPG key ID: F7E46DED420788F3

View file

@ -256,7 +256,9 @@ async def add_security_headers(request: Request, call_next: typing.Callable):
# swagger-ui needs access to cdn.jsdelivr.net javascript # swagger-ui needs access to cdn.jsdelivr.net javascript
script_hosts = ["cdn.jsdelivr.net"] script_hosts = ["cdn.jsdelivr.net"]
csp += f"script-src 'self' 'nonce-{nonce}' " + " ".join(script_hosts) csp += f"script-src 'self' 'unsafe-inline' 'nonce-{nonce}' " + " ".join(
script_hosts
)
# swagger-ui needs access to cdn.jsdelivr.net css # swagger-ui needs access to cdn.jsdelivr.net css
css_hosts = ["cdn.jsdelivr.net"] css_hosts = ["cdn.jsdelivr.net"]