Skip to content

Commit 7ddd4f4

Browse files
committed
update to fix tests
Signed-off-by: Shoumi <[email protected]>
1 parent 93582a6 commit 7ddd4f4

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

mcpgateway/middleware/security_headers.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -273,25 +273,21 @@ async def dispatch(self, request: Request, call_next) -> Response:
273273
# Content Security Policy
274274
# This CSP is designed to work with the Admin UI while providing security
275275
# Dynamically set frame-ancestors based on X_FRAME_OPTIONS setting to stay consistent
276-
if settings.x_frame_options is None:
277-
# No X-Frame-Options configured, default to self
276+
x_frame = str(settings.x_frame_options)
277+
x_frame_upper = x_frame.upper()
278+
279+
if x_frame_upper == "DENY":
280+
frame_ancestors = "'none'"
281+
elif x_frame_upper == "SAMEORIGIN":
278282
frame_ancestors = "'self'"
283+
elif x_frame_upper.startswith("ALLOW-FROM"):
284+
allowed_uri = x_frame.split(" ", 1)[1] if " " in x_frame else "'none'"
285+
frame_ancestors = allowed_uri
286+
elif not x_frame: # Empty string means allow all
287+
frame_ancestors = "*"
279288
else:
280-
x_frame = str(settings.x_frame_options)
281-
x_frame_upper = x_frame.upper()
282-
283-
if x_frame_upper == "DENY":
284-
frame_ancestors = "'none'"
285-
elif x_frame_upper == "SAMEORIGIN":
286-
frame_ancestors = "'self'"
287-
elif x_frame_upper.startswith("ALLOW-FROM"):
288-
allowed_uri = x_frame.split(" ", 1)[1] if " " in x_frame else "'none'"
289-
frame_ancestors = allowed_uri
290-
elif not x_frame: # Empty string means allow all
291-
frame_ancestors = "*"
292-
else:
293-
# Default to self for unknown values
294-
frame_ancestors = "'self'"
289+
# Default to none for unknown values (matches DENY default)
290+
frame_ancestors = "'none'"
295291

296292
csp_directives = [
297293
"default-src 'self'",

0 commit comments

Comments
 (0)