Skip to content

Commit

Permalink
Relaxed CSP headers
Browse files Browse the repository at this point in the history
  • Loading branch information
fbanados committed Oct 22, 2024
1 parent 153fceb commit ab42669
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/morphodict/site/securemiddleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@
Based on: https://github.com/TypeError/secure/blob/main/docs/frameworks.md#django
"""

from secure import Secure
from secure import Secure, ContentSecurityPolicy

secure_headers = Secure.with_default_headers()
# TODO Improve precision of style_src and remove unsafe-inline CSS

csp = (
ContentSecurityPolicy()
.default_src("'self'")
.script_src("'self'", "cdn.example.com")
.style_src("'self'", "fonts.googleapis.com", "'unsafe-inline'")
.img_src("'self'")
.connect_src("'self'", "speech-db.altlab.app")
.font_src("'self'", "fonts.gstatic.com", "fonts.googleapis.com")
)

secure_headers = Secure(csp=csp)


def set_secure_headers(get_response):
Expand Down

0 comments on commit ab42669

Please sign in to comment.