@momeidejiyi/dsh-general-mcp 0.1.1 → 0.1.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 +17 -4
- package/package.json +1 -1
- package/src/index.ts +13 -1
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @momeidejiyi/dsh-general-mcp@0.1.
|
|
1
|
+
// @momeidejiyi/dsh-general-mcp@0.1.3 (generated)
|
|
2
2
|
|
|
3
3
|
// packages/general-mcp/src/index.ts
|
|
4
4
|
import { appendFileSync } from "node:fs";
|
|
@@ -559,9 +559,22 @@ async function apply(ctx, config = {}) {
|
|
|
559
559
|
const installed = shared.__GENMCP_ROUTES__ ??= /* @__PURE__ */ new WeakMap();
|
|
560
560
|
if (installed.get(webServer) === true) return;
|
|
561
561
|
installed.set(webServer, true);
|
|
562
|
+
const sameOrigin = (req) => {
|
|
563
|
+
const headers = req.headers ?? {};
|
|
564
|
+
const site = headers["sec-fetch-site"];
|
|
565
|
+
if (site === "same-origin") return true;
|
|
566
|
+
const origin = headers.origin;
|
|
567
|
+
const host = headers.host;
|
|
568
|
+
if (typeof origin !== "string" || typeof host !== "string" || origin === "") return false;
|
|
569
|
+
try {
|
|
570
|
+
return new URL(origin).host === host;
|
|
571
|
+
} catch {
|
|
572
|
+
return false;
|
|
573
|
+
}
|
|
574
|
+
};
|
|
562
575
|
const authorized = (req) => {
|
|
563
576
|
const authorization = req.headers?.authorization ?? "";
|
|
564
|
-
return authorization === "Bearer " + live.token;
|
|
577
|
+
return authorization === "Bearer " + live.token || sameOrigin(req);
|
|
565
578
|
};
|
|
566
579
|
const send = (res, status, payload) => {
|
|
567
580
|
res.writeHead(status, { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" });
|
|
@@ -601,8 +614,8 @@ async function apply(ctx, config = {}) {
|
|
|
601
614
|
resource: async (request) => {
|
|
602
615
|
const headers = request.headers;
|
|
603
616
|
const bearer = headers?.get?.("authorization") === "Bearer " + live.token;
|
|
604
|
-
const
|
|
605
|
-
if (!bearer && !
|
|
617
|
+
const sameOrigin2 = headers?.get?.("sec-fetch-site") === "same-origin";
|
|
618
|
+
if (!bearer && !sameOrigin2) {
|
|
606
619
|
return new Response("unauthorized", { status: 401, headers: { "cache-control": "no-store" } });
|
|
607
620
|
}
|
|
608
621
|
const url = new URL(request.url);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -213,9 +213,21 @@ export async function apply(ctx: any, config: Config = {}) {
|
|
|
213
213
|
if (installed.get(webServer) === true) return
|
|
214
214
|
installed.set(webServer, true)
|
|
215
215
|
|
|
216
|
+
// Writes accept either the boot token or a same-origin browser request.
|
|
217
|
+
// The token alone made the UI unusable whenever index-inject did not fire
|
|
218
|
+
// (older DSH builds, or a page loaded before the plugin registered).
|
|
219
|
+
const sameOrigin = (req: any): boolean => {
|
|
220
|
+
const headers = req.headers ?? {}
|
|
221
|
+
const site = headers['sec-fetch-site']
|
|
222
|
+
if (site === 'same-origin') return true
|
|
223
|
+
const origin = headers.origin
|
|
224
|
+
const host = headers.host
|
|
225
|
+
if (typeof origin !== 'string' || typeof host !== 'string' || origin === '') return false
|
|
226
|
+
try { return new URL(origin).host === host } catch { return false }
|
|
227
|
+
}
|
|
216
228
|
const authorized = (req: any): boolean => {
|
|
217
229
|
const authorization = req.headers?.authorization ?? ''
|
|
218
|
-
return authorization === 'Bearer ' + live.token
|
|
230
|
+
return authorization === 'Bearer ' + live.token || sameOrigin(req)
|
|
219
231
|
}
|
|
220
232
|
const send = (res: any, status: number, payload: unknown) => {
|
|
221
233
|
res.writeHead(status, { 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' })
|