Skip to content

fix(gateway): HTTPS 服务默认注入 X-Frame-Options: SAMEORIGIN - #43

Merged
239573049 merged 1 commit into
239573049:mainfrom
xuzeyu91:master
Nov 13, 2026
Merged

239573049 merged 1 commit into
239573049:mainfrom
xuzeyu91:master

Conversation

@xuzeyu91

Copy link
Copy Markdown

X-Frame-Options: DENY 会连同源 iframe 一起禁止,把依赖「父窗口驱动同源预览」 的应用直接打断:预览空白,且浏览器拿到跨源空 frame 后持续抛 SecurityError。

  • 安全头改为「仅补齐、不覆盖」;上游已声明 X-Frame-Options 或 CSP frame-ancestors 时网关不再注入,避免反向代理改写源站策略
  • 新增服务级 FrameOptions 配置(SAMEORIGIN / DENY / NONE),默认 SAMEORIGIN; 旧 gateway.config 缺字段时同样取默认值,非法值回退以规避响应头注入
  • 管理界面「服务 → 功能设置」增加 iframe 嵌套策略选项
  • 新增 FrameOptionsTests,覆盖默认值、大小写、非法值回退、禁用与上游策略优先

Motivation and Context

How Has This Been Tested?

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

X-Frame-Options: DENY 会连同源 iframe 一起禁止,把依赖「父窗口驱动同源预览」
的应用直接打断:预览空白,且浏览器拿到跨源空 frame 后持续抛 SecurityError。

- 安全头改为「仅补齐、不覆盖」;上游已声明 X-Frame-Options 或 CSP
  frame-ancestors 时网关不再注入,避免反向代理改写源站策略
- 新增服务级 FrameOptions 配置(SAMEORIGIN / DENY / NONE),默认 SAMEORIGIN;
  旧 gateway.config 缺字段时同样取默认值,非法值回退以规避响应头注入
- 管理界面「服务 → 功能设置」增加 iframe 嵌套策略选项
- 新增 FrameOptionsTests,覆盖默认值、大小写、非法值回退、禁用与上游策略优先
Copilot AI balanced review requested due to automatic review settings November 13, 2026 01:40
@239573049
239573049 merged commit 7b3d717 into 239573049:main Nov 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The CSP substring check can mistake a reporting URL containing frame-ancestors for a framing directive, suppressing configured X-Frame-Options protection and leaving responses vulnerable to clickjacking.

1 open issue
What changed in this PR

This PR restores same-origin iframe support for HTTPS gateways by defaulting to X-Frame-Options: SAMEORIGIN, while preserving upstream security policies.

Changes:

  • Makes security-header injection additive rather than overwriting upstream values.
  • Adds per-service framing configuration and dashboard controls.
  • Adds policy-resolution tests and documents the behavior change.
File Description
web/​src/​types/​index.ts Defines framing options and the server configuration field.
web/​src/​pages/​server/​features/​UpdateServer.tsx Adds framing-policy selection when editing services.
web/​src/​pages/​server/​features/​CreateServer.tsx Adds framing-policy selection when creating services.
tests/​FastGateway.Tests/​FrameOptionsTests.cs Tests defaults, normalization, disabling, and upstream-policy precedence.
src/​FastGateway/​Services/​ServerService.cs Includes framing configuration in server-list responses.
src/​FastGateway/​Gateway/​Gateway.cs Updates security-header injection and resolves configured framing policies.
src/​FastGateway/​Dto/​ServerDto.cs Exposes framing configuration in the server DTO.
src/​Core/​Entities/​Server.cs Adds the persisted service-level framing setting.
CHANGELOG.md Documents the new behavior, configuration, and tests.

Review effort: Balanced

Comment on lines +645 to +646
csp.ToString().Contains("frame-ancestors",
StringComparison.OrdinalIgnoreCase);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants