Skip to content

Commit

Permalink
make security headers optional work with office.js via CDN
Browse files Browse the repository at this point in the history
  • Loading branch information
fzumstein committed Mar 28, 2024
1 parent 5497398 commit 0e35146
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


class Settings(BaseSettings):
add_security_headers: bool = True
base_dir: Path = Path(__file__).resolve().parent
cors_allow_origins: List[str] = ["*"]
development: bool = False
Expand Down
18 changes: 13 additions & 5 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,19 @@ async def add_security_headers(request, call_next):
# https://owasp.org/www-project-secure-headers/index.html#configuration-proposal
# https://owasp.org/www-project-secure-headers/ci/headers_add.json
response = await call_next(request)
with open(settings.base_dir / "security_headers.json", "r") as f:
data = json.load(f)

for header in data["headers"]:
response.headers[header["name"]] = header["value"]
if settings.add_security_headers:
with open(settings.base_dir / "security_headers.json", "r") as f:
data = json.load(f)

for header in data["headers"]:
response.headers[header["name"]] = header["value"]
if settings.public_addin_store:
response.headers["Content-Security-Policy"] = (
response.headers["Content-Security-Policy"]
+ "; script-src 'self' https://appsforoffice.microsoft.com;"
)
response.headers["Cross-Origin-Resource-Policy"] = "cross-origin"
del response.headers["Cross-Origin-Embedder-Policy"]
return response


Expand Down

0 comments on commit 0e35146

Please sign in to comment.