dsh-sensitive-guard 0.5.2 → 0.5.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/CHANGELOG.md +6 -0
- package/index.js +13 -5
- package/package.json +1 -1
- package/test.mjs +15 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# 变更记录
|
|
2
2
|
|
|
3
|
+
## 0.5.3
|
|
4
|
+
|
|
5
|
+
- 修掉回环路径上的 DNS rebinding 漏洞:`hostHeaderOk` 此前对回环直接放行,而 rebinding 的攻击流量恰恰从回环进来、Host 却是攻击者域名;此时 `sameOriginOk` 看到的 Origin 与 Host 一致,无法区分。现在回环同样要求 Host 是字面量:放行 `localhost`(RFC 6761 保留名,不能被公网 DNS 重绑)、`127.0.0.0/8` 与 `::1`(含 IPv4-mapped 形式)。非回环分支的行为不变。
|
|
6
|
+
- 自测 139 → 142:新增回环来源 + 域名 Host 被 `bad-host` 拒;`localhost` 与 `[::1]` 仍放行三项。
|
|
7
|
+
- 桌面版用 `127.0.0.1` / `localhost` 访问不受影响;从局域网访问仍按原规则要求 `allowCidrs` 且 Host 为 IP 字面量。
|
|
8
|
+
|
|
3
9
|
## 0.5.2
|
|
4
10
|
|
|
5
11
|
- 修掉对话内胶囊的 `aria-label` / `title` 硬编码中文:现在走宿主字典,英文宿主下是 `Show secret` / `Hide secret`;拿不到 locale 服务时仍回退到内置中文,不影响「没服务也要有锁」这条底线。
|
package/index.js
CHANGED
|
@@ -1286,12 +1286,13 @@ function suggestCidr(ip) {
|
|
|
1286
1286
|
}
|
|
1287
1287
|
|
|
1288
1288
|
/**
|
|
1289
|
-
*
|
|
1290
|
-
*
|
|
1291
|
-
* real
|
|
1289
|
+
* The Host header must be an IP literal — loopback included. DNS rebinding
|
|
1290
|
+
* always arrives over loopback but carries the attacker's domain in Host, and
|
|
1291
|
+
* `sameOriginOk` cannot tell it from a real local page (both send a matching
|
|
1292
|
+
* Origin and Host). `localhost` is reserved by RFC 6761 and cannot be rebound
|
|
1293
|
+
* through public DNS, so it stays usable.
|
|
1292
1294
|
*/
|
|
1293
1295
|
function hostHeaderOk(req, level) {
|
|
1294
|
-
if (level === 'loopback') return true;
|
|
1295
1296
|
const raw = String(req.headers.host || '');
|
|
1296
1297
|
if (raw.length === 0) return false;
|
|
1297
1298
|
let name = raw;
|
|
@@ -1302,7 +1303,14 @@ function hostHeaderOk(req, level) {
|
|
|
1302
1303
|
} else if (name.indexOf(':') === name.lastIndexOf(':')) {
|
|
1303
1304
|
name = name.split(':')[0];
|
|
1304
1305
|
}
|
|
1305
|
-
|
|
1306
|
+
const ip = normalizeIp(name);
|
|
1307
|
+
if (level === 'loopback') {
|
|
1308
|
+
if (name.toLowerCase() === 'localhost') return true;
|
|
1309
|
+
if (ip === '::1') return true;
|
|
1310
|
+
const v4 = ipv4Bytes(ip);
|
|
1311
|
+
return v4 !== null && v4[0] === 127;
|
|
1312
|
+
}
|
|
1313
|
+
return ip.length > 0 && isIP(ip) !== 0;
|
|
1306
1314
|
}
|
|
1307
1315
|
|
|
1308
1316
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sensitive-guard",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "敏感信息脱敏 DSH 插件:密钥、令牌、密码、API Key 在进入模型上下文前替换为 <SG_> 占位符,内置 221 条 gitleaks 规则与 .env/JSON 字段识别;明文 AES-256-GCM 加密存本机保管库,点小锁看真值,可导出给命令用。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"icon": "icon.svg",
|
package/test.mjs
CHANGED
|
@@ -496,6 +496,21 @@ const rebound = fakeRes();
|
|
|
496
496
|
await settings.handler({ method: 'GET', socket: { remoteAddress: '198.51.100.78' }, headers: { host: 'evil.example.com:3080' } }, rebound);
|
|
497
497
|
check('rebound host header rejected', rebound.status === 403 && JSON.parse(rebound.body).error === 'bad-host', rebound.body);
|
|
498
498
|
|
|
499
|
+
// Rebinding lands on loopback with a domain Host: same-origin passes, so the
|
|
500
|
+
// Host literal check is the only thing that can still stop it.
|
|
501
|
+
const localRebound = fakeRes();
|
|
502
|
+
await settings.handler({ method: 'GET', socket: { remoteAddress: '127.0.0.1' }, headers: { host: 'evil.example.com:3080' } }, localRebound);
|
|
503
|
+
check('loopback rebound host rejected', localRebound.status === 403 && JSON.parse(localRebound.body).error === 'bad-host', localRebound.body);
|
|
504
|
+
|
|
505
|
+
// Reserved names and literal loopback addresses stay usable.
|
|
506
|
+
const localHostName = fakeRes();
|
|
507
|
+
await settings.handler({ method: 'GET', socket: { remoteAddress: '127.0.0.1' }, headers: { host: 'localhost:3080' } }, localHostName);
|
|
508
|
+
check('loopback localhost still allowed', localHostName.status === 200, String(localHostName.status));
|
|
509
|
+
|
|
510
|
+
const v6Loopback = fakeRes();
|
|
511
|
+
await settings.handler({ method: 'GET', socket: { remoteAddress: '::1' }, headers: { host: '[::1]:3080' } }, v6Loopback);
|
|
512
|
+
check('loopback ::1 still allowed', v6Loopback.status === 200, String(v6Loopback.status));
|
|
513
|
+
|
|
499
514
|
// Cross-site `text/plain` POST needs no preflight; JSON does.
|
|
500
515
|
const plainPost = fakeRes();
|
|
501
516
|
await settings.handler(Object.assign(Readable.from([Buffer.from('{"action":"pause","minutes":30}')]), {
|