Skip to content

[Bug] HTTP 隧道动态 script/link 资源绕过路径改写并返回 404 #808

Description

@yovinchen

Affected area

Gateway (agent-gateway / Go)

Version or commit

v1.3.5 / main@4eb6a4a8

Environment

自托管 Docker Gateway,macOS Apple Silicon Desktop 提供本地 HTTP 服务;使用 Chromium 访问 /t/<slug>/ 公开隧道。

Steps to reproduce

  1. 本地服务提供首页和 /lazy-root.js,脚本执行时设置一个可观察的成功标志。
  2. 首页动态插入脚本:
const script = document.createElement('script');
script.src = '/lazy-root.js';
document.head.appendChild(script);
  1. 直接访问本地首页,确认脚本加载成功。
  2. 通过 Gateway /t/<slug>/ 访问相同首页,检查脚本请求路径和执行结果。

Expected behavior

动态脚本请求经过 /t/<slug>/lazy-root.js 转发并执行。动态 link.href 样式资源也应保持同样的隧道前缀。

Actual behavior

浏览器请求 Gateway 根路径 /lazy-root.js 并返回 404,动态脚本不执行。首页及其他 API 请求可以正常返回,链路/中继/本地服务检查也可保持绿色。

Logs / investigation

直接本地页面:/lazy-root.js                200
原版隧道页面:/lazy-root.js                404
手动带前缀:  /t/<slug>/lazy-root.js        200

现有运行时包装了 fetch、XHR、WebSocket 和 EventSource,但浏览器原生的 script/link 资源加载器不经过 window.fetch。HTML 响应改写也无法处理页面运行后创建的节点。应在原生属性赋值或节点插入之前同步改写;MutationObserver 不能阻止首次错误请求。

此报告限定为动态 DOM script/link 资源路径,不要求透明支持所有 SPA 的原生 ESM 根路径导入、Worker、客户端路由或动态 HTML 字符串。

Pre-submit checklist

  • I searched existing issues and pull requests and found no duplicates.
  • This is not a security vulnerability.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions