diff --git a/README.en.md b/README.en.md index 5322dea..9047970 100644 --- a/README.en.md +++ b/README.en.md @@ -76,11 +76,16 @@ Push to `main` branch to trigger automatic deployment. ### 4. Initialize Database -After deployment, visit the following URL to initialize the database: +After deployment, initialize the database with a POST request (the secret goes in a header so it never appears in the URL, browser history, or access logs): +```bash +curl -X POST https://your-worker.workers.dev/api/setup \ + -H "X-Setup-Secret: " ``` -https://your-worker.workers.dev/api/setup/ -``` + +You can call it again after each upgrade/deploy to run database migrations (migrations run automatically when the database is already initialized). + +> The old `GET /api/setup/` URL is deprecated and returns 405. If you ever visited that URL against a deployment, rotate `SETUP_SECRET`, since the secret may have leaked into browser history or access logs. ### 5. Register Admin diff --git a/README.md b/README.md index 04289f6..05b2312 100644 --- a/README.md +++ b/README.md @@ -76,11 +76,16 @@ npx wrangler kv namespace create ENOTIFY_KV ### 4. 初始化数据库 -部署完成后,访问以下 URL 初始化数据库: +部署完成后,使用 curl 发送 POST 请求初始化数据库(secret 放在请求头,避免出现在 URL / 浏览器历史 / 访问日志中): +```bash +curl -X POST https://your-worker.workers.dev/api/setup \ + -H "X-Setup-Secret: " ``` -https://your-worker.workers.dev/api/setup/ -``` + +每次升级部署后可再次调用一次,以执行数据库迁移(数据库已初始化时会自动运行迁移)。 + +> 旧的 `GET /api/setup/` 地址已废弃(返回 405)。如果你曾通过旧 GET 地址访问过部署,建议轮换 `SETUP_SECRET`,因为 secret 可能已泄露到浏览器历史或访问日志中。 ### 5. 注册管理员 diff --git a/worker/src/routes/setup.ts b/worker/src/routes/setup.ts index ff9ab1c..4c9dfe7 100644 --- a/worker/src/routes/setup.ts +++ b/worker/src/routes/setup.ts @@ -17,17 +17,18 @@ const DEFAULT_SETTINGS: Record = { app_name: "eNotify", }; -setupRoutes.get("/:secret", async (c) => { - const secret = c.req.param("secret"); - - if ( - !c.env.SETUP_SECRET || - !(await safeEqual(secret ?? "", c.env.SETUP_SECRET)) - ) { - return c.json({ error: "Invalid setup secret" }, 403); - } - - return runSetup(c); +// GET /api/setup/* is deprecated for security: the secret must never appear in +// the URL (browser history, access logs, Referer, link previews). Use +// POST /api/setup with the X-Setup-Secret header instead. +setupRoutes.get("*", (c) => { + c.header("Allow", "POST"); + return c.json( + { + error: + "GET setup is deprecated. Use POST /api/setup with the X-Setup-Secret header.", + }, + 405, + ); }); setupRoutes.post("/", async (c) => {