Skip to content

eNotify 初始化接口只保留 POST,移除 GET /api/setup/:secret - #111

Merged
todosdev[bot] merged 1 commit into
mainfrom
tds/conv-01a14945-4c9b-78f7-9a79-345195f54567
Oct 17, 2026
Merged

todosdev[bot] merged 1 commit into
mainfrom
tds/conv-01a14945-4c9b-78f7-9a79-345195f54567

Conversation

@todosdev

@todosdev todosdev Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • 移除 GET /api/setup/:secret 初始化入口:setup secret 不再出现在 URL 中,避免泄露到浏览器历史、访问日志、Referer 和链接预览。
  • 初始化仅保留 POST /api/setup(secret 走 X-Setup-Secret 请求头,safeEqual 比较),行为保持不变。
  • 同步更新中英文 README 的初始化说明为 curl POST 示例。

Changes

  • worker/src/routes/setup.ts
    • 将 setupRoutes.get("/:secret", ...) 替换为 setupRoutes.get("*", ...):任何 GET /api/setup/* 一律返回 405,响应头带 Allow: POST,并提示改用 POST /api/setup + X-Setup-Secret 请求头,不再执行任何初始化/迁移。
    • POST /api/setup(读 X-Setup-Secret 头)逻辑原样保留。
  • README.md / README.en.md
    • 初始化步骤改为 curl -X POST … -H "X-Setup-Secret: <SETUP_SECRET>" 示例。
    • 补充「升级部署后可再次调用以执行数据库迁移」的说明。
    • 注明旧 GET /api/setup/<SETUP_SECRET> 已废弃(返回 405),并建议访问过旧 URL 的部署轮换 SETUP_SECRET。

Testing

  • 本地 wrangler dev --local 实测:
    • GET /api/setup/<正确secret> → 405 Method Not Allowed,带 Allow: POST,D1 无任何用户表变化(仅剩 miniflare 内部 _cf_METADATA)。
    • POST /api/setup + 正确 secret → 200 {"success":true};再次调用 → 200 {"success":true,"alreadyInitialized":true}(跑迁移)。
    • POST /api/setup + 错误 secret / 缺失 secret → 403 {"error":"Invalid setup secret"}。
  • pnpm lint、pnpm format:check、pnpm typecheck、pnpm build 全部通过。

- Replace GET /api/setup/:secret with a 405 handler (Allow: POST) so the
  setup secret no longer leaks into browser history, access logs, Referer,
  or link previews.
- Keep POST /api/setup (X-Setup-Secret header) unchanged, including
  safeEqual comparison and runMigrations on repeat calls.
- Update README.md / README.en.md to document the curl POST flow and
  recommend rotating SETUP_SECRET for deployments that used the old URL.

Checkpoint: 6JK1LKzo0sO2d4gQpz46f
@todosdev
todosdev Bot merged commit 0086a83 into main Oct 17, 2026
1 check passed
@mapxn
mapxn deleted the tds/conv-01a14945-4c9b-78f7-9a79-345195f54567 branch October 18, 2026 08:59
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