Skip to content

Commit da5d067

Browse files
authored
fix allow all frame_ancestors (#1552)
* fix allow all frame_ancestors Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com> * updated test cases Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com> --------- Signed-off-by: Keval Mahajan <mahajankeval23@gmail.com>
1 parent cadf02e commit da5d067

File tree

7 files changed

+7
-6
lines changed

7 files changed

+7
-6
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ SECURITY_HEADERS_ENABLED=true
536536
# "" (empty string): Allows all iframe embedding → frame-ancestors * file: http: https:
537537
# null or none: Completely removes iframe restrictions (no headers sent)
538538
# ALLOW-FROM uri: Allows specific domain (deprecated, use CSP instead)
539+
# ALLOW-ALL uri: Allows all (*, http, https)
539540
#
540541
# Both X-Frame-Options header and CSP frame-ancestors directive are automatically synced.
541542
# Modern browsers prioritize CSP frame-ancestors over X-Frame-Options.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@ ContextForge implements **OAuth 2.0 Dynamic Client Registration (RFC 7591)** and
16201620
> **iframe Embedding**: The gateway controls iframe embedding through both `X-Frame-Options` header and CSP `frame-ancestors` directive (both are automatically synced). Options:
16211621
> - `X_FRAME_OPTIONS=DENY` (default): Blocks all iframe embedding
16221622
> - `X_FRAME_OPTIONS=SAMEORIGIN`: Allows embedding from same domain only
1623-
> - `X_FRAME_OPTIONS=""`: Allows embedding from all sources (sets `frame-ancestors * file: http: https:`)
1623+
> - `X_FRAME_OPTIONS="ALLOW-ALL"`: Allows embedding from all sources (sets `frame-ancestors * file: http: https:`)
16241624
> - `X_FRAME_OPTIONS=null` or `none`: Completely removes iframe restrictions (no headers sent)
16251625
>
16261626
> Modern browsers prioritize CSP `frame-ancestors` over the legacy `X-Frame-Options` header. Both are now kept in sync automatically.

charts/mcp-stack/values.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@
487487
},
488488
"X_FRAME_OPTIONS": {
489489
"type": "string",
490-
"enum": ["DENY", "SAMEORIGIN"],
490+
"enum": ["DENY", "SAMEORIGIN", "ALLOW-ALL"],
491491
"description": "X-Frame-Options header value",
492492
"default": "DENY"
493493
},

docs/docs/architecture/adr/014-security-headers-cors-middleware.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ By default, iframe embedding is **disabled** for security via `X-Frame-Options:
213213

214214
1. **Same-domain embedding**: Set `X_FRAME_OPTIONS=SAMEORIGIN`
215215
2. **Specific domain embedding**: Set `X_FRAME_OPTIONS=ALLOW-FROM https://trusted-domain.com`
216-
3. **Disable frame protection**: Set `X_FRAME_OPTIONS=""` (not recommended)
216+
3. **Disable frame protection**: Set `X_FRAME_OPTIONS="ALLOW-ALL"` (not recommended)
217217

218218
**Note**: When changing X-Frame-Options, also consider updating the CSP `frame-ancestors` directive for comprehensive browser support.
219219

docs/docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ You can get started by copying the provided [.env.example](https://github.com/IB
11731173
>
11741174
> **Security Headers**: The gateway automatically adds configurable security headers to all responses including CSP, X-Frame-Options, X-Content-Type-Options, X-Download-Options, and HSTS (on HTTPS). All headers can be individually enabled/disabled. Sensitive server headers are removed.
11751175
>
1176-
> **iframe Embedding**: By default, `X-Frame-Options: DENY` prevents iframe embedding for security. To allow embedding, set `X_FRAME_OPTIONS=SAMEORIGIN` (same domain) or disable with `X_FRAME_OPTIONS=""`. Also update CSP `frame-ancestors` directive if needed.
1176+
> **iframe Embedding**: By default, `X-Frame-Options: DENY` prevents iframe embedding for security. To allow embedding, set `X_FRAME_OPTIONS=SAMEORIGIN` (same domain) or allow all with `X_FRAME_OPTIONS="ALLOW-ALL"`. Also update CSP `frame-ancestors` directive if needed.
11771177
>
11781178
> **Cookie Security**: Authentication cookies are automatically configured with HttpOnly, Secure (in production), and SameSite attributes for CSRF protection.
11791179
>

mcpgateway/middleware/security_headers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ async def dispatch(self, request: Request, call_next) -> Response:
295295
elif x_frame_upper.startswith("ALLOW-FROM"):
296296
allowed_uri = x_frame.split(" ", 1)[1] if " " in x_frame else "'none'"
297297
frame_ancestors = allowed_uri
298-
elif not x_frame: # Empty string means allow all (including file:// scheme)
298+
elif x_frame_upper == "ALLOW-ALL":
299299
frame_ancestors = "* file: http: https:"
300300
else:
301301
# Default to none for unknown values (matches DENY default)

tests/security/test_security_middleware_comprehensive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ class TestFrameAncestorsCSPConsistency:
622622
("DENY", "'none'"),
623623
("SAMEORIGIN", "'self'"),
624624
("ALLOW-FROM https://example.com", "https://example.com"),
625-
("", "*"), # Empty string should allow all
625+
("ALLOW-ALL", "*"), # Empty string should allow all
626626
("invalid-value", "'none'"), # Unknown values default to none
627627
],
628628
)

0 commit comments

Comments
 (0)