Skip to content

nav 堵搜索框当前页跳转的 Referer(外科式,noreferrer 锚点) - #36

Merged
todosdev[bot] merged 1 commit into
mainfrom
tds/conv-01a1b0dd-43c8-729e-8401-5909ceee4ff3
Nov 6, 2026
Merged

todosdev[bot] merged 1 commit into
mainfrom
tds/conv-01a1b0dd-43c8-729e-8401-5909ceee4ff3

Conversation

@todosdev

@todosdev todosdev Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • 堵住主页搜索框在「当前页打开」(站点设置 searchNewTab=false)时唯一一处 Referer 泄漏:原来走 window.location.href,浏览器按默认策略(strict-origin-when-cross-origin)会把本站 origin 发给搜索引擎。
  • 同页跳转改由临时 <a rel="noreferrer" target="_self"> 点击完成,rel="noreferrer" 只作用于这一次导航;新标签搜索、链接卡片等其它外跳与图标/壁纸等资源加载的行为一律不变,也未引入页面级 <meta name="referrer">。

Changes

  • web/src/components/search-bar.tsx
    • 新增 navigateSameTabWithoutReferrer(url):建锚点 → 设 rel="noreferrer" → 插入 body → 点击 → 立即移除。
    • submit() 的当前页分支由 window.location.href = url 改为调用该函数;新标签分支 window.open(url, "_blank", "noopener,noreferrer") 一行未动。
  • web/test/search-bar.test.tsx
    • window.location 桩改为带写入计数:同页跳转若退回 location.href,断言立刻失败。
    • 同页用例断言被点锚点 rel="noreferrer"、target="_self"、href 正确、点完已移出 DOM;新标签用例断言不写 location、不点锚点;另加 helper 的直接单测与空查询不点锚点。
  • web/test/public-page.test.tsx:searchNewTab=false 的集成用例改为断言锚点契约(PublicPage 全链路渲染),不再断言 location 被改写。

Testing

  • CI(workflow_dispatch,commit be52861):success,Lint / Format check / Type check / Build / Test 全部通过 — https://github.com/WorkerHub/nav/actions/runs/42220884446 ;其中 worker 193 用例、web 213 用例通过。
  • 真实浏览器实测(Chrome 158 无头 + CDP 驱动真敲字回车,本地探针服务器冒充搜索站并记录请求头;开发模式、数据来自仓库自带 mockDb):
    • searchNewTab=false:修复前 referer: http://localhost:57649/ → 修复后 referer: null,且页面确实完成跳转。
    • searchNewTab=true:修复前后均 referer: null、起始页不动,行为不变。
  • 本地复现 CI 五步:pnpm lint(退出码 0,仅存量 warning)、format:check、typecheck、build、test 全绿。
  • 未覆盖:Safari / Firefox 的真实请求头(本机只有 Chrome),按 HTML 标准锚点 rel="noreferrer" 同样强制 no-referrer。

Same-tab search now navigates through a temporary rel="noreferrer" anchor
instead of window.location.href, so the engine no longer receives this
site's origin. New-tab path and other outbound links are untouched; tests
assert the anchor contract and that location is never written.

Checkpoint: c_hgEIUTPf23SAyywVp-J
@todosdev
todosdev Bot merged commit 68ae803 into main Nov 6, 2026
2 checks passed
@mapxn
mapxn deleted the tds/conv-01a1b0dd-43c8-729e-8401-5909ceee4ff3 branch November 8, 2026 12:42
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.

0 participants