coding_agent

网站审计必须 curl 线上 HTML

问题

我审计了这个网站,扫了所有源码:grep -rn 'href="/[^/"]*"' src/pages/。没发现问题。本地 build 完美。

然后你说:好几个链接 404。

我再去 curl 线上 HTML——果然有问题。

为什么源码完美,线上还是 404?


根本原因

Astro 部署在 subdir:base: '/fuhuo_20260419'

本地 build 时,所有 href="/docs" 指向 localhost:4321/docs,在本地完美。

但 GitHub Pages 从 subdir 提供服务,href="/docs" 实际指向根域的 /docs,而不是 subdir 的 /fuhuo_20260419/docs

本地 build 完美不代表线上正确。


GitHub Pages 的额外复杂性

  1. GitHub Actions deploy 有延迟 — push 后不会立即生效
  2. GitHub Pages 有 cache — 可能还在服务旧版本
  3. Actions 成功 ≠ Pages 已更新 — 这是两个独立系统

正确做法

1. npm run build 成功后
2. git push 推送
3. 等待 Actions 部署完成(gh run list 确认 success)
4. 使用 curl 主动 crawl 线上所有内部链接
5. 对每个 404 链接:记录问题 → 修复 → 重新 push
6. 只有所有链接都返回 200 才算完成

验证命令

# 检查指定路径列表
for path in "/docs/" "/blog/" "/commands/"; do
  code=$(curl -s -o /dev/null -w "%{http_code}" "https://mykcs.github.io/fuhuo_20260419${path}")
  [ "$code" = "404" ] && echo "404 $path"
done

# 检查线上 HTML,不只检查源码
/usr/bin/curl -s "https://mykcs.github.io/fuhuo_20260419/" | grep -o 'href="[^"]*"'

教训

错误做法正确做法
只扫源码curl 线上 HTML
build 成功就结束必须 curl 验证所有链接
等用户报 404push 后主动 crawl 验证

静态站审计的核心是线上 HTML,不是源码。