@momeidejiyi/dsh-general-mcp 0.3.2 → 0.3.3
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/lib/index.js +6 -3
- package/package.json +1 -1
- package/src/index.ts +13 -4
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @momeidejiyi/dsh-general-mcp@0.3.
|
|
1
|
+
// @momeidejiyi/dsh-general-mcp@0.3.3 (generated)
|
|
2
2
|
|
|
3
3
|
// packages/general-mcp/src/index.ts
|
|
4
4
|
import { appendFileSync } from "node:fs";
|
|
@@ -1133,9 +1133,10 @@ function installRoutes(ctx) {
|
|
|
1133
1133
|
if (origin === "") return true;
|
|
1134
1134
|
if (origin.startsWith("dsh-app:") || origin.startsWith("file:")) return true;
|
|
1135
1135
|
const loopback = /^(127\.0\.0\.1|localhost|\[::1\])(:|$)/;
|
|
1136
|
+
if (origin === "null") return loopback.test(host) || host === "";
|
|
1136
1137
|
try {
|
|
1137
1138
|
const originHost = new URL(origin).host;
|
|
1138
|
-
if (host !== "" && originHost === host) return
|
|
1139
|
+
if (host !== "" && originHost === host) return true;
|
|
1139
1140
|
if (loopback.test(originHost) && loopback.test(host)) return true;
|
|
1140
1141
|
} catch {
|
|
1141
1142
|
}
|
|
@@ -1208,7 +1209,9 @@ function installRoutes(ctx) {
|
|
|
1208
1209
|
const catalogPayload = (method, rawUrl, headers) => {
|
|
1209
1210
|
const allowed = cors({ headers });
|
|
1210
1211
|
if (method === "OPTIONS") return { status: 204, headers: { ...allowed }, body: void 0 };
|
|
1211
|
-
if (!trusted({ headers }))
|
|
1212
|
+
if (!trusted({ headers })) {
|
|
1213
|
+
return { status: 401, headers: { ...allowed, "content-type": "text/plain; charset=utf-8" }, body: "unauthorized" };
|
|
1214
|
+
}
|
|
1212
1215
|
const url = new URL(rawUrl, "http://localhost");
|
|
1213
1216
|
const raw = url.searchParams.get("since");
|
|
1214
1217
|
const since = raw !== null && /^\d+$/.test(raw) ? Number(raw) : -1;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -479,11 +479,15 @@ function installRoutes(ctx: any): void {
|
|
|
479
479
|
if (origin === '') return true
|
|
480
480
|
if (origin.startsWith('dsh-app:') || origin.startsWith('file:')) return true
|
|
481
481
|
const loopback = /^(127\.0\.0\.1|localhost|\[::1\])(:|$)/
|
|
482
|
+
// A page opened from a local file (desktop shells, sandboxed webviews)
|
|
483
|
+
// reports the literal origin "null" on every POST, even though same-origin
|
|
484
|
+
// GETs carry no Origin at all.
|
|
485
|
+
if (origin === 'null') return loopback.test(host) || host === ''
|
|
482
486
|
try {
|
|
483
487
|
const originHost = new URL(origin).host
|
|
484
|
-
// origin
|
|
485
|
-
//
|
|
486
|
-
if (host !== '' && originHost === host) return
|
|
488
|
+
// Same-origin is the normal case for the settings page, including when
|
|
489
|
+
// DSH is opened over a LAN/Tailscale address instead of loopback.
|
|
490
|
+
if (host !== '' && originHost === host) return true
|
|
487
491
|
// A page served from loopback may talk to a differently-addressed loopback API.
|
|
488
492
|
if (loopback.test(originHost) && loopback.test(host)) return true
|
|
489
493
|
} catch {}
|
|
@@ -554,10 +558,15 @@ function installRoutes(ctx: any): void {
|
|
|
554
558
|
const catalogPayload = (method: string, rawUrl: string, headers: Record<string, string>) => {
|
|
555
559
|
const allowed = cors({ headers })
|
|
556
560
|
if (method === 'OPTIONS') return { status: 204, headers: { ...allowed }, body: undefined as string | undefined }
|
|
557
|
-
if (!trusted({ headers }))
|
|
561
|
+
if (!trusted({ headers })) {
|
|
562
|
+
// 401 carries a short text body, so say what it is. 304 stays
|
|
563
|
+
// body-less (a Content-Type there would describe nothing).
|
|
564
|
+
return { status: 401, headers: { ...allowed, 'content-type': 'text/plain; charset=utf-8' }, body: 'unauthorized' }
|
|
565
|
+
}
|
|
558
566
|
const url = new URL(rawUrl, 'http://localhost')
|
|
559
567
|
const raw = url.searchParams.get('since')
|
|
560
568
|
const since = raw !== null && /^\d+$/.test(raw) ? Number(raw) : -1
|
|
569
|
+
// RFC 9110: a 304 repeats validators/Cache-Control/Vary, never a body.
|
|
561
570
|
if (since === live.version) return { status: 304, headers: { ...allowed }, body: undefined }
|
|
562
571
|
return {
|
|
563
572
|
status: 200,
|