Skip to content

Commit

Permalink
fix(BA-632): Fix Broken CSS by allowing unsafe-inline CSP (#3572)
Browse files Browse the repository at this point in the history
Backported-from: main (25.1)
Backported-to: 24.09
Backport-of: 3572
  • Loading branch information
jopemachine committed Feb 4, 2025
1 parent 14f753b commit d3f6018
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions changes/3572.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix Broken CSS by allowing `unsafe-inline` content security policy.
2 changes: 1 addition & 1 deletion src/ai/backend/web/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def reject_access_for_unsafe_file_policy(request: web.Request) -> None:

def add_self_content_security_policy(response: web.StreamResponse) -> web.StreamResponse:
response.headers["Content-Security-Policy"] = (
"default-src 'self'; frame-ancestors 'none'; form-action 'self';"
"default-src 'self'; style-src 'self' 'unsafe-inline'; frame-ancestors 'none'; form-action 'self';"
)
return response

Expand Down
4 changes: 2 additions & 2 deletions tests/webserver/test_security_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def test_default_security_policy_response(default_app, async_handler) -> N
response = await security_policy_middleware(request, async_handler)
assert (
response.headers["Content-Security-Policy"]
== "default-src 'self'; frame-ancestors 'none'; form-action 'self';"
== "default-src 'self'; style-src 'self' 'unsafe-inline'; frame-ancestors 'none'; form-action 'self';"
)
assert response.headers["X-Content-Type-Options"] == "nosniff"

Expand Down Expand Up @@ -100,7 +100,7 @@ async def test_add_self_content_security_policy(async_handler) -> None:
response = await security_policy_middleware(request, async_handler)
assert (
response.headers["Content-Security-Policy"]
== "default-src 'self'; frame-ancestors 'none'; form-action 'self';"
== "default-src 'self'; style-src 'self' 'unsafe-inline'; frame-ancestors 'none'; form-action 'self';"
)


Expand Down

0 comments on commit d3f6018

Please sign in to comment.