Fixes CSP directive blocking the iframe issue #1537
Merged
+55
−24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🐛 Bug-fix PR
📌 Summary
Fixes iframe embedding issue where CSP
frame-ancestorsdirective was always set even when users configuredX_FRAME_OPTIONSto allow embedding. PR #1352 fixed theX-Frame-Optionsheader but missed the CSPframe-ancestorsdirective, which takes precedence in modern browsers.frame-ancestorswithX-Frame-OptionsconfigurationX_FRAME_OPTIONS=nullto completely disable iframe restrictionsfile:scheme support forX_FRAME_OPTIONS=""to enable testing🔗 Related Issue
#1327
🐞 Root Cause
X-Frame-Optionsheader handling but not the CSPframe-ancestorsdirectiveframe-ancestorswas always being added to responses based onX_FRAME_OPTIONSvalueframe-ancestorsdirective (evenX_FRAME_OPTIONS=""addedframe-ancestors *)X-Frame-Options, causing iframe blocking*in CSP doesn't includefile://scheme, breaking local testing🧪 Verification
X_FRAME_OPTIONS=null→ curl shows NO frame-ancestorsX_FRAME_OPTIONS=""→ curl showsframe-ancestors * file: http: https:X_FRAME_OPTIONS=DENY→ curl showsframe-ancestors 'none'✅Testing Checklist
📐 MCP Compliance
X_FRAME_OPTIONS=DENY)nullor""to enable embedding📄 Files Changed
mcpgateway/config.py- Added validator to normalize "null"/"none" stringsmcpgateway/middleware/security_headers.py- Conditional CSP frame-ancestors logicREADME.md- Updated iframe embedding documentation.env.example- Comprehensive X_FRAME_OPTIONS comments💡 Configuration Options After Fix
X_FRAME_OPTIONSDENY(default)DENY'none'SAMEORIGINSAMEORIGIN'self'""(empty)* file: http: https:nullornone