Skip to content

Security: WebSocket Origin Check Bypass via Spoofed X-Forwarded-Proto Header - #333

Closed
tomaioo wants to merge 1 commit into
Stack-Cairn:mainfrom
tomaioo:fix/security/websocket-origin-check-bypass-via-spoofe
Closed

Security: WebSocket Origin Check Bypass via Spoofed X-Forwarded-Proto Header#333
tomaioo wants to merge 1 commit into
Stack-Cairn:mainfrom
tomaioo:fix/security/websocket-origin-check-bypass-via-spoofe

Conversation

@tomaioo

@tomaioo tomaioo commented Jul 30, 2026

Copy link
Copy Markdown

Summary

Security: WebSocket Origin Check Bypass via Spoofed X-Forwarded-Proto Header

Problem

Severity: Medium | File: crates/agent-gateway/internal/protocol/shared/origin.go:L43

The OriginAllowed function in origin.go determines the request's scheme by reading the X-Forwarded-Proto HTTP header. If an attacker can send requests directly to the gateway (bypassing a proxy) or if the proxy does not strip client-provided X-Forwarded-Proto headers, the attacker can spoof the scheme. By setting X-Forwarded-Proto: https on an HTTP request, the attacker forces the server to construct an https request URL, which could bypass same-origin checks or loopback allowances designed for secure connections.

Solution

Do not trust client-provided headers for origin security checks unless the gateway is explicitly configured to run behind a trusted reverse proxy. Rely on r.TLS to determine the scheme, or introduce a configuration flag that explicitly enables trusting X-Forwarded-* headers only when behind a known proxy.

Changes

  • crates/agent-gateway/internal/protocol/shared/origin.go (modified)

The `OriginAllowed` function in `origin.go` determines the request's scheme by reading the `X-Forwarded-Proto` HTTP header. If an attacker can send requests directly to the gateway (bypassing a proxy) or if the proxy does not strip client-provided `X-Forwarded-Proto` headers, the attacker can spoof the scheme. By setting `X-Forwarded-Proto: https` on an HTTP request, the attacker forces the server to construct an `https` request URL, which could bypass same-origin checks or loopback allowances designed for secure connections.

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

PR governance checks failed — this PR has been converted to draft.

  • No linked issue: the PR body must contain Closes #123 / Fixes #123 / Resolves #123. This project requires an issue before a PR — see the contribution guidelines.

Fix the items above, then click Ready for review to re-run the checks.

@su-fen su-fen closed this Aug 8, 2026
ouoiouo pushed a commit to ouoiouo/LiveAgent that referenced this pull request Aug 8, 2026
ouoiouo pushed a commit to ouoiouo/LiveAgent that referenced this pull request Aug 8, 2026
…proxy SVG

- agent/terminal WS 链路升级后立即设置读超时,读循环按 idleTimeout
  续期(3×心跳周期+宽限,与浏览器链 wscore 一致):未鉴权静默连接
  不再能永久占满连接槽(DoS)
- /image-proxy 对 SVG 响应附加 sandbox CSP:<img> 加载不受影响,
  顶层导航的恶意 SVG 无法执行脚本(防网关源 XSS/token 窃取)
- origin 校验不再信任 X-Forwarded-Proto(同步上游 PR Stack-Cairn#333),
  更新对应测试为忽略伪造头的新语义
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.

2 participants