Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

Support plaintext login password secrets

yoma4ddc27d4a1f6
diff --git a/.env.local.example b/.env.local.example
index 32606632..f79b3016 100644
--- a/.env.local.example
+++ b/.env.local.example
@@ -64,13 +64,9 @@ EDGE_EVER_R2_PREVIEW_BUCKET_NAME=edgeever-resources-preview
# Login username.
EDGE_EVER_AUTH_USERNAME=admin
-# PBKDF2-SHA256 hash of the login password.
-# Generate it with: `bun run auth:hash -- <your-password>`
-# For multi-instance deployments, use `EDGE_EVER_<INSTANCE>_AUTH_PASSWORD_HASH`
-# to configure a different password for each instance.
-# For Workers Builds, store this as a Cloudflare Build Secret. The deploy command
-# synchronizes it to the runtime Worker Secret after every successful deployment.
-EDGE_EVER_AUTH_PASSWORD_HASH=
+# Login password. Store it as a Cloudflare Secret.
+# Example: EDGE_EVER_AUTH_PASSWORD=Admin123
+EDGE_EVER_AUTH_PASSWORD=
# Web session lifetime in days. The server limits it to 1-400 days.
EDGE_EVER_SESSION_TTL_DAYS=400
diff --git a/README.md b/README.md
index ef219267..f104f79d 100644
--- a/README.md
+++ b/README.md
@@ -68,7 +68,7 @@ After the first deployment, see [Cloudflare Workers Builds](docs/cloudflare-work
Please refer to the [Cloudflare Manual Deployment Guide](docs/manual-deploy.md) for first-time manual installation, Cloudflare resource setup, and emergency recovery. After the first deployment, connect Workers Builds; future updates arrive through GitHub **Sync fork** or pushes to `main`.
-The automated helper commands are recommended. If you create the Cloudflare resources manually, finish configuring `.env.local`—including the D1 ID, R2 bucket, password hash, and the 400-day session limit—before running `bun run deploy`. Use that command only for first installation and emergency recovery; Workers Builds handles routine updates.
+The automated helper commands are recommended. If you create the Cloudflare resources manually, finish configuring `.env.local`—including the D1 ID, R2 bucket, login password Secret, and the 400-day session limit—before running `bun run deploy`. Existing installations that use `EDGE_EVER_AUTH_PASSWORD_HASH` remain supported. Use that command only for first installation and emergency recovery; Workers Builds handles routine updates.
## PWA Installation
diff --git a/apps/api/src/auth-bootstrap.ts b/apps/api/src/auth-bootstrap.ts
new file mode 100644
index 00000000..51bd075f
--- /dev/null
+++ b/apps/api/src/auth-bootstrap.ts
@@ -0,0 +1,40 @@
+type PasswordHashVerifier = (password: string, passwordHash: string) => Promise<boolean>;
+
+export const hasBootstrapCredential = (password: string | undefined, passwordHash: string | undefined) =>
+ Boolean(password || passwordHash?.trim());
+
+export const verifyBootstrapPassword = async (
+ password: string,
+ configuredPassword: string | undefined,
+ configuredPasswordHash: string | undefined,
+ verifyPasswordHash: PasswordHashVerifier,
+) => {
+ const passwordHash = configuredPasswordHash?.trim();
+
+ if (passwordHash) {
+ return verifyPasswordHash(password, passwordHash);
+ }
+
+ if (configuredPassword === undefined || configuredPassword.length === 0) {
+ return false;
+ }
+
+ const encoder = new TextEncoder();
+ const [providedHash, expectedHash] = await Promise.all([
+ crypto.subtle.digest("SHA-256", encoder.encode(password)),
+ crypto.subtle.digest("SHA-256", encoder.encode(configuredPassword)),
+ ]);
+
+ return timingSafeEqual(new Uint8Array(providedHash), new Uint8Array(expectedHash));
+};
+
+const timingSafeEqual = (left: Uint8Array, right: Uint8Array) => {
+ const length = Math.max(left.length, right.length);
+ let diff = left.length ^ right.length;
+
+ for (let index = 0; index < length; index += 1) {
+ diff |= (left[index % left.length] ?? 0) ^ (right[index % right.length] ?? 0);
+ }
+
+ return diff === 0;
+};
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index 3fec7200..d9e509f2 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -47,11 +47,13 @@ import { Hono } from "hono";
import { deleteCookie, getCookie, setCookie } from "hono/cookie";
import { cors } from "hono/cors";
import openApiSpec from "../../../docs/openapi.json";
+import { hasBootstrapCredential, verifyBootstrapPassword } from "./auth-bootstrap";
type Bindings = {
DB: D1Database;
RESOURCES: R2Bucket;
EDGE_EVER_AUTH_USERNAME?: string;
+ EDGE_EVER_AUTH_PASSWORD?: string;
EDGE_EVER_AUTH_PASSWORD_HASH?: string;
EDGE_EVER_SESSION_TTL_DAYS?: string;
EDGE_EVER_R2_BUCKET_NAME?: string;
@@ -3138,7 +3140,7 @@ const escapeMarkdownImageAlt = (value: string) => value.replace(/[\\[\]]/g, "\\$
const escapeMarkdownLinkLabel = (value: string) => value.replace(/[\\[\]]/g, "\\$&");
const isAuthRequired = async (env: Bindings) => {
- if (env.EDGE_EVER_AUTH_PASSWORD_HASH?.trim()) {
+ if (hasBootstrapCredential(env.EDGE_EVER_AUTH_PASSWORD, env.EDGE_EVER_AUTH_PASSWORD_HASH)) {
return true;
}
@@ -3155,14 +3157,26 @@ const verifyLogin = async (env: Bindings, username: string, password: string): P
}
const configuredHash = env.EDGE_EVER_AUTH_PASSWORD_HASH?.trim();
+ const configuredPassword = env.EDGE_EVER_AUTH_PASSWORD;
- if (!configuredHash) {
+ if (!configuredHash && !configuredPassword) {
return null;
}
const configuredUsername = env.EDGE_EVER_AUTH_USERNAME?.trim() || "admin";
- if (normalizedUsername !== configuredUsername || !(await verifyPassword(password, configuredHash))) {
+ if (normalizedUsername !== configuredUsername) {
+ return null;
+ }
+
+ const passwordMatches = await verifyBootstrapPassword(
+ password,
+ configuredPassword,
+ configuredHash,
+ verifyPassword,
+ );
+
+ if (!passwordMatches) {
return null;
}
diff --git a/docs/agent-deploy-cloudflare.md b/docs/agent-deploy-cloudflare.md
index 154b5fd7..4241ccac 100644
--- a/docs/agent-deploy-cloudflare.md
+++ b/docs/agent-deploy-cloudflare.md
@@ -70,7 +70,7 @@ Chinese version:
- copy `.env.local.example` to `.env.local` when needed
- reuse or create the D1 database
- create the R2 buckets when needed
- - generate `EDGE_EVER_AUTH_PASSWORD_HASH` from `EDGE_EVER_PASSWORD`
+ - save `EDGE_EVER_PASSWORD` as `EDGE_EVER_AUTH_PASSWORD` in the private `.env.local`
5. Check the deployment inputs.
@@ -86,7 +86,7 @@ Chinese version:
bun run deploy
```
- `bun run deploy` builds the web app, applies remote D1 migrations, and deploys the Worker. During deploy, `scripts/run-wrangler.mjs` uploads `EDGE_EVER_AUTH_PASSWORD_HASH` as a Worker Secret via a generated `.env.wrangler.generated*.secrets` file, then synchronizes it again with `wrangler secret put` after a successful deployment so the first login does not depend on the bulk secrets upload alone.
+ `bun run deploy` builds the web app, applies remote D1 migrations, and deploys the Worker. During deploy, `scripts/run-wrangler.mjs` uploads `EDGE_EVER_AUTH_PASSWORD` as a Worker Secret via a generated `.env.wrangler.generated*.secrets` file, then synchronizes it again with `wrangler secret put` after a successful deployment so the first login does not depend on the bulk secrets upload alone. Existing `EDGE_EVER_AUTH_PASSWORD_HASH` configurations remain supported and take precedence when both Secrets exist.
7. Verify the result.
@@ -121,6 +121,7 @@ EDGE_EVER_D1_DATABASE_NAME=edgeever
EDGE_EVER_R2_BUCKET_NAME=edgeever-resources
EDGE_EVER_R2_PREVIEW_BUCKET_NAME=edgeever-resources-preview
EDGE_EVER_AUTH_USERNAME=admin
+EDGE_EVER_AUTH_PASSWORD=<login-password>
EDGE_EVER_SESSION_TTL_DAYS=400
EDGE_EVER_CUSTOM_DOMAIN=notes.example.com
```
@@ -131,9 +132,11 @@ For multiple instances, set `EDGE_EVER_INSTANCE=<name>` and use scoped variables
EDGE_EVER_PROD_WORKER_NAME=edgeever-prod
EDGE_EVER_PROD_D1_DATABASE_ID=<database-id>
EDGE_EVER_PROD_R2_BUCKET_NAME=edgeever-prod-resources
-EDGE_EVER_PROD_AUTH_PASSWORD_HASH=<password-hash>
+EDGE_EVER_PROD_AUTH_PASSWORD=<login-password>
```
+Legacy or advanced installations may use `EDGE_EVER_<INSTANCE>_AUTH_PASSWORD_HASH` instead. Never place either password value in a committed file or a non-secret Cloudflare variable.
+
## Blocking Conditions
Stop and ask the user only when:
diff --git a/docs/cloudflare-workers-builds.md b/docs/cloudflare-workers-builds.md
index 2db9a0e2..05c12202 100644
--- a/docs/cloudflare-workers-builds.md
+++ b/docs/cloudflare-workers-builds.md
@@ -57,9 +57,9 @@ If the command cannot be used, configure the Worker in the Cloudflare dashboard:
Deploy command: bun run deploy:cloudflare-builds
```
-5. Add the instance values from `.env.local` under **Settings** -> **Builds** -> **Build variables and secrets**. Use a secret for `EDGE_EVER_AUTH_PASSWORD_HASH`.
+5. Add the instance values from `.env.local` under **Settings** -> **Builds** -> **Build variables and secrets**. Store `EDGE_EVER_AUTH_PASSWORD` as a Build Secret. Existing installations may keep using `EDGE_EVER_AUTH_PASSWORD_HASH` as a Build Secret.
-The Worker selected in the dashboard must be the one named by `EDGE_EVER_WORKER_NAME`. The deployment command creates a temporary Wrangler configuration from these variables, so do not commit a D1 ID, R2 bucket name, route, or password hash.
+The Worker selected in the dashboard must be the one named by `EDGE_EVER_WORKER_NAME`. The deployment command creates a temporary Wrangler configuration from these variables, so do not commit a D1 ID, R2 bucket name, route, password, or password hash.
## Required Build Variables
@@ -73,7 +73,7 @@ EDGE_EVER_D1_DATABASE_ID
EDGE_EVER_R2_BUCKET_NAME
EDGE_EVER_R2_PREVIEW_BUCKET_NAME
EDGE_EVER_AUTH_USERNAME
-EDGE_EVER_AUTH_PASSWORD_HASH # Build Secret
+EDGE_EVER_AUTH_PASSWORD # Build Secret
EDGE_EVER_SESSION_TTL_DAYS
EDGE_EVER_DEMO_MODE # optional
EDGE_EVER_DEMO_RESET_CRON # optional
@@ -81,6 +81,8 @@ EDGE_EVER_CUSTOM_DOMAIN # optional
EDGE_EVER_ROUTE_PATTERN # optional
```
+Existing installations that already use `EDGE_EVER_AUTH_PASSWORD_HASH` may keep it instead of `EDGE_EVER_AUTH_PASSWORD`. If both are present, the hash takes precedence for backward compatibility.
+
For a multi-instance configuration, set `EDGE_EVER_INSTANCE` and the matching scoped variables such as `EDGE_EVER_PROD_D1_DATABASE_ID` instead. The same resolution rules apply in local deployment and Workers Builds.
Workers Builds needs an API token that can deploy Workers, update R2 bindings, and apply D1 migrations. If the automatically created Builds token does not have D1 edit permission, select or create a token with that permission before enabling automated deployments.
diff --git a/docs/cloudflare-workers-builds.zh-CN.md b/docs/cloudflare-workers-builds.zh-CN.md
index 771bbfc1..3e2d0d20 100644
--- a/docs/cloudflare-workers-builds.zh-CN.md
+++ b/docs/cloudflare-workers-builds.zh-CN.md
@@ -58,9 +58,9 @@ Cloudflare 无法为 **Direct Upload(直接上传)** 类型的 Pages 项目
Deploy command: bun run deploy:cloudflare-builds
```
-5. 在 **Settings** -> **Builds** -> **Build variables and secrets** 中,填入初次部署时 `.env.local` 的实例配置;`EDGE_EVER_AUTH_PASSWORD_HASH` 必须保存为 Secret。
+5. 在 **Settings** -> **Builds** -> **Build variables and secrets** 中,填入初次部署时 `.env.local` 的实例配置;推荐将 `EDGE_EVER_AUTH_PASSWORD` 保存为 Build Secret。已有实例可继续将 `EDGE_EVER_AUTH_PASSWORD_HASH` 保存为 Build Secret。
-Dashboard 中选中的 Worker 必须与 `EDGE_EVER_WORKER_NAME` 对应。部署命令会根据这些变量生成临时 Wrangler 配置,因此严禁把 D1 ID、R2 bucket、路由或密码 hash 提交进仓库。
+Dashboard 中选中的 Worker 必须与 `EDGE_EVER_WORKER_NAME` 对应。部署命令会根据这些变量生成临时 Wrangler 配置,因此严禁把 D1 ID、R2 bucket、路由、密码或密码 hash 提交进仓库。
## 必需的构建变量
@@ -74,7 +74,7 @@ EDGE_EVER_D1_DATABASE_ID
EDGE_EVER_R2_BUCKET_NAME
EDGE_EVER_R2_PREVIEW_BUCKET_NAME
EDGE_EVER_AUTH_USERNAME
-EDGE_EVER_AUTH_PASSWORD_HASH # Build Secret
+EDGE_EVER_AUTH_PASSWORD # Build Secret
EDGE_EVER_SESSION_TTL_DAYS
EDGE_EVER_DEMO_MODE # 可选
EDGE_EVER_DEMO_RESET_CRON # 可选
@@ -82,6 +82,8 @@ EDGE_EVER_CUSTOM_DOMAIN # 可选
EDGE_EVER_ROUTE_PATTERN # 可选
```
+已经使用 `EDGE_EVER_AUTH_PASSWORD_HASH` 的旧实例可以继续保留该变量,无需改成 `EDGE_EVER_AUTH_PASSWORD`。为兼容已有实例,两个变量同时存在时哈希优先。
+
多实例场景则设置 `EDGE_EVER_INSTANCE`,并使用 `EDGE_EVER_PROD_D1_DATABASE_ID` 之类的带实例前缀变量。本地部署和 Workers Builds 使用相同的变量解析规则。
Workers Builds 使用的 API Token 必须拥有 Worker 发布、R2 binding 更新和 D1 migration 所需权限。如果 Cloudflare 自动创建的 Builds token 没有 D1 编辑权限,请选择或新建一个具备该权限的 token。
diff --git a/docs/manual-deploy.md b/docs/manual-deploy.md
index 8f79e846..a1ecfc65 100644
--- a/docs/manual-deploy.md
+++ b/docs/manual-deploy.md
@@ -48,13 +48,10 @@ bunx wrangler d1 create edgeever
# Create the R2 bucket
bunx wrangler r2 bucket create edgeever-resources
-# Generate the password hash
-bun run auth:hash -- <your password>
-
# Edit .env.local and fill in at least the generated resource and password values
# EDGE_EVER_D1_DATABASE_ID=<database_id returned by the D1 command>
# EDGE_EVER_R2_BUCKET_NAME=edgeever-resources
-# EDGE_EVER_AUTH_PASSWORD_HASH=<hash generated above>
+# EDGE_EVER_AUTH_PASSWORD=<your login password>
# EDGE_EVER_SESSION_TTL_DAYS=400
# Validate the completed configuration before deploying
@@ -62,9 +59,11 @@ bun run deploy:doctor
bun run deploy
```
-Before running `bun run deploy`, copy the D1 `database_id`, R2 bucket name, and generated password hash into your local `.env.local` file. Keep the session lifetime at the template default of `400` days; the server also caps larger values at 400 days.
+Before running `bun run deploy`, copy the D1 `database_id`, R2 bucket name, and login password into your local `.env.local` file. Keep the session lifetime at the template default of `400` days; the server also caps larger values at 400 days.
+
+`bun run deploy` builds the web app, applies remote D1 migrations, deploys the Worker, and uploads `EDGE_EVER_AUTH_PASSWORD` as a Worker Secret. After the first successful login, EdgeEver stores a salted PBKDF2-SHA256 hash in D1. Existing installations may continue to use `EDGE_EVER_AUTH_PASSWORD_HASH`; when both Secrets are set, the hash takes precedence. Verify the deployment by signing in with `EDGE_EVER_AUTH_USERNAME` and the configured password.
-`bun run deploy` builds the web app, applies remote D1 migrations, deploys the Worker, and uploads `EDGE_EVER_AUTH_PASSWORD_HASH` as a Worker Secret. After a successful deployment, the script also synchronizes that Secret through `wrangler secret put` to ensure the first login works. Verify the deployment by signing in with `EDGE_EVER_AUTH_USERNAME` and the original password used to generate the hash.
+Existing installations do not need to migrate. If you intentionally switch from the hash setting to `EDGE_EVER_AUTH_PASSWORD`, remove the old `EDGE_EVER_AUTH_PASSWORD_HASH` from `.env.local`, Workers Builds, and the Worker's runtime Secrets; otherwise the legacy hash remains authoritative.
---
diff --git a/docs/manual-deploy.zh-CN.md b/docs/manual-deploy.zh-CN.md
index 44455030..7e89accb 100644
--- a/docs/manual-deploy.zh-CN.md
+++ b/docs/manual-deploy.zh-CN.md
@@ -48,13 +48,10 @@ bunx wrangler d1 create edgeever
# 手动创建 R2 存储桶
bunx wrangler r2 bucket create edgeever-resources
-# 生成密码 hash(用于后台验证)
-bun run auth:hash -- <你的密码>
-
# 编辑 .env.local,至少填入刚创建的资源和密码配置
# EDGE_EVER_D1_DATABASE_ID=<D1 创建命令返回的 database_id>
# EDGE_EVER_R2_BUCKET_NAME=edgeever-resources
-# EDGE_EVER_AUTH_PASSWORD_HASH=<上一步生成的 hash>
+# EDGE_EVER_AUTH_PASSWORD=<你的登录密码>
# EDGE_EVER_SESSION_TTL_DAYS=400
# 确认配置完整后再部署
@@ -62,9 +59,11 @@ bun run deploy:doctor
bun run deploy
```
-必须在执行 `bun run deploy` **之前**,将 D1 创建命令返回的 `database_id`、R2 bucket 名称和生成的密码 hash 写入本机 `.env.local`。会话有效期建议保留模板中的 `400` 天;服务端也会把更大的值限制为 400 天。
+必须在执行 `bun run deploy` **之前**,将 D1 创建命令返回的 `database_id`、R2 bucket 名称和登录密码写入本机 `.env.local`。会话有效期建议保留模板中的 `400` 天;服务端也会把更大的值限制为 400 天。
+
+`bun run deploy` 会构建 Web 应用、执行远程 D1 migration、部署 Worker,并将 `EDGE_EVER_AUTH_PASSWORD` 作为 Worker Secret 上传。首次登录成功后,EdgeEver 会将加盐的 PBKDF2-SHA256 哈希写入 D1。已有实例可以继续使用 `EDGE_EVER_AUTH_PASSWORD_HASH`;两个 Secret 同时存在时优先使用哈希。部署完成后,请使用 `.env.local` 中的 `EDGE_EVER_AUTH_USERNAME` 和配置的密码登录验证。
-`bun run deploy` 会构建 Web 应用、执行远程 D1 migration、部署 Worker,并将 `EDGE_EVER_AUTH_PASSWORD_HASH` 作为 Worker Secret 上传。部署脚本还会在成功后通过 `wrangler secret put` 再同步一次该 Secret,确保首次登录可用。部署完成后,请使用 `.env.local` 中的 `EDGE_EVER_AUTH_USERNAME` 和生成 hash 时使用的原始密码登录验证。
+已有实例无需迁移。如果确实要从哈希配置切换为 `EDGE_EVER_AUTH_PASSWORD`,需要同时从 `.env.local`、Workers Builds 和 Worker 运行时 Secrets 中移除旧的 `EDGE_EVER_AUTH_PASSWORD_HASH`,否则旧哈希仍会优先生效。
---
diff --git a/scripts/cloudflare-deploy.mjs b/scripts/cloudflare-deploy.mjs
index 728f4208..00a0823d 100644
--- a/scripts/cloudflare-deploy.mjs
+++ b/scripts/cloudflare-deploy.mjs
@@ -202,32 +202,29 @@ const ensureR2 = (values, name) => {
return check(`create R2 bucket ${bucketName}`, false);
};
-const ensurePasswordHash = (values) => {
+const ensureAuthPassword = (values) => {
const currentHash = envValue("AUTH_PASSWORD_HASH", values);
if (currentHash) {
- return check("auth password hash", PASSWORD_HASH_PATTERN.test(currentHash), "configured");
+ const valid = PASSWORD_HASH_PATTERN.test(currentHash);
+ return check("auth password hash", valid, valid ? "configured" : "invalid");
+ }
+
+ const currentPassword = envValue("AUTH_PASSWORD", values);
+ if (currentPassword) {
+ return check("auth password", true, "configured as a secret");
}
const password = process.env.EDGE_EVER_PASSWORD?.trim();
if (!password) {
return check(
- "auth password hash",
+ "auth password",
false,
- "set EDGE_EVER_PASSWORD and rerun setup, or set EDGE_EVER_AUTH_PASSWORD_HASH",
+ "set EDGE_EVER_PASSWORD and rerun setup, or set EDGE_EVER_AUTH_PASSWORD",
);
}
- const result = run("bun", ["scripts/hash-password.mjs"], {
- env: { ...process.env, EDGE_EVER_PASSWORD: password },
- });
- if (result.status !== 0) {
- console.error(result.stderr.trim());
- return check("generate auth password hash", false);
- }
-
- const passwordHash = result.stdout.trim();
- upsertEnv(targetKey("AUTH_PASSWORD_HASH", values), passwordHash);
- console.log("[ok] generated auth password hash");
+ upsertEnv(targetKey("AUTH_PASSWORD", values), password);
+ console.log("[ok] configured auth password secret");
return true;
};
@@ -263,11 +260,22 @@ const doctor = () => {
) && passed;
const passwordHash = envValue("AUTH_PASSWORD_HASH", values);
+ const password = envValue("AUTH_PASSWORD", values);
+ const passwordHashValid = Boolean(passwordHash && PASSWORD_HASH_PATTERN.test(passwordHash));
+ const passwordConfigured = Boolean(password);
passed =
check(
- "auth password hash",
- Boolean(passwordHash && PASSWORD_HASH_PATTERN.test(passwordHash)),
- passwordHash ? "configured" : "missing",
+ "auth password",
+ passwordHash ? passwordHashValid : passwordConfigured,
+ passwordHash
+ ? passwordHashValid
+ ? password
+ ? "hash configured and takes precedence over password secret"
+ : "hash configured"
+ : "invalid password hash; remove or replace it because it takes precedence"
+ : password
+ ? "password secret configured"
+ : "missing",
) && passed;
process.exit(passed ? 0 : 1);
@@ -289,7 +297,7 @@ const setup = () => {
passed = ensureD1(values) && passed;
passed = ensureR2(values, "R2_BUCKET_NAME") && passed;
passed = ensureR2(values, "R2_PREVIEW_BUCKET_NAME") && passed;
- passed = ensurePasswordHash(values) && passed;
+ passed = ensureAuthPassword(values) && passed;
process.exit(passed ? 0 : 1);
};
diff --git a/scripts/cloudflare-workers-builds.mjs b/scripts/cloudflare-workers-builds.mjs
index 90bdfa26..3ab4e407 100644
--- a/scripts/cloudflare-workers-builds.mjs
+++ b/scripts/cloudflare-workers-builds.mjs
@@ -98,6 +98,7 @@ const buildVariables = () => {
"R2_BUCKET_NAME",
"R2_PREVIEW_BUCKET_NAME",
"AUTH_USERNAME",
+ "AUTH_PASSWORD",
"AUTH_PASSWORD_HASH",
"SESSION_TTL_DAYS",
"DEMO_MODE",
@@ -115,13 +116,13 @@ const buildVariables = () => {
if (current) entries.push([key, current]);
}
- if (!entries.some(([key]) => key.endsWith("AUTH_PASSWORD_HASH"))) {
- throw new Error("Missing EDGE_EVER_AUTH_PASSWORD_HASH. Run deploy:setup before configuring Workers Builds.");
+ if (!entries.some(([key]) => key.endsWith("AUTH_PASSWORD") || key.endsWith("AUTH_PASSWORD_HASH"))) {
+ throw new Error("Missing EDGE_EVER_AUTH_PASSWORD or EDGE_EVER_AUTH_PASSWORD_HASH. Run deploy:setup before configuring Workers Builds.");
}
return Object.fromEntries(entries.map(([key, current]) => [key, {
value: current.replace(/\\\$/g, "$"),
- is_secret: key.endsWith("AUTH_PASSWORD_HASH"),
+ is_secret: key.endsWith("AUTH_PASSWORD") || key.endsWith("AUTH_PASSWORD_HASH"),
}]));
};
diff --git a/scripts/run-wrangler.mjs b/scripts/run-wrangler.mjs
index 3eadddc9..8a654b5d 100644
--- a/scripts/run-wrangler.mjs
+++ b/scripts/run-wrangler.mjs
@@ -197,11 +197,16 @@ if (changed) {
const isDeployCommand = wranglerArgs.includes("deploy");
const hasSecretsFileArg = wranglerArgs.some((arg) => arg === "--secrets-file" || arg.startsWith("--secrets-file="));
+const authPassword = envValue("AUTH_PASSWORD");
const authPasswordHash = envValue("AUTH_PASSWORD_HASH");
+const authSecrets = {
+ ...(authPassword ? { EDGE_EVER_AUTH_PASSWORD: authPassword } : {}),
+ ...(authPasswordHash ? { EDGE_EVER_AUTH_PASSWORD_HASH: authPasswordHash } : {}),
+};
const finalWranglerArgs = [...wranglerArgs];
-if (isDeployCommand && authPasswordHash && !hasSecretsFileArg) {
- writeFileSync(generatedSecretsPath, `EDGE_EVER_AUTH_PASSWORD_HASH=${authPasswordHash}\n`);
+if (isDeployCommand && Object.keys(authSecrets).length > 0 && !hasSecretsFileArg) {
+ writeFileSync(generatedSecretsPath, `${JSON.stringify(authSecrets, null, 2)}\n`);
finalWranglerArgs.push("--secrets-file", generatedSecretsPath);
}
@@ -220,23 +225,25 @@ const result = spawnSync(executable, ["--config", configPath, ...finalWranglerAr
shell: process.platform === "win32",
});
-if (result.status === 0 && isDeployCommand && authPasswordHash) {
- const secretResult = spawnSync(
- executable,
- ["--config", configPath, "secret", "put", "EDGE_EVER_AUTH_PASSWORD_HASH"],
- {
- input: authPasswordHash,
- stdio: ["pipe", "inherit", "inherit"],
- shell: process.platform === "win32",
- },
- );
-
- if (secretResult.error) {
- throw secretResult.error;
- }
+if (result.status === 0 && isDeployCommand) {
+ for (const [secretName, secretValue] of Object.entries(authSecrets)) {
+ const secretResult = spawnSync(
+ executable,
+ ["--config", configPath, "secret", "put", secretName],
+ {
+ input: secretValue,
+ stdio: ["pipe", "inherit", "inherit"],
+ shell: process.platform === "win32",
+ },
+ );
+
+ if (secretResult.error) {
+ throw secretResult.error;
+ }
- if (secretResult.status !== 0) {
- process.exit(secretResult.status ?? 1);
+ if (secretResult.status !== 0) {
+ process.exit(secretResult.status ?? 1);
+ }
}
}
diff --git a/tests/auth-bootstrap.test.ts b/tests/auth-bootstrap.test.ts
new file mode 100644
index 00000000..4a79d697
--- /dev/null
+++ b/tests/auth-bootstrap.test.ts
@@ -0,0 +1,38 @@
+import { describe, expect, test } from "bun:test";
+import { hasBootstrapCredential, verifyBootstrapPassword } from "../apps/api/src/auth-bootstrap";
+
+const rejectHash = async () => false;
+
+describe("bootstrap password authentication", () => {
+ test("accepts an exact plaintext password Secret", async () => {
+ const password = "first-login#$ password";
+
+ expect(hasBootstrapCredential(password, undefined)).toBe(true);
+ expect(await verifyBootstrapPassword(password, password, undefined, rejectHash)).toBe(true);
+ expect(await verifyBootstrapPassword(`${password}!`, password, undefined, rejectHash)).toBe(false);
+ });
+
+ test("keeps the legacy password hash authoritative when both values exist", async () => {
+ const calls: Array<[string, string]> = [];
+ const verifyHash = async (password: string, passwordHash: string) => {
+ calls.push([password, passwordHash]);
+ return password === "legacy-password" && passwordHash === "legacy-hash";
+ };
+
+ expect(
+ await verifyBootstrapPassword("new-password", "new-password", "legacy-hash", verifyHash),
+ ).toBe(false);
+ expect(
+ await verifyBootstrapPassword("legacy-password", "new-password", "legacy-hash", verifyHash),
+ ).toBe(true);
+ expect(calls).toEqual([
+ ["new-password", "legacy-hash"],
+ ["legacy-password", "legacy-hash"],
+ ]);
+ });
+
+ test("rejects login when neither password setting exists", async () => {
+ expect(hasBootstrapCredential(undefined, undefined)).toBe(false);
+ expect(await verifyBootstrapPassword("password", undefined, undefined, rejectHash)).toBe(false);
+ });
+});