fix(proxy): 非 ASCII docs 路径 edge 直接 404,避免 x-next-cache-tags 500#371
Merged
Conversation
爬虫构造的不存在中文 docs 路径(如 ".../你的图片.jpg \"悬停名\"")会进 [...slug] 的运行时动态渲染,Vercel 把中文写进 x-next-cache-tags 响应头, Node 拒绝 >0xFF 的 header 字符 → 未捕获 TypeError → 500。上游 vercel/next.js#92145 未修,页面内拦不住(崩溃在 notFound() 之后的框架层)。 - matcher 的 dot-path 排除新增 docs 例外(对齐 leetcode 例外),让带点的 垃圾路径能进 middleware;/docs/ URL 下无真实静态资源,放开安全 - 新增 isPoisonedDocsPath:解码后仍含 >0xFF 字符的 docs 路径返回裸 404。 合法 docs slug 全 ASCII(中文 leetcode 旧 URL 由 slug-map 先行 301, doc_paths 历史表无非 leetcode 中文行),不误伤 resolve 重定向 - ASCII 未知路径仍走 page.tsx 的 resolve→301/404 流程,行为不变 Fixes INVOLUTIONHELL-FRONTEND-4 Closes #370 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RtSNVtrEkCsFVHrbt4Zjgi
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Co-authored-by: github-code-quality[bot] <github-code-quality[bot]@users.noreply.github.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RtSNVtrEkCsFVHrbt4Zjgi
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RtSNVtrEkCsFVHrbt4Zjgi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
问题
Closes #370 / Sentry INVOLUTIONHELL-FRONTEND-4(197 次)
爬虫访问不存在的中文 docs 路径(如
.../你的图片.jpg "自定义鼠标悬停显示名",AhrefsBot 把文档里反引号包的示例代码当链接爬)→ 未知 slug 走运行时动态渲染 → Vercel 把中文写进x-next-cache-tags响应头 → Node 拒绝 >0xFF header 字符 → 未捕获 TypeError → 500。上游 vercel/next.js#92145 因缺复现被关(未修),升级 16.2.10 无效;页面内拦不住(崩溃发生在
notFound()返回之后的框架层 header 写入)。方案
在
proxy.ts(edge)把「解码后仍含 >0xFF 字符的 docs 路径」直接裸 404:.jpg,不放开根本进不了 middleware。public/下没有任何/docs/...路径的静态资源,安全。lib/poisoned-docs-path.ts:守卫函数(独立模块是为了 vitest 可测,proxy.ts引 next-intl 在 node 环境 import 不动)。为什么不会误伤
content/docs/非 ASCII 文件名只在 leetcode 目录,其 canonical URL 全是拼音(slug-map 68 个目标 0 非 ASCII)doc_paths499 行历史路径实测 SQL:非 leetcode 的非 ASCII 行 = 0[object Object]这类垃圾)仍走 page.tsx 的 resolve→301/404 流程,行为不变验证
pnpm test67 通过(新增 15 用例:守卫函数 + matcher 不变量,含 PR 🔥 hotfix(proxy): matcher 排除 oauth/auth/analytics,修复登录 404 #335 oauth 排除回归)pnpm typecheck/pnpm lint(0 error)pnpm devcurl 矩阵:中文垃圾路径 404 裸响应 / 正常 docs 页 200 / 旧中文 leetcode URL 301 到拼音 //oauth/render/github不被加 locale 前缀 / ASCII 垃圾路径走 resolve 404pnpm build通过,/[locale]/docs/[...slug]仍为 ● SSG附带收益:这类垃圾请求不再进 Fluid lambda、不再打后端 resolve 接口。
Fixes INVOLUTIONHELL-FRONTEND-4
🤖 Generated with Claude Code
https://claude.ai/code/session_01RtSNVtrEkCsFVHrbt4Zjgi