@moonquake2004/dsh-security 0.1.4 → 0.1.5
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
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[](LICENSE)
|
|
4
4
|
[](https://www.npmjs.com/package/@moonquake2004/dsh-security)
|
|
5
|
-
[](#)
|
|
6
6
|
|
|
7
|
-
**DSH 生态统一安全检查框架** — 覆盖插件全生命周期(发现→安装→运行→更新→退役),
|
|
7
|
+
**DSH 生态统一安全检查框架** — 覆盖插件全生命周期(发现→安装→运行→更新→退役),21 个内置检查 + 4 个外部工具集成。
|
|
8
8
|
|
|
9
9
|
> Community security tool. Not an official DeepSeek project.
|
|
10
10
|
|
|
@@ -80,6 +80,7 @@ dsh-security 的目标:**建立 DSH 生态的统一安全检查层**,让任
|
|
|
80
80
|
│ SS1: 凭据泄露检测 (会话日志) │
|
|
81
81
|
│ SS2: PII 数据暴露检测 │
|
|
82
82
|
│ SS3: 插件输出敏感数据检测 │
|
|
83
|
+
│ SS4: 会话日志完整性校验 (截断JSON/孤儿tool-call) │
|
|
83
84
|
├──────────────────────────────────────────────────────────┤
|
|
84
85
|
│ Layer 2: Runtime Checks(运行时,基于会话日志) │
|
|
85
86
|
│ SR1: 沙箱逃逸检测 (#1769 mount remount 等) │
|
|
@@ -252,7 +253,7 @@ node --test test/*.mjs
|
|
|
252
253
|
dsh-security/
|
|
253
254
|
├── src/
|
|
254
255
|
│ ├── protocol/ # Layer 0: Check Protocol
|
|
255
|
-
│ ├── checks/ #
|
|
256
|
+
│ ├── checks/ # 21 个内置检查
|
|
256
257
|
│ ├── integrations/ # 4 个外部工具集成
|
|
257
258
|
│ ├── session-reader.mjs # 会话日志读取(明文 + zstd)
|
|
258
259
|
│ ├── registry.mjs # Check Registry(支持 setConfig 注入配置)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonquake2004/dsh-security",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Unified security check framework for DeepSeek Harness ecosystem — covers the full plugin lifecycle (discovery → install → runtime → update → retirement)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.mjs",
|
package/src/checks/index.mjs
CHANGED
|
@@ -25,3 +25,4 @@ export { sl4Check } from './sl4-release-compat.mjs';
|
|
|
25
25
|
export { ss1Check } from './ss1-credential-leak.mjs';
|
|
26
26
|
export { ss2Check } from './ss2-pii-exposure.mjs';
|
|
27
27
|
export { ss3Check } from './ss3-sensitive-output.mjs';
|
|
28
|
+
export { ss4Check } from './ss4-session-integrity.mjs';
|
|
@@ -124,7 +124,7 @@ export async function run(sessionFile) {
|
|
|
124
124
|
.map(f => `行 ${f.line} — ${f.type}(${f.snippet})`)
|
|
125
125
|
.join('\n');
|
|
126
126
|
|
|
127
|
-
const fix = '
|
|
127
|
+
const fix = '轮换泄露的密钥(不可逆),然后清理会话日志:可用 zoahdev/dsh-redact(GitHub: github.com/zoahdev/dsh-redact)或手动删除含密钥的行';
|
|
128
128
|
|
|
129
129
|
return fail(id, Severity.CRITICAL, `检测到 ${findings.length} 个凭据泄露(${summary}):\n${details}`, fix, ['#962']);
|
|
130
130
|
}
|
|
@@ -74,7 +74,7 @@ export async function run(sessionFile) {
|
|
|
74
74
|
for (const f of findings) { if (!byType[f.type]) byType[f.type] = 0; byType[f.type]++; }
|
|
75
75
|
const summary = Object.entries(byType).map(([t, c]) => `${t}: ${c}`).join(', ');
|
|
76
76
|
const details = findings.slice(0, 10).map(f => `行${f.line} — ${f.type}: ${f.snippet}`).join('\n');
|
|
77
|
-
return fail(id, Severity.MEDIUM, `检测到 ${findings.length} 个 PII 暴露(${summary}):\n${details}`, '
|
|
77
|
+
return fail(id, Severity.MEDIUM, `检测到 ${findings.length} 个 PII 暴露(${summary}):\n${details}`, '分享会话日志前用 zoahdev/dsh-redact(github.com/zoahdev/dsh-redact)脱敏,或手动删除含 PII 的行');
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
export const ss2Check = { id: 'SS2', name: 'pii-exposure', severity: Severity.MEDIUM, phase: CheckPhase.POST_INSTALL, description: 'PII 数据暴露检测', src: 'builtin', runner: (f) => run(f) };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SS4: Session Integrity — 会话日志完整性校验
|
|
3
|
+
*
|
|
4
|
+
* 出处:zoahdev/dsh-ecosystem 家族 3(坏工件隔离)+ 家族 11(out-of-tree
|
|
5
|
+
* 会话事件信封缺口)——截断的 tool-call 参数、torn session tail、空文件
|
|
6
|
+
* 会导致会话永久砖化或 resume 失败。
|
|
7
|
+
*
|
|
8
|
+
* 检查项:
|
|
9
|
+
* 1. JSON 语法:逐行 parse,无效行 = 截断/损坏
|
|
10
|
+
* 2. tool/call 配对:每个 tool/call 应有对应 tool/result(孤儿调用)
|
|
11
|
+
* 3. 空/极小文件:0 行或 <10 行 = 可能未正常写入
|
|
12
|
+
*
|
|
13
|
+
* Severity: HIGH
|
|
14
|
+
* Phase: SESSION
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { existsSync, statSync } from 'node:fs';
|
|
18
|
+
import { Severity } from '../protocol/severity.mjs';
|
|
19
|
+
import { CheckPhase } from '../protocol/phase.mjs';
|
|
20
|
+
import { pass, fail, skip } from '../protocol/check.mjs';
|
|
21
|
+
import { scanSessionLines } from '../session-reader.mjs';
|
|
22
|
+
|
|
23
|
+
const MIN_LINES = 10;
|
|
24
|
+
|
|
25
|
+
export async function run(sessionFile) {
|
|
26
|
+
const id = 'SS4';
|
|
27
|
+
|
|
28
|
+
if (!sessionFile || !existsSync(sessionFile)) {
|
|
29
|
+
return skip(id, Severity.HIGH, '无会话日志文件,跳过完整性校验');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 检查文件大小
|
|
33
|
+
let fileSize = 0;
|
|
34
|
+
try { fileSize = statSync(sessionFile).size; } catch { /* ignore */ }
|
|
35
|
+
if (fileSize === 0) {
|
|
36
|
+
return fail(id, Severity.HIGH, '会话日志文件为空(0 字节)——可能未正常写入', '检查 dsh 进程是否正常退出;若为预期空会话可忽略', ['#675']);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let totalLines = 0;
|
|
40
|
+
let invalidJson = 0;
|
|
41
|
+
let firstInvalidLine = null;
|
|
42
|
+
const orphanCalls = new Map(); // callId → line number
|
|
43
|
+
let resultCount = 0;
|
|
44
|
+
|
|
45
|
+
await scanSessionLines(sessionFile, (line, lineNum) => {
|
|
46
|
+
totalLines++;
|
|
47
|
+
|
|
48
|
+
// 1. JSON 语法检查
|
|
49
|
+
let parsed;
|
|
50
|
+
try {
|
|
51
|
+
parsed = JSON.parse(line);
|
|
52
|
+
} catch {
|
|
53
|
+
invalidJson++;
|
|
54
|
+
if (!firstInvalidLine) firstInvalidLine = lineNum;
|
|
55
|
+
return; // 无法 parse 的行跳过后续检查
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 2. tool/call 与 tool/result 配对检查
|
|
59
|
+
const type = parsed.type;
|
|
60
|
+
if (type === 'tool/call') {
|
|
61
|
+
const callId = parsed.data?.callId;
|
|
62
|
+
if (callId) orphanCalls.set(callId, lineNum);
|
|
63
|
+
} else if (type === 'tool/result') {
|
|
64
|
+
const callId = parsed.data?.callId;
|
|
65
|
+
if (callId) {
|
|
66
|
+
orphanCalls.delete(callId); // 配对成功
|
|
67
|
+
resultCount++;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// 3. 极小文件检查
|
|
73
|
+
if (totalLines < MIN_LINES && totalLines > 0) {
|
|
74
|
+
return fail(id, Severity.HIGH,
|
|
75
|
+
`会话日志仅 ${totalLines} 行(阈值 ${MIN_LINES})——可能未完整记录`,
|
|
76
|
+
'检查会话是否正常结束;若为极短会话可忽略',
|
|
77
|
+
['#675']
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const issues = [];
|
|
82
|
+
const refs = [];
|
|
83
|
+
|
|
84
|
+
// 汇总孤儿 tool/call
|
|
85
|
+
if (orphanCalls.size > 0) {
|
|
86
|
+
const samples = [...orphanCalls.entries()].slice(0, 5).map(([id, ln]) => ` 行${ln}: callId=${id.slice(0, 16)}…`);
|
|
87
|
+
issues.push(`${orphanCalls.size} 个孤儿 tool/call(有调用无结果):\n${samples.join('\n')}`);
|
|
88
|
+
refs.push('#3234');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 汇总无效 JSON
|
|
92
|
+
if (invalidJson > 0) {
|
|
93
|
+
issues.push(`${invalidJson} 行无效 JSON(首个在行 ${firstInvalidLine})——可能截断或损坏`);
|
|
94
|
+
refs.push('#675', '#1047');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (issues.length === 0) {
|
|
98
|
+
return pass(id, Severity.HIGH,
|
|
99
|
+
`会话日志完整性通过:${totalLines} 行,JSON 全有效,${resultCount} 个 tool/result 均已配对`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return fail(id, Severity.HIGH,
|
|
103
|
+
`检测到会话日志完整性问题(${totalLines} 行):\n${issues.join('\n\n')}`,
|
|
104
|
+
'截断的 tool/call 会导致会话砖化(#3234);无效 JSON 行可能是损坏的事件(#675/#1047);考虑用 dsh-shelf 归档后重新开始会话',
|
|
105
|
+
refs
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export const ss4Check = {
|
|
110
|
+
id: 'SS4',
|
|
111
|
+
name: 'session-integrity',
|
|
112
|
+
severity: Severity.HIGH,
|
|
113
|
+
phase: CheckPhase.POST_INSTALL,
|
|
114
|
+
description: '会话日志完整性校验——检测截断 JSON、孤儿 tool/call、空/极小文件(家族 3/11)',
|
|
115
|
+
src: 'builtin',
|
|
116
|
+
runner: (sessionFile) => run(sessionFile),
|
|
117
|
+
};
|
package/src/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* DSH Security Framework — 统一安全检查框架
|
|
3
3
|
*
|
|
4
|
-
* 为 DSH 生态提供全生命周期安全检查(
|
|
4
|
+
* 为 DSH 生态提供全生命周期安全检查(21 个检查项,4 层架构)。
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
7
|
* import { createDefaultRegistry } from '@moonquake2004/dsh-security';
|
|
@@ -42,6 +42,7 @@ export { sl4Check } from './checks/sl4-release-compat.mjs';
|
|
|
42
42
|
export { ss1Check } from './checks/ss1-credential-leak.mjs';
|
|
43
43
|
export { ss2Check } from './checks/ss2-pii-exposure.mjs';
|
|
44
44
|
export { ss3Check } from './checks/ss3-sensitive-output.mjs';
|
|
45
|
+
export { ss4Check } from './checks/ss4-session-integrity.mjs';
|
|
45
46
|
|
|
46
47
|
// Registry
|
|
47
48
|
export { SecurityCheckRegistry, createDefaultRegistry } from './registry.mjs';
|
package/src/registry.mjs
CHANGED
|
@@ -147,6 +147,7 @@ export async function createDefaultRegistry(loadExternal = true, options = {}) {
|
|
|
147
147
|
import('./checks/ss1-credential-leak.mjs'),
|
|
148
148
|
import('./checks/ss2-pii-exposure.mjs'),
|
|
149
149
|
import('./checks/ss3-sensitive-output.mjs'),
|
|
150
|
+
import('./checks/ss4-session-integrity.mjs'),
|
|
150
151
|
import('./checks/sp7-client-syntax.mjs'),
|
|
151
152
|
import('./checks/sp8-dist-tag-health.mjs'),
|
|
152
153
|
import('./checks/sp9-dual-instance-guard.mjs'),
|