@kidecms/core 0.35.1 → 0.36.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.
- package/internals/allowed-domains.ts +13 -0
- package/internals/integration.ts +8 -1
- package/middleware/auth.ts +2 -19
- package/middleware/csrf.ts +19 -0
- package/package.json +24 -24
|
@@ -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
|
+
};
|
package/internals/integration.ts
CHANGED
|
@@ -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: {
|
package/middleware/auth.ts
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
3
|
+
"version": "0.36.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.
|
|
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.
|
|
55
|
-
"@base-ui/react": "^1.
|
|
56
|
-
"@better-auth/passkey": "1.7.
|
|
57
|
-
"@better-auth/utils": "0.
|
|
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.
|
|
62
|
-
"@radix-ui/react-dropdown-menu": "^2.1
|
|
63
|
-
"@radix-ui/react-popover": "^1.1
|
|
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.
|
|
67
|
-
"@tiptap/extension-image": "3.
|
|
68
|
-
"@tiptap/extension-link": "3.
|
|
69
|
-
"@tiptap/extension-placeholder": "3.
|
|
70
|
-
"@tiptap/markdown": "3.
|
|
71
|
-
"@tiptap/pm": "3.
|
|
72
|
-
"@tiptap/react": "3.
|
|
73
|
-
"@tiptap/starter-kit": "3.
|
|
74
|
-
"@tiptap/suggestion": "3.
|
|
75
|
-
"ai": "^6.0.
|
|
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.
|
|
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.
|
|
82
|
-
"lucide-react": "^1.
|
|
83
|
-
"nanoid": "^6.0.
|
|
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.
|
|
85
|
+
"tsx": "^4.23.15",
|
|
86
86
|
"tw-animate-css": "^1.4.0",
|
|
87
87
|
"uqr": "^0.1.3"
|
|
88
88
|
},
|