@jokab1074/rememberme 0.22.0 → 0.22.1
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/LICENSE +19 -18
- package/README.en.md +18 -0
- package/README.md +18 -0
- package/dist/mcp/index.js +71 -24
- package/package.json +1 -1
- package/server.json +2 -2
- package/src/mcp/instructions.ts +2 -1
- package/src/mcp/tools/record-turn.ts +58 -13
- package/src/profile.ts +1095 -1008
- package/src/web-security.ts +43 -0
- package/src/web.ts +724 -624
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/web-security.ts
|
|
2
|
+
//
|
|
3
|
+
// 网页版的网络暴露面相关的纯函数(单独成文件,方便单测直接 import
|
|
4
|
+
// —— src/web.ts 一被 import 就会启动服务器,不能在测试里直接引)。
|
|
5
|
+
//
|
|
6
|
+
// ⚠️ 背景(v0.22.0 修复的真实安全问题):
|
|
7
|
+
//
|
|
8
|
+
// Bun.serve 不写 hostname 时**默认绑 0.0.0.0**(所有网卡)。
|
|
9
|
+
// 同一局域网里任何设备都能访问这个服务,而 POST /api/send 会直接
|
|
10
|
+
// 用用户的 API key 调 LLM —— key 不会"泄露",但额度会被别人烧掉。
|
|
11
|
+
// /api/messages、/api/sessions 还会把对话历史读走,/api/clear 能删会话。
|
|
12
|
+
//
|
|
13
|
+
// 修复后的策略:
|
|
14
|
+
// 1. 默认只监听 127.0.0.1(要放开用 HOST=0.0.0.0)
|
|
15
|
+
// 2. 一旦监听**非回环**地址,必须配 EC_WEB_TOKEN,否则**拒绝启动**
|
|
16
|
+
// (fail-closed:宁可起不来,也不要默默把 key 送人)
|
|
17
|
+
// 3. 所有 /api/* 做同源检查,挡浏览器发起的 CSRF
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 是否是本机回环地址(只有这种地址才不需要鉴权)。
|
|
21
|
+
*
|
|
22
|
+
* 覆盖:127.0.0.0/8 整段、localhost、IPv6 的 ::1。
|
|
23
|
+
*/
|
|
24
|
+
export function isLoopbackHost(host: string): boolean {
|
|
25
|
+
const h = host.trim().toLowerCase().replace(/^\[|\]$/g, "");
|
|
26
|
+
if (h === "localhost" || h === "::1" || h === "0:0:0:0:0:0:0:1") return true;
|
|
27
|
+
return /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(h);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 常量时间比较。
|
|
32
|
+
*
|
|
33
|
+
* 逐字符比较会在第一个不同的字节就返回,理论上能被时序攻击推出 token 前缀。
|
|
34
|
+
* 这里累加 XOR 差异,保证耗时与内容无关。
|
|
35
|
+
*/
|
|
36
|
+
export function safeEqual(a: string, b: string): boolean {
|
|
37
|
+
if (a.length !== b.length) return false;
|
|
38
|
+
let diff = 0;
|
|
39
|
+
for (let i = 0; i < a.length; i++) {
|
|
40
|
+
diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
41
|
+
}
|
|
42
|
+
return diff === 0;
|
|
43
|
+
}
|