@kidecms/core 0.35.1 → 0.37.0

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.
@@ -264,17 +264,17 @@ const DEV_SECRET = "kide-development-secret-do-not-use-in-production";
264
264
  let warnedDevSecret = false;
265
265
 
266
266
  export const resolveAuthSecret = () => {
267
- const secret = safeEnv("KIDE_AUTH_SECRET") ?? safeEnv("BETTER_AUTH_SECRET");
267
+ const secret = safeEnv("KIDE_SECRET") || safeEnv("KIDE_AUTH_SECRET") || safeEnv("BETTER_AUTH_SECRET");
268
268
  if (secret) return secret;
269
269
  if (process.env.NODE_ENV === "production") {
270
270
  throw new Error(
271
- "[kide] KIDE_AUTH_SECRET is not set. Generate one with `openssl rand -base64 32` and add it to the " +
271
+ "[kide] KIDE_SECRET is not set. Generate one with `openssl rand -base64 32` and add it to the " +
272
272
  "deployment environment — it signs admin session cookies.",
273
273
  );
274
274
  }
275
275
  if (!warnedDevSecret) {
276
276
  warnedDevSecret = true;
277
- console.warn("[kide] KIDE_AUTH_SECRET is not set — using a development secret.");
277
+ console.warn("[kide] KIDE_SECRET is not set — using a development secret.");
278
278
  }
279
279
  return DEV_SECRET;
280
280
  };
@@ -0,0 +1,13 @@
1
+ // @astrojs/node only trusts the Host / X-Forwarded-* headers for domains in `security.allowedDomains`;
2
+ // otherwise Astro.url falls back to localhost. Derive the entry from Kide's own public-origin setting.
3
+ export const allowedDomainsFromOrigin = (origin: string | undefined) => {
4
+ if (!origin) return null;
5
+ try {
6
+ const url = new URL(origin);
7
+ return [
8
+ { protocol: url.protocol.replace(/:$/, ""), hostname: url.hostname, ...(url.port ? { port: url.port } : {}) },
9
+ ];
10
+ } catch {
11
+ return null;
12
+ }
13
+ };
@@ -4,6 +4,7 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, watch,
4
4
  import { createRequire } from "node:module";
5
5
  import path from "node:path";
6
6
  import { fileURLToPath } from "node:url";
7
+ import { allowedDomainsFromOrigin } from "./allowed-domains";
7
8
  import { analyzeSharedDeps, formatConflicts } from "./shared-deps";
8
9
 
9
10
  // All runtime files resolve relative to this module, never the project root, so
@@ -114,7 +115,7 @@ export default function cmsIntegration(options?: CmsIntegrationOptions): AstroIn
114
115
  return {
115
116
  name: "kide-cms",
116
117
  hooks: {
117
- "astro:config:setup": ({ command, updateConfig, injectRoute, injectScript, addMiddleware, logger }) => {
118
+ "astro:config:setup": ({ command, config, updateConfig, injectRoute, injectScript, addMiddleware, logger }) => {
118
119
  const root = process.cwd();
119
120
 
120
121
  // One copy per library the admin shares with the project — see shared-deps.ts.
@@ -172,6 +173,12 @@ export default function cmsIntegration(options?: CmsIntegrationOptions): AstroIn
172
173
  };
173
174
  generateFieldsBarrel();
174
175
 
176
+ // Build-time: the adapter bakes allowedDomains into the server. A project's own setting wins.
177
+ const allowedDomains = allowedDomainsFromOrigin(process.env.CMS_TRUSTED_ORIGIN);
178
+ if (allowedDomains && !config.security?.allowedDomains?.length) {
179
+ updateConfig({ security: { allowedDomains } });
180
+ }
181
+
175
182
  // Virtual module aliases — resolve route imports to the user's app files
176
183
  updateConfig({
177
184
  vite: {
@@ -15,6 +15,7 @@ import config from "virtual:kide/config";
15
15
  import "virtual:kide/runtime";
16
16
  import { getDb } from "virtual:kide/db";
17
17
 
18
+ import { isSameOriginRequest } from "./csrf";
18
19
  import { startSchedulerOnce } from "./scheduler";
19
20
 
20
21
  let hasUsers: boolean | null = null;
@@ -131,25 +132,7 @@ const handle = async (context: APIContext, next: MiddlewareNext) => {
131
132
  pathname.startsWith("/api/cms/webhooks/") ||
132
133
  pathname.startsWith("/api/cms/forms/submit/");
133
134
  if (method !== "GET" && method !== "HEAD" && method !== "OPTIONS" && !isMachineEndpoint) {
134
- // Compare against an explicitly configured origin when set (robust behind a proxy that
135
- // may rewrite Host); otherwise fall back to the request's own origin.
136
- const host = publicOrigin(context.request);
137
- const origin = context.request.headers.get("origin");
138
- const referer = context.request.headers.get("referer");
139
- const secFetchSite = context.request.headers.get("sec-fetch-site");
140
-
141
- let refererOk = false;
142
- if (!origin && referer) {
143
- try {
144
- refererOk = new URL(referer).origin === host;
145
- } catch {
146
- refererOk = false;
147
- }
148
- }
149
- const originOk = origin === host;
150
- // Reject an explicit cross-site Fetch-Metadata signal, or the absence of any
151
- // trustworthy same-origin signal (the hole the old `if (origin && ...)` left open).
152
- if (secFetchSite === "cross-site" || !(originOk || refererOk)) {
135
+ if (!isSameOriginRequest(context.request.headers, publicOrigin(context.request))) {
153
136
  return new Response(JSON.stringify({ error: "Forbidden" }), {
154
137
  status: 403,
155
138
  headers: { "Content-Type": "application/json" },
@@ -0,0 +1,19 @@
1
+ // Same-origin proof for a state-changing request. Fetch Metadata comes first: browsers set
2
+ // Sec-Fetch-Site themselves, and it doesn't depend on the server knowing its public origin
3
+ // (behind a proxy without CMS_TRUSTED_ORIGIN, request.url is localhost). Origin/Referer is
4
+ // the fallback for clients that don't send it.
5
+ export const isSameOriginRequest = (headers: Headers, expectedOrigin: string): boolean => {
6
+ const secFetchSite = headers.get("sec-fetch-site");
7
+ if (secFetchSite === "same-origin") return true;
8
+ if (secFetchSite && secFetchSite !== "none") return false;
9
+
10
+ const origin = headers.get("origin");
11
+ if (origin) return origin === expectedOrigin;
12
+ const referer = headers.get("referer");
13
+ if (!referer) return false;
14
+ try {
15
+ return new URL(referer).origin === expectedOrigin;
16
+ } catch {
17
+ return false;
18
+ }
19
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kidecms/core",
3
- "version": "0.35.1",
3
+ "version": "0.37.0",
4
4
  "description": "Kide CMS runtime — core library, admin UI, routes, and middleware for Astro. Shipped as TypeScript source.",
5
5
  "keywords": [
6
6
  "cms",
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "bugs": "https://github.com/mhernesniemi/kide-cms/issues",
21
21
  "engines": {
22
- "node": ">=22.12.0"
22
+ "node": ">=22.23.4"
23
23
  },
24
24
  "bin": {
25
25
  "kide": "./internals/cli.mjs"
@@ -51,38 +51,38 @@
51
51
  "access": "public"
52
52
  },
53
53
  "dependencies": {
54
- "@ai-sdk/openai": "^3.0.114",
55
- "@base-ui/react": "^1.8.0",
56
- "@better-auth/passkey": "1.7.7",
57
- "@better-auth/utils": "0.4.2",
54
+ "@ai-sdk/openai": "^3.0.132",
55
+ "@base-ui/react": "^1.9.0",
56
+ "@better-auth/passkey": "1.7.14",
57
+ "@better-auth/utils": "0.5.1",
58
58
  "@dnd-kit/core": "^6.3.1",
59
59
  "@dnd-kit/sortable": "^10.0.0",
60
60
  "@dnd-kit/utilities": "^3.2.2",
61
- "@modelcontextprotocol/sdk": "^1.30.0",
62
- "@radix-ui/react-dropdown-menu": "^2.1.24",
63
- "@radix-ui/react-popover": "^1.1.23",
61
+ "@modelcontextprotocol/sdk": "^1.32.2",
62
+ "@radix-ui/react-dropdown-menu": "^2.2.1",
63
+ "@radix-ui/react-popover": "^1.3.1",
64
64
  "@simplewebauthn/browser": "^13.3.0",
65
65
  "@tanstack/react-table": "^8.21.3",
66
- "@tiptap/core": "3.31.3",
67
- "@tiptap/extension-image": "3.31.3",
68
- "@tiptap/extension-link": "3.31.3",
69
- "@tiptap/extension-placeholder": "3.31.3",
70
- "@tiptap/markdown": "3.31.3",
71
- "@tiptap/pm": "3.31.3",
72
- "@tiptap/react": "3.31.3",
73
- "@tiptap/starter-kit": "3.31.3",
74
- "@tiptap/suggestion": "3.31.3",
75
- "ai": "^6.0.286",
66
+ "@tiptap/core": "3.32.0",
67
+ "@tiptap/extension-image": "3.32.0",
68
+ "@tiptap/extension-link": "3.32.0",
69
+ "@tiptap/extension-placeholder": "3.32.0",
70
+ "@tiptap/markdown": "3.32.0",
71
+ "@tiptap/pm": "3.32.0",
72
+ "@tiptap/react": "3.32.0",
73
+ "@tiptap/starter-kit": "3.32.0",
74
+ "@tiptap/suggestion": "3.32.0",
75
+ "ai": "^6.0.316",
76
76
  "aws4fetch": "^1.0.20",
77
- "better-auth": "1.7.7",
77
+ "better-auth": "1.7.14",
78
78
  "class-variance-authority": "^0.7.1",
79
79
  "clsx": "^2.1.1",
80
80
  "cmdk": "^1.1.1",
81
- "drizzle-kit": "^0.31.10",
82
- "lucide-react": "^1.47.0",
83
- "nanoid": "^6.0.1",
81
+ "drizzle-kit": "^0.31.11",
82
+ "lucide-react": "^1.62.0",
83
+ "nanoid": "^6.0.2",
84
84
  "tailwind-merge": "^3.7.0",
85
- "tsx": "^4.23.13",
85
+ "tsx": "^4.23.15",
86
86
  "tw-animate-css": "^1.4.0",
87
87
  "uqr": "^0.1.3"
88
88
  },