@kidecms/core 0.14.0 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/core/auth.ts +20 -9
  2. package/package.json +1 -1
package/core/auth.ts CHANGED
@@ -4,8 +4,11 @@ import { nanoid } from "nanoid";
4
4
  import { getDb } from "./runtime";
5
5
  import { getSchema } from "./schema";
6
6
 
7
- // 600k per OWASP. Iteration count is stored per-hash, so existing 100k hashes still verify.
8
- const ITERATIONS = 600_000;
7
+ // 600k per OWASP, but Cloudflare Workers rejects counts above 100k in production
8
+ // (not in wrangler dev, so only deploys hit it). Iteration count is stored
9
+ // per-hash, so hashes created at either count keep verifying on both runtimes.
10
+ const isWorkers = typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers";
11
+ const ITERATIONS = isWorkers ? 100_000 : 600_000;
9
12
  const HASH_LENGTH = 32;
10
13
  const SALT_LENGTH = 16;
11
14
 
@@ -66,13 +69,21 @@ export const verifyPassword = async (hash: string, plain: string): Promise<boole
66
69
  const keyMaterial = await crypto.subtle.importKey("raw", new TextEncoder().encode(plain), "PBKDF2", false, [
67
70
  "deriveBits",
68
71
  ]);
69
- const derived = new Uint8Array(
70
- await crypto.subtle.deriveBits(
71
- { name: "PBKDF2", salt, iterations, hash: "SHA-256" },
72
- keyMaterial,
73
- expected.length * 8,
74
- ),
75
- );
72
+ let derived: Uint8Array;
73
+ try {
74
+ derived = new Uint8Array(
75
+ await crypto.subtle.deriveBits(
76
+ { name: "PBKDF2", salt, iterations, hash: "SHA-256" },
77
+ keyMaterial,
78
+ expected.length * 8,
79
+ ),
80
+ );
81
+ } catch (error) {
82
+ // Workers rejects iteration counts above 100k — a hash created on Node can
83
+ // land here after a database move. Fail the login instead of crashing.
84
+ console.error("[auth] verifyPassword failed to derive", error);
85
+ return false;
86
+ }
76
87
 
77
88
  if (derived.length !== expected.length) return false;
78
89
  let diff = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kidecms/core",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "description": "Kide CMS runtime — core library, admin UI, routes, and middleware for Astro. Shipped as TypeScript source.",
5
5
  "type": "module",
6
6
  "license": "MIT",