dsh-ws-recency 0.32.1 → 0.32.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/README.md +6 -0
- package/index.js +49 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -188,6 +188,12 @@ DSH 原生的置顶只把会话顶到**它所属工作区分组的第一行**,
|
|
|
188
188
|
|
|
189
189
|
偏好持久化在 Client store 的 `dsh.ws-recency.prefs.v1`。
|
|
190
190
|
|
|
191
|
+
## 局域网 / 网关访问
|
|
192
|
+
|
|
193
|
+
插件的宿主路由(删除、回收站、统计、搜索、移动、交接)会校验请求来源:只接受**同源**请求,也就是 `Origin` 指向的 host 与请求的 `Host`(或代理的 `X-Forwarded-Host`)一致;没有 `Origin` 的非浏览器请求照旧放行。
|
|
194
|
+
|
|
195
|
+
所以用 `dsh-gateway` 之类的转接插件、或直接从局域网 IP 访问时,删除和统计都能正常用;只有**真正的跨站页面**会被 403 拒绝。0.32.1 及更早的版本只认回环地址,非回环访问一律 403(issue #3)。
|
|
196
|
+
|
|
191
197
|
## 已知边界
|
|
192
198
|
|
|
193
199
|
- 依赖宿主 DOM:分组容器带 `_groupSection`、分组头带 `data-row-key="workspace:<id>"`、行带 `data-row-key="session:<id>"`、溢出按钮类名含 `sessionOverflowButton`。宿主改结构就要跟着改。
|
package/index.js
CHANGED
|
@@ -32,7 +32,7 @@ import { dirname, join } from "node:path";
|
|
|
32
32
|
export const name = "ws-recency";
|
|
33
33
|
|
|
34
34
|
/** Version marker reported by the health route. */
|
|
35
|
-
export const HOST_VERSION = "0.32.
|
|
35
|
+
export const HOST_VERSION = "0.32.2";
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Exact routes the client half calls. Registered on the bare web server, so they
|
|
@@ -67,16 +67,52 @@ function sessionIdFrom(req, body) {
|
|
|
67
67
|
return body !== null && body !== undefined && typeof body.sessionId === "string" ? body.sessionId.trim() : "";
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
/**
|
|
71
|
-
function
|
|
70
|
+
/** Hostnames that are this machine, whatever port is in front of them. */
|
|
71
|
+
function isLoopbackHostname(hostname) {
|
|
72
|
+
const name = String(hostname ?? "").toLowerCase().replace(/^\[|\]$/g, "");
|
|
73
|
+
return name === "localhost" || name === "127.0.0.1" || name === "::1" || name.endsWith(".localhost");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Whether a request comes from the app itself.
|
|
78
|
+
*
|
|
79
|
+
* The old rule demanded a loopback origin, which refused every page that reached
|
|
80
|
+
* the app through a LAN address or a gateway - those pages are the app too, and
|
|
81
|
+
* the user could not delete a session from them.
|
|
82
|
+
*
|
|
83
|
+
* What actually has to be stopped is a foreign page driving these destructive
|
|
84
|
+
* routes at a local server (a browser will send its own origin). So the rule is
|
|
85
|
+
* same-origin: the origin has to name the host the request was addressed to, as
|
|
86
|
+
* seen either directly or through a proxy's forwarded headers. A request with no
|
|
87
|
+
* origin comes from a non-browser client and is allowed, as before.
|
|
88
|
+
*/
|
|
89
|
+
function trustedOrigin(req) {
|
|
72
90
|
const origin = req.headers.origin;
|
|
73
|
-
if (origin === undefined) return true;
|
|
91
|
+
if (origin === undefined || origin === null || origin === "") return true;
|
|
92
|
+
let originHost = "";
|
|
93
|
+
let originName = "";
|
|
74
94
|
try {
|
|
75
|
-
const
|
|
76
|
-
|
|
95
|
+
const parsed = new URL(String(origin));
|
|
96
|
+
originHost = parsed.host.toLowerCase();
|
|
97
|
+
originName = parsed.hostname.toLowerCase();
|
|
77
98
|
} catch {
|
|
78
99
|
return false;
|
|
79
100
|
}
|
|
101
|
+
const headers = req.headers ?? {};
|
|
102
|
+
const candidates = [headers.host, headers["x-forwarded-host"]]
|
|
103
|
+
.filter((value) => typeof value === "string" && value !== "")
|
|
104
|
+
.flatMap((value) => String(value).split(","))
|
|
105
|
+
.map((value) => value.trim().toLowerCase())
|
|
106
|
+
.filter((value) => value !== "");
|
|
107
|
+
for (const candidate of candidates) {
|
|
108
|
+
if (candidate === originHost) return true;
|
|
109
|
+
const name = candidate.replace(/:\d+$/, "");
|
|
110
|
+
if (name === originName) return true;
|
|
111
|
+
}
|
|
112
|
+
/* No host header at all: a non-browser client, judged by the old rule. */
|
|
113
|
+
if (candidates.length === 0) return isLoopbackHostname(originName);
|
|
114
|
+
/* Loopback to loopback stays allowed even if a proxy rewrote the host. */
|
|
115
|
+
return isLoopbackHostname(originName) && candidates.some((value) => isLoopbackHostname(value.replace(/:\d+$/, "")));
|
|
80
116
|
}
|
|
81
117
|
|
|
82
118
|
async function readJsonBody(req) {
|
|
@@ -266,7 +302,7 @@ export async function handleTrashRequest(ctx, req, res) {
|
|
|
266
302
|
sendJson(res, 405, { ok: false, error: "method not allowed" });
|
|
267
303
|
return;
|
|
268
304
|
}
|
|
269
|
-
if (!
|
|
305
|
+
if (!trustedOrigin(req)) {
|
|
270
306
|
sendJson(res, 403, { ok: false, error: "origin not trusted" });
|
|
271
307
|
return;
|
|
272
308
|
}
|
|
@@ -2231,7 +2267,7 @@ export async function handleHandoffRequest(ctx, req, res) {
|
|
|
2231
2267
|
sendJson(res, 405, { ok: false, error: "method not allowed" });
|
|
2232
2268
|
return;
|
|
2233
2269
|
}
|
|
2234
|
-
if (!
|
|
2270
|
+
if (!trustedOrigin(req)) {
|
|
2235
2271
|
sendJson(res, 403, { ok: false, error: "origin not trusted" });
|
|
2236
2272
|
return;
|
|
2237
2273
|
}
|
|
@@ -2320,7 +2356,7 @@ export async function handleTrashListRequest(ctx, req, res) {
|
|
|
2320
2356
|
sendJson(res, 405, { ok: false, error: "method not allowed" });
|
|
2321
2357
|
return;
|
|
2322
2358
|
}
|
|
2323
|
-
if (!
|
|
2359
|
+
if (!trustedOrigin(req)) {
|
|
2324
2360
|
sendJson(res, 403, { ok: false, error: "origin not trusted" });
|
|
2325
2361
|
return;
|
|
2326
2362
|
}
|
|
@@ -2380,7 +2416,7 @@ export async function handleAdoptRequest(ctx, req, res) {
|
|
|
2380
2416
|
sendJson(res, 405, { ok: false, error: "method not allowed" });
|
|
2381
2417
|
return;
|
|
2382
2418
|
}
|
|
2383
|
-
if (!
|
|
2419
|
+
if (!trustedOrigin(req)) {
|
|
2384
2420
|
sendJson(res, 403, { ok: false, error: "origin not trusted" });
|
|
2385
2421
|
return;
|
|
2386
2422
|
}
|
|
@@ -2397,7 +2433,7 @@ export async function handleMoveRequest(ctx, req, res) {
|
|
|
2397
2433
|
sendJson(res, 405, { ok: false, error: "method not allowed" });
|
|
2398
2434
|
return;
|
|
2399
2435
|
}
|
|
2400
|
-
if (!
|
|
2436
|
+
if (!trustedOrigin(req)) {
|
|
2401
2437
|
sendJson(res, 403, { ok: false, error: "origin not trusted" });
|
|
2402
2438
|
return;
|
|
2403
2439
|
}
|
|
@@ -2422,7 +2458,7 @@ export async function handleSearchRequest(ctx, req, res) {
|
|
|
2422
2458
|
sendJson(res, 405, { ok: false, error: "method not allowed" });
|
|
2423
2459
|
return;
|
|
2424
2460
|
}
|
|
2425
|
-
if (!
|
|
2461
|
+
if (!trustedOrigin(req)) {
|
|
2426
2462
|
sendJson(res, 403, { ok: false, error: "origin not trusted" });
|
|
2427
2463
|
return;
|
|
2428
2464
|
}
|
|
@@ -2449,7 +2485,7 @@ export async function handleStatsRequest(ctx, req, res) {
|
|
|
2449
2485
|
sendJson(res, 405, { ok: false, error: "method not allowed" });
|
|
2450
2486
|
return;
|
|
2451
2487
|
}
|
|
2452
|
-
if (!
|
|
2488
|
+
if (!trustedOrigin(req)) {
|
|
2453
2489
|
sendJson(res, 403, { ok: false, error: "origin not trusted" });
|
|
2454
2490
|
return;
|
|
2455
2491
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-ws-recency",
|
|
3
|
-
"version": "0.32.
|
|
3
|
+
"version": "0.32.2",
|
|
4
4
|
"description": "Sidebar session management for DeepSeek Harness: workspace groups sorted by latest activity, stale history folded, a global pinned section, follow-up marks, session delete into a recoverable trash, archived sessions managed from that same trash panel, per-session token statistics with an argument/result split and an option to count tool arguments as the agent's writing, moving a session to another workspace, and a literal content search that jumps to the turn a word was said in.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "chyxhtc",
|