From 372a77754a9ef32c4a9ddd7881d58320c48110a4 Mon Sep 17 00:00:00 2001 From: maverick Date: Wed, 22 Jul 2026 02:04:40 +1000 Subject: [PATCH] Fix PBKDF2 iteration cap (Workers max 100k), add custom domain + error handler - PBKDF2 iterations 210k->100k (Cloudflare WebCrypto hard limit; miniflare didn't enforce) - Add cipher.theradicalparty.com custom domain route - Add onError handler - Verified live: E2E delivery + offline store-and-forward both working Co-Authored-By: Claude Opus 4.8 (1M context) --- src/index.js | 5 +++++ src/lib/auth.js | 3 ++- wrangler.jsonc | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 1e615f4..a54ef8f 100644 --- a/src/index.js +++ b/src/index.js @@ -11,6 +11,11 @@ export { Mailbox } from "./do/mailbox.js"; const app = new Hono(); +app.onError((err, c) => { + console.error("unhandled:", err.stack || err.message); + return c.json({ error: "server error" }, 500); +}); + app.get("/api/health", (c) => c.json({ ok: true, service: "cipher" })); app.route("/api/auth", auth); diff --git a/src/lib/auth.js b/src/lib/auth.js index 82b4424..1ecc8fa 100644 --- a/src/lib/auth.js +++ b/src/lib/auth.js @@ -4,7 +4,8 @@ import { b64, randomToken, now } from "./util.js"; -const PBKDF2_ITERS = 210000; +// Cloudflare Workers caps PBKDF2 at 100k iterations (WebCrypto limit). +const PBKDF2_ITERS = 100000; async function pbkdf2(password, saltBytes) { const enc = new TextEncoder(); diff --git a/wrangler.jsonc b/wrangler.jsonc index f672427..62a967d 100644 --- a/wrangler.jsonc +++ b/wrangler.jsonc @@ -5,6 +5,9 @@ "compatibility_date": "2025-07-01", "compatibility_flags": ["nodejs_compat"], "observability": { "enabled": true }, + "routes": [ + { "pattern": "cipher.theradicalparty.com", "custom_domain": true } + ], "assets": { "directory": "./public", "binding": "ASSETS", @@ -14,7 +17,7 @@ { "binding": "DB", "database_name": "cipher", - "database_id": "REPLACE_AFTER_CREATE", + "database_id": "f80ec87d-02ad-486d-b33a-50322f33c235", "migrations_dir": "migrations" } ],