Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <SETUP_SECRET>"
```
https://your-worker.workers.dev/api/setup/<SETUP_SECRET>
```

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/<SETUP_SECRET>` 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

Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <SETUP_SECRET>"
```
https://your-worker.workers.dev/api/setup/<SETUP_SECRET>
```

每次升级部署后可再次调用一次,以执行数据库迁移(数据库已初始化时会自动运行迁移)。

> 旧的 `GET /api/setup/<SETUP_SECRET>` 地址已废弃(返回 405)。如果你曾通过旧 GET 地址访问过部署,建议轮换 `SETUP_SECRET`,因为 secret 可能已泄露到浏览器历史或访问日志中。

### 5. 注册管理员

Expand Down
23 changes: 12 additions & 11 deletions worker/src/routes/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ const DEFAULT_SETTINGS: Record<string, string> = {
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) => {
Expand Down
Loading