@kidecms/core 0.14.0 → 0.14.2
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.
package/admin/lib/edit-data.ts
CHANGED
|
@@ -436,7 +436,7 @@ export async function loadParentFormTitle(
|
|
|
436
436
|
runtimeContext: RuntimeContext,
|
|
437
437
|
): Promise<string | null> {
|
|
438
438
|
try {
|
|
439
|
-
const parentForm = (await cmsRuntime.forms.findOne({
|
|
439
|
+
const parentForm = (await cmsRuntime.forms.findOne({ _id: formId }, runtimeContext)) as Record<
|
|
440
440
|
string,
|
|
441
441
|
unknown
|
|
442
442
|
> | null;
|
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
|
|
8
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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/middleware/auth.ts
CHANGED
|
@@ -33,7 +33,13 @@ export const onRequest = defineMiddleware(async (context, next) => {
|
|
|
33
33
|
const scope: RequestScope = cfContext?.waitUntil
|
|
34
34
|
? { defer: (task) => cfContext.waitUntil!(task) }
|
|
35
35
|
: { defer: () => {} };
|
|
36
|
-
return runWithRequestScope(scope, () =>
|
|
36
|
+
return runWithRequestScope(scope, async () => {
|
|
37
|
+
const response = await handle(context, next);
|
|
38
|
+
// Draft responses must never enter the shared cache. Runs after the page
|
|
39
|
+
// rendered because a page-level cache.set() would re-enable caching.
|
|
40
|
+
if (context.url.searchParams.has("preview")) context.cache?.set(false);
|
|
41
|
+
return response;
|
|
42
|
+
});
|
|
37
43
|
});
|
|
38
44
|
|
|
39
45
|
const handle = async (context: APIContext, next: MiddlewareNext) => {
|
package/package.json
CHANGED
package/routes/admin/login.astro
CHANGED
|
@@ -18,7 +18,11 @@ const errorMessage =
|
|
|
18
18
|
? "Email and password are required."
|
|
19
19
|
: error === "disabled"
|
|
20
20
|
? "Password login is disabled."
|
|
21
|
-
:
|
|
21
|
+
: error === "rate-limited"
|
|
22
|
+
? "Too many attempts. Try again in a few minutes."
|
|
23
|
+
: error
|
|
24
|
+
? "Sign-in failed. Try again."
|
|
25
|
+
: null;
|
|
22
26
|
const auth = resolveAdminAuth(config);
|
|
23
27
|
---
|
|
24
28
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { APIRoute } from "astro";
|
|
2
2
|
import { cms } from "virtual:kide/api";
|
|
3
3
|
import { sendFormSubmissionEmail, isEmailConfigured } from "virtual:kide/email";
|
|
4
|
-
import { hitRateLimit, PayloadTooLargeError, readLimitedFormData } from "../../../../core";
|
|
4
|
+
import { hitRateLimit, PayloadTooLargeError, readLimitedFormData, safeUrl } from "../../../../core";
|
|
5
5
|
|
|
6
6
|
export const prerender = false;
|
|
7
7
|
|
|
@@ -58,7 +58,7 @@ export const POST: APIRoute = async ({ request, params, redirect, clientAddress
|
|
|
58
58
|
return redirect(buildRedirectUrl(request, null, true), 303);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
const form = await cms.forms.findOne({
|
|
61
|
+
const form = await cms.forms.findOne({ slug }, { _system: true });
|
|
62
62
|
if (!form) return new Response("Form not found", { status: 404 });
|
|
63
63
|
|
|
64
64
|
const fieldConfigs = Array.isArray(form.fields) ? (form.fields as FormFieldConfig[]) : [];
|
|
@@ -125,8 +125,9 @@ export const POST: APIRoute = async ({ request, params, redirect, clientAddress
|
|
|
125
125
|
await sendFormSubmissionEmail(String(form.notificationEmail), String(form.title), data);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
const submitRedirect = form.submitRedirect ? safeUrl(String(form.submitRedirect)) : null;
|
|
129
|
+
if (submitRedirect) {
|
|
130
|
+
return redirect(submitRedirect, 303);
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
return redirect(buildRedirectUrl(request, null, true), 303);
|