dsh-code-security 0.3.6 → 0.3.8
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 +29 -0
- package/README.en.md +31 -27
- package/README.md +23 -66
- package/docs/CHANGELOG.en.md +15 -0
- package/docs/ITERATION-2026-10-12.md +53 -0
- package/docs/USAGE.en.md +37 -0
- package/docs/USAGE.md +85 -0
- package/docs/VALIDATION.md +15 -0
- package/lib/config.d.ts +1 -0
- package/lib/config.js +2 -1
- package/lib/diff.d.ts +3 -0
- package/lib/diff.js +112 -34
- package/lib/extra.d.ts +1 -1
- package/lib/extra.js +4 -4
- package/lib/index.d.ts +3 -2
- package/lib/index.js +3 -2
- package/lib/policy.d.ts +1 -1
- package/lib/policy.js +17 -5
- package/lib/runner.d.ts +2 -0
- package/lib/runner.js +4 -2
- package/lib/scanner.d.ts +4 -1
- package/lib/scanner.js +79 -35
- package/lib/state.d.ts +2 -2
- package/lib/state.js +76 -20
- package/lib/tools.d.ts +2 -2
- package/lib/tools.js +37 -13
- package/package.json +10 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# 更新记录
|
|
2
|
+
|
|
3
|
+
[返回简介](README.md) · [使用说明](docs/USAGE.md) · [验证记录](docs/VALIDATION.md)
|
|
4
|
+
|
|
5
|
+
[历史英文记录](docs/CHANGELOG.en.md)
|
|
6
|
+
|
|
7
|
+
## 0.3.8 (2026-10-12)
|
|
8
|
+
|
|
9
|
+
- 修复增量扫描遗漏中文/转义文件名、私钥、`.env` 敏感项和禁用依赖审计配置的问题,报告真实证据行号。
|
|
10
|
+
- 结合有限上下文识别已有豁免和跨行配置,仅报告涉及新增行的问题;校验差异块行数,格式错误或不完整时明确报错。
|
|
11
|
+
- 全量、单文件与增量扫描统一排除策略和工作区相对路径,兼容旧记录中 `./` 前缀的基线指纹。
|
|
12
|
+
- 固定 Git 输出格式与当前工作区范围,禁用外部 diff/textconv,拒绝被误当成 Git 选项的基线参数和错误类型的 `staged` 参数。
|
|
13
|
+
- 补充隔离 Git 回归场景;范围、兼容注意事项及后续计划见[本轮迭代记录](docs/ITERATION-2026-10-12.md)。
|
|
14
|
+
|
|
15
|
+
## 0.3.7 (2026-10-05)
|
|
16
|
+
|
|
17
|
+
- 扫描、策略、报告和 git diff 使用当前会话工作区;支持取消并跳过目录联接。锁定合并历史与基线写入,损坏记录和无效策略明确报错并保留原文件。
|
|
18
|
+
|
|
19
|
+
## 0.3.6 (2026-09-28)
|
|
20
|
+
|
|
21
|
+
- 更新官方 Harness 0.2.0-rc.1 的兼容声明和共同加载验证;运行时代码未变。验证范围见[验证记录](docs/VALIDATION.md)。
|
|
22
|
+
|
|
23
|
+
## 0.3.5 (2026-09-28)
|
|
24
|
+
|
|
25
|
+
扫描参数写错时明确报错,避免把 `paths`、`files` 或空目标误当成扫描整个工作区。修复标准模式中结果卡片误显示“0 个文件、未通过”的问题;文件数量、结论与问题列表现在使用实际扫描结果。
|
|
26
|
+
|
|
27
|
+
## 更早的改动
|
|
28
|
+
|
|
29
|
+
完整历史可查阅 [GitHub 提交记录](https://github.com/STARDUSTLC666/dsh-code-security/commits/master)。
|
package/README.en.md
CHANGED
|
@@ -1,44 +1,48 @@
|
|
|
1
1
|
# dsh-code-security
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[中文](README.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+

|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Run local static security checks on code or Git changes and verify fixes.
|
|
8
8
|
|
|
9
|
-

|
|
9
|
+
[](https://www.npmjs.com/package/dsh-code-security) [](https://www.npmjs.com/package/dsh-code-security)
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Feedback and contributions are welcome: report [issues](https://github.com/STARDUSTLC666/dsh-code-security/issues) or submit [pull requests](https://github.com/STARDUSTLC666/dsh-code-security/pulls).
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
## What it does
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
- Scan files, directories or Git diffs with locations and code evidence.
|
|
16
|
+
- Recheck fixes and manage baselines or scan policy.
|
|
17
|
+
- Export Markdown or SARIF reports and inspect dependency manifests.
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
## Install
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
In DSH Desktop, install `dsh-code-security` from the Plugins panel. If the bundled dsh command is available:
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
```bash
|
|
24
|
+
dsh plugin --profile desktop add dsh-code-security
|
|
25
|
+
```
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
| :-- | :-- | :-- |
|
|
25
|
-
| `secure_scan` | Scan files with CWE/severity/line/snippet evidence | state |
|
|
26
|
-
| `secure_diff` | Review only added lines of git diff | state |
|
|
27
|
-
| `secure_fix_verify` | Compare with baseline: closed / remaining / fresh | state |
|
|
28
|
-
| `secure_report` | Aggregate by rule/file with gate verdict | no |
|
|
29
|
-
| `secure_export` | Export SARIF 2.1.0 / Markdown | file write approval |
|
|
30
|
-
| `secure_baseline` | Accept current findings as baseline; gate on new issues only | approval |
|
|
31
|
-
| `secure_deps` | SBOM-lite: parse dependency manifests and version-risk flags | no |
|
|
32
|
-
| `secure_policy_show` | Show .code-security.json | no |
|
|
33
|
-
| `secure_policy_set` | Replace policy JSON | approval |
|
|
27
|
+
For the web version, replace `desktop` with `web`. Restart DSH after installation.
|
|
34
28
|
|
|
35
|
-
|
|
29
|
+
## Start using it
|
|
36
30
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
Ask: “Review the current Git diff for security findings, show evidence and recheck the fixes.”
|
|
32
|
+
|
|
33
|
+
## Requirements and configuration
|
|
34
|
+
|
|
35
|
+
Deterministic rules run locally. See the usage guide for rule coverage, baselines and policy configuration.
|
|
36
|
+
|
|
37
|
+
Detailed configuration, tool arguments and troubleshooting are in the [usage guide](docs/USAGE.en.md). For standalone development, follow the Node requirement in [package.json](package.json).
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
- [Usage and troubleshooting](docs/USAGE.en.md)
|
|
42
|
+
- [Changelog](CHANGELOG.md)
|
|
43
|
+
- [Validation scope and history](docs/VALIDATION.md)
|
|
44
|
+
- [Report a problem or suggest a feature](https://github.com/STARDUSTLC666/dsh-code-security/issues)
|
|
40
45
|
|
|
41
|
-
MIT
|
|
42
46
|
## License
|
|
43
47
|
|
|
44
|
-
MIT
|
|
48
|
+
[MIT](LICENSE)
|
package/README.md
CHANGED
|
@@ -1,91 +1,48 @@
|
|
|
1
1
|
# dsh-code-security
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[English](README.en.md)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+

|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
对代码与 Git 改动进行本地静态安全检查,并追踪修复结果。
|
|
8
8
|
|
|
9
|
-

|
|
9
|
+
[](https://www.npmjs.com/package/dsh-code-security) [](https://www.npmjs.com/package/dsh-code-security)
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
欢迎使用,遇到问题或有改进建议,请提交 [issues](https://github.com/STARDUSTLC666/dsh-code-security/issues) 和 [PR](https://github.com/STARDUSTLC666/dsh-code-security/pulls)。
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
## 功能
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
| :-- | :-- | :-- |
|
|
19
|
-
| `secure_scan` | 扫描文件/目录,输出 CWE/严重度/行号/代码片段证据 | 写状态 |
|
|
20
|
-
| `secure_diff` | 只审查 git diff 新增行 | 写状态 |
|
|
21
|
-
| `secure_fix_verify` | 修复后复扫:关闭 / 仍存在 / 新引入 | 写状态 |
|
|
22
|
-
| `secure_report` | 按规则/文件聚合 + 门禁结论 | 否 |
|
|
23
|
-
| `secure_export` | 导出 SARIF 2.1.0 / Markdown 报告 | 写文件审批 |
|
|
24
|
-
| `secure_baseline` | 接受当前已知问题为基线,之后只按新增判定 | 审批门 |
|
|
25
|
-
| `secure_deps` | SBOM-lite:解析依赖清单与版本约束风险 | 否 |
|
|
26
|
-
| `secure_policy_show` | 查看 .code-security.json 策略 | 否 |
|
|
27
|
-
| `secure_policy_set` | 写入策略(排除/忽略/阈值) | 审批门 |
|
|
28
|
-
|
|
29
|
-
## 规则覆盖(40+)
|
|
30
|
-
|
|
31
|
-
- 注入:eval / exec / shell=True / SQL 拼接 / innerHTML
|
|
32
|
-
- 反序列化:pickle / yaml.load / ObjectInputStream / Marshal / unserialize
|
|
33
|
-
- 加密:弱哈希、ECB、硬编码 IV/密钥、JWT none、TLS 校验关闭、Shell TLS 绕过(curl -k / wget --no-check-certificate / git sslVerify=false)
|
|
34
|
-
- 凭据:硬编码密码、令牌、私钥、高熵密钥
|
|
35
|
-
- 配置:chmod 777、Docker privileged / latest、npm audit=false、CORS *
|
|
36
|
-
- 泄露:敏感日志、错误堆栈外发、路径穿越、SSRF
|
|
37
|
-
|
|
38
|
-
发现只包含客观证据与 CWE 编号,不附修复建议——修复方案由 agent 基于证据生成。
|
|
39
|
-
|
|
40
|
-
## 兼容性
|
|
41
|
-
|
|
42
|
-
已在官方 `@deepseek-ai/dsh@0.1.5-rc.1`、Node `24.16.0` 上验证(2026-09-11):18 个组件与 Modlens 同载,工具 schema、技能注册及离线只读调用检查通过。采用 `cordis.patch.yml` + `dsh.bundle.patch` 组合包模型。Node 要求与该版本 Harness 一致:22.19 及以上的 22.x,或 24 及以上。外部服务的实际业务操作需按各组件配置单独验证。
|
|
43
|
-
|
|
44
|
-
2026-09-13 修复:保留宿主 `subprocess.spawn` 的服务对象,避免方法独立传递后因 `this` 丢失而报错。已在官方 `0.1.5-rc.1` 和 `0.1.5-rc.2`、Node `24.16.0` 上验证。`secure_diff` 已通过真实宿主进程服务读取隔离 Git 仓库差异,正确识别变更文件和新增行。
|
|
15
|
+
- 扫描文件、目录或 Git diff,报告规则、位置与代码证据。
|
|
16
|
+
- 复扫修复结果,维护问题基线和检查策略。
|
|
17
|
+
- 导出 Markdown / SARIF 报告,检查依赖清单。
|
|
45
18
|
|
|
46
19
|
## 安装
|
|
47
20
|
|
|
48
|
-
|
|
49
|
-
dsh plugin --profile web add dsh-code-security
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## 卸载
|
|
21
|
+
桌面版可在「插件」面板按包名 `dsh-code-security` 安装。已配置 dsh 命令时也可使用:
|
|
53
22
|
|
|
54
23
|
```bash
|
|
55
|
-
dsh plugin --profile
|
|
24
|
+
dsh plugin --profile desktop add dsh-code-security
|
|
56
25
|
```
|
|
57
26
|
|
|
58
|
-
|
|
27
|
+
网页版把命令中的 `desktop` 改为 `web`。安装后重启 DSH。
|
|
59
28
|
|
|
29
|
+
## 开始使用
|
|
60
30
|
|
|
61
|
-
|
|
31
|
+
安装后可说:“审查当前 Git 改动的安全问题,给出位置和证据,再复查修复结果。”
|
|
62
32
|
|
|
63
|
-
|
|
64
|
-
secure_scan { target: src }
|
|
65
|
-
secure_diff { base: HEAD }
|
|
66
|
-
secure_fix_verify { target: src }
|
|
67
|
-
secure_baseline { reason: 历史遗留 }
|
|
68
|
-
secure_deps { target: . }
|
|
69
|
-
```
|
|
33
|
+
## 依赖与配置
|
|
70
34
|
|
|
71
|
-
|
|
35
|
+
默认在本机执行确定性规则检查。规则覆盖与基线、策略配置见使用说明。
|
|
72
36
|
|
|
73
|
-
|
|
74
|
-
{
|
|
75
|
-
"version": 1,
|
|
76
|
-
"exclude": ["vendor/**", "generated/**"],
|
|
77
|
-
"ignore": [{ "ruleId": "SEC-206", "file": "test/**", "reason": "非安全敏感" }],
|
|
78
|
-
"failOn": "high"
|
|
79
|
-
}
|
|
80
|
-
```
|
|
37
|
+
详细配置、工具参数与排错见[使用说明](docs/USAGE.md)。从源码独立开发时,Node 要求以 [package.json](package.json) 为准。
|
|
81
38
|
|
|
82
|
-
##
|
|
39
|
+
## 文档
|
|
83
40
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
41
|
+
- [使用与排错](docs/USAGE.md)
|
|
42
|
+
- [更新记录](CHANGELOG.md)
|
|
43
|
+
- [验证范围与历史记录](docs/VALIDATION.md)
|
|
44
|
+
- [问题反馈与功能建议](https://github.com/STARDUSTLC666/dsh-code-security/issues)
|
|
87
45
|
|
|
88
|
-
MIT
|
|
89
46
|
## License
|
|
90
47
|
|
|
91
|
-
MIT
|
|
48
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Historical release notes
|
|
2
|
+
|
|
3
|
+
[Current changelog](../CHANGELOG.md) · [Overview](../README.en.md)
|
|
4
|
+
|
|
5
|
+
These English notes preserve the earlier translations. The main changelog contains the consolidated version history.
|
|
6
|
+
|
|
7
|
+
## 0.3.7 (2026-10-05)
|
|
8
|
+
|
|
9
|
+
- Use the session workspace for scans, policy, reports and git diff. Respect cancellation and skip directory junctions. Lock history/baseline merges and preserve damaged files with explicit errors.
|
|
10
|
+
|
|
11
|
+
## 0.3.5 (2026-09-28)
|
|
12
|
+
|
|
13
|
+
Rejects unknown scan arguments and empty targets before scanning or replacing state, preventing misspelled scopes from expanding to the whole workspace. Fixes standard-mode output incorrectly displaying zero files and a failed verdict: counts, verdicts and findings now come from the actual scan result.
|
|
14
|
+
|
|
15
|
+
Validation host: Harness `0.2.0-rc.1` built from official sources (commit `407e65c8`) with Node `24.16.0` on 2026-09-28. All 31 plugin tests pass in an isolated environment; all 18 plugins mount together in one host registering 10 tools, with tool schemas and health-check contracts passing. No live ports or external services were exercised in this round.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# dsh-code-security 第一轮迭代
|
|
2
|
+
|
|
3
|
+
日期:2026-10-12。基于 `91d4d8c770cfaa796d07b7b770a627c3bce8f49e`,本轮版本为 `0.3.8`。此页记录源码迭代和本地验证;发布 CI、npm 完整性及隔离安装结果在发布后独立核验。
|
|
4
|
+
|
|
5
|
+
这轮先解决增量审查的漏报、范围和证据一致性。原有 37 项测试全部通过,但新增回归测试在旧实现上复现了中文路径、文件级规则等问题被误判为通过。
|
|
6
|
+
|
|
7
|
+
## 已实现
|
|
8
|
+
|
|
9
|
+
| 场景 | 原行为 | 当前行为 |
|
|
10
|
+
| :-- | :-- | :-- |
|
|
11
|
+
| 中文/转义文件名 | Git 引号与八进制路径解析失败,可能返回零发现并通过 | 解码 UTF-8 与 Git 的 C 转义,保留正确文件和行号 |
|
|
12
|
+
| 新增私钥、`.env` 敏感项、`audit=false` | 增量扫描跳过文件级规则 | 全量和增量共用匹配,定位实际证据;保留跨行配置检测 |
|
|
13
|
+
| 未改动的豁免注释、危险代码 | 缺少上下文,已有 next-line 豁免失效 | 读取少量上下文,只报告证据涉及新增行的问题 |
|
|
14
|
+
| 仓库子目录作为会话工作区 | 带入兄弟目录改动,路径基准偏离工作区 | Git 范围和证据路径均相对当前会话工作区 |
|
|
15
|
+
| 策略排除 | 增量扫描未应用排除,直接选择文件也绕过排除 | 三种扫描入口统一排除;报告实际扫描和跳过数量 |
|
|
16
|
+
| 基线一致性 | 全量的 `./src/a.js` 与增量的 `src/a.js` 指纹不同 | 规范相对路径,并从保存的证据重算旧基线指纹 |
|
|
17
|
+
| Git 个性化配置/参数 | 颜色、前缀影响解析;`--quiet` 可误当基线 | 固定输出格式,禁用外部 diff/textconv,校验参数类型 |
|
|
18
|
+
| 差异块缺失行 | 接受不完整差异并给出部分结果 | 校验差异块行数,异常时保留原扫描状态并报错 |
|
|
19
|
+
|
|
20
|
+
主要代码:[diff.ts](../src/diff.ts)、[scanner.ts](../src/scanner.ts)、[tools.ts](../src/tools.ts)、[state.ts](../src/state.ts)。已同步仓库跟踪的 `lib/` 构建产物。
|
|
21
|
+
|
|
22
|
+
## 验证
|
|
23
|
+
|
|
24
|
+
- `pnpm test`:53/53 通过,0 失败,0 跳过;包含 TypeScript 构建。
|
|
25
|
+
- 新增 16 项回归测试,其中 9 项使用本地隔离 Git 仓库。覆盖中文路径、暂存区与工作树不一致、Git 输出偏好、子工作区、基线兼容、外部转换器与排除计数等。
|
|
26
|
+
- 工具调用链覆盖 `secure_scan` / `secure_diff` / `secure_baseline` / `secure_fix_verify` / `secure_report` / `secure_export`,验证写入状态、结果渲染文本和 SARIF 路径。
|
|
27
|
+
- 环境:Windows,Node `24.16.0`,pnpm `11.7.0`,Git `2.54.0.windows.1`。
|
|
28
|
+
- 本页所列测试未在真实 DSH Web/桌面界面执行点击、输入或视觉验收;本地运行环境为 Windows/Node 24,Linux CI 与 npm 发布验收另行记录。
|
|
29
|
+
|
|
30
|
+
回归入口:[diff.test.mjs](../test/diff.test.mjs)、[git-diff.test.mjs](../test/git-diff.test.mjs)。测试仓库位于 E 盘项目内的 `test/.tmp/`,测试结束后仅清理经过路径校验的自建子目录。
|
|
31
|
+
|
|
32
|
+
## 兼容注意
|
|
33
|
+
|
|
34
|
+
未新增依赖;继续沿用项目已有的 MIT 许可与 `proper-lockfile@4.1.2`(MIT),Node 声明保持 `^22.19.0 || >=24.0.0`。原工具名和参数结构保留,增量输出增加明确的扫描/跳过计数。
|
|
35
|
+
|
|
36
|
+
旧记录的 `./` 前缀兼容已验证。`SEC-303`、`SEC-305`、`SEC-404` 的证据由“整个文件开头”改成“实际匹配片段”;旧基线若使用前一种片段,可能被视为新增。应复扫并人工确认后重新接受,不能自动把新证据全部豁免。
|
|
37
|
+
|
|
38
|
+
增量检查只涵盖 Git 显示的文本差异,仍不包含未跟踪文件。上下文为前后各 3 行;超出上下文的跨行结构、通用数据流和复杂语言语义未由本轮解决。差异块校验可以发现块内截断,但不代表已解决所有收集上限下的完整性判断。
|
|
39
|
+
|
|
40
|
+
## 下一轮优先项
|
|
41
|
+
|
|
42
|
+
以下来自当前代码静态检查,尚未在本轮实现或验收。
|
|
43
|
+
|
|
44
|
+
1. **扫描完整性门禁。** `scanPath` 遇到不存在目标、读取失败或文件数上限时,应返回明确的完整性状态;`passed` 不能仅因发现为空而为真。还应检查宿主 stdout 收集上限带来的整体截断。
|
|
45
|
+
2. **复扫范围校验。** `secure_fix_verify` 应核对上次与本次目标/覆盖范围,避免把没有重新扫描的问题误报为关闭;部分复扫应输出“未验证”。
|
|
46
|
+
3. **规则准确性与隐私。** 补充安全/危险样例集,优先处理普通字符串、块注释、已使用安全 Loader 等误报;为密钥证据增加默认脱敏,并设计不依赖明文片段的稳定指纹。
|
|
47
|
+
4. **依赖清单解析。** 为标准 `pyproject.toml`、Cargo 依赖区段和损坏清单补测试,再评估采用 MIT/兼容许可的 TOML 解析器;当前 SBOM-lite 不能当作漏洞数据库扫描。
|
|
48
|
+
|
|
49
|
+
后续功能迭代仍需补单插件真实 DSH 界面验收和更广的跨平台 CI;本版发布验证独立进行。
|
|
50
|
+
|
|
51
|
+
## Git 行为依据
|
|
52
|
+
|
|
53
|
+
输出格式、工作区相对范围和外部转换器开关按 [Git diff 官方文档](https://git-scm.com/docs/git-diff) 实现;文件名转义依据 [core.quotePath 官方说明](https://git-scm.com/docs/git-config#Documentation/git-config.txt-corequotePath)。
|
package/docs/USAGE.en.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# dsh-code-security usage guide
|
|
2
|
+
|
|
3
|
+
[Overview](../README.en.md) · [Changelog](../CHANGELOG.md) · [Validation](VALIDATION.md)
|
|
4
|
+
|
|
5
|
+
## Current improvements
|
|
6
|
+
|
|
7
|
+
Relative stateDir defaults to .code-security in the session workspace. Concurrent scans retain both histories. Damaged records must be inspected after backup rather than silently recreated. Scans skip symlinks and junctions; static rules do not replace a full security audit.
|
|
8
|
+
|
|
9
|
+
0.3.8 (2026-10-12): incremental reviews decode Git's quoted paths and check added private keys, `.env` secrets and disabled audit settings. Three context lines on each side support existing next-line suppressions and multiline settings; only evidence intersecting added lines is reported. Multiline locations point to the match's first line. Staged reviews use index content rather than later working-tree edits.
|
|
10
|
+
|
|
11
|
+
Full, directly selected file and incremental scans share default and policy exclusions. Paths and Git scope are relative to the session workspace, including nested workspaces. `filesScanned` counts reviewed files and `filesSkipped` includes exclusions; incremental results also provide `filesChanged` and reviewed `addedLines`. Git output uses fixed colors/prefixes and disables external diff/textconv helpers. Invalid `base`/`staged` arguments and malformed or incomplete hunks fail without replacing scan state.
|
|
12
|
+
|
|
13
|
+
Saved evidence with a legacy `./` path prefix still matches baselines. File-level findings now use actual matching snippets; older baselines that saved the beginning of an entire file may require a fresh scan and human review before acceptance.
|
|
14
|
+
|
|
15
|
+
## Tools
|
|
16
|
+
|
|
17
|
+
| Tool | Purpose | Write |
|
|
18
|
+
| :-- | :-- | :-- |
|
|
19
|
+
| `secure_scan` | Scan files with CWE/severity/line/snippet evidence | state |
|
|
20
|
+
| `secure_diff` | Review only added lines of git diff | state |
|
|
21
|
+
| `secure_fix_verify` | Compare with baseline: closed / remaining / fresh | state |
|
|
22
|
+
| `secure_report` | Aggregate by rule/file with gate verdict | no |
|
|
23
|
+
| `secure_export` | Export SARIF 2.1.0 / Markdown | file write approval |
|
|
24
|
+
| `secure_baseline` | Accept current findings as baseline; gate on new issues only | approval |
|
|
25
|
+
| `secure_deps` | SBOM-lite: parse dependency manifests and version-risk flags | no |
|
|
26
|
+
| `secure_policy_show` | Show .code-security.json | no |
|
|
27
|
+
| `secure_policy_set` | Replace policy JSON | approval |
|
|
28
|
+
|
|
29
|
+
40+ deterministic rules: injection, deserialization, weak crypto (including shell TLS bypass flags), secrets, dangerous config, sensitive logging, path traversal, SSRF.
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
dsh plugin --profile web add dsh-code-security
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
MIT (see [LICENSE](../LICENSE))
|
package/docs/USAGE.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# dsh-code-security 使用说明
|
|
2
|
+
|
|
3
|
+
[返回简介](../README.md) · [更新记录](../CHANGELOG.md) · [验证记录](VALIDATION.md)
|
|
4
|
+
|
|
5
|
+
## 本次改进
|
|
6
|
+
|
|
7
|
+
相对 stateDir 默认在会话工作区的 .code-security。并发扫描保留双方历史;记录损坏时先备份排查,不会默默重建。扫描不跟随符号链接或目录联接;静态规则不能代替完整安全审计。
|
|
8
|
+
|
|
9
|
+
0.3.8 改进(2026-10-12):`secure_diff` 支持 Git 转义的中文/特殊文件名,并检查新增私钥、`.env` 敏感项与禁用审计配置。它读取前后各 3 行上下文以处理已有豁免和跨行配置,只报告证据涉及新增行的问题;跨行证据的行号指向匹配的起始行。暂存扫描以暂存区内容为准。
|
|
10
|
+
|
|
11
|
+
全量、直接指定文件与增量扫描均遵守默认目录排除及策略 `exclude`。文件路径统一相对当前会话工作区;在仓库子目录作为工作区时,增量扫描不包含该目录外的改动。返回的 `filesScanned` 为实际审查的文件数,`filesSkipped` 包含排除项;增量结果另有 `filesChanged` 和实际审查的 `addedLines`。
|
|
12
|
+
|
|
13
|
+
`base` 必须是非空 Git ref,不能以 `-` 开头;`staged` 必须是布尔值。差异块行数不完整或格式错误会报错,本次不会覆盖已有扫描记录。Git 的颜色/前缀偏好不会改变解析格式,外部 diff 和 textconv 转换器被禁用。
|
|
14
|
+
|
|
15
|
+
旧记录的 `./` 路径前缀可继续匹配基线。私钥、`.env` 和禁用审计配置现在使用实际匹配片段;旧基线若保存的是文件开头的大段文本,可能被重新识别为新增,需复扫并人工复核后再接受。详见[本轮迭代记录](ITERATION-2026-10-12.md)。
|
|
16
|
+
|
|
17
|
+
## 工具
|
|
18
|
+
|
|
19
|
+
| 工具 | 作用 | 写操作 |
|
|
20
|
+
| :-- | :-- | :-- |
|
|
21
|
+
| `secure_scan` | 扫描文件/目录,输出 CWE/严重度/行号/代码片段证据 | 写状态 |
|
|
22
|
+
| `secure_diff` | 只审查 git diff 新增行 | 写状态 |
|
|
23
|
+
| `secure_fix_verify` | 修复后复扫:关闭 / 仍存在 / 新引入 | 写状态 |
|
|
24
|
+
| `secure_report` | 按规则/文件聚合 + 门禁结论 | 否 |
|
|
25
|
+
| `secure_export` | 导出 SARIF 2.1.0 / Markdown 报告 | 写文件审批 |
|
|
26
|
+
| `secure_baseline` | 接受当前已知问题为基线,之后只按新增判定 | 审批门 |
|
|
27
|
+
| `secure_deps` | SBOM-lite:解析依赖清单与版本约束风险 | 否 |
|
|
28
|
+
| `secure_policy_show` | 查看 .code-security.json 策略 | 否 |
|
|
29
|
+
| `secure_policy_set` | 写入策略(排除/忽略/阈值) | 审批门 |
|
|
30
|
+
|
|
31
|
+
## 规则覆盖(40+)
|
|
32
|
+
|
|
33
|
+
- 注入:eval / exec / shell=True / SQL 拼接 / innerHTML
|
|
34
|
+
- 反序列化:pickle / yaml.load / ObjectInputStream / Marshal / unserialize
|
|
35
|
+
- 加密:弱哈希、ECB、硬编码 IV/密钥、JWT none、TLS 校验关闭、Shell TLS 绕过(curl -k / wget --no-check-certificate / git sslVerify=false)
|
|
36
|
+
- 凭据:硬编码密码、令牌、私钥、高熵密钥
|
|
37
|
+
- 配置:chmod 777、Docker privileged / latest、npm audit=false、CORS *
|
|
38
|
+
- 泄露:敏感日志、错误堆栈外发、路径穿越、SSRF
|
|
39
|
+
|
|
40
|
+
发现只包含客观证据与 CWE 编号,不附修复建议——修复方案由 agent 基于证据生成。
|
|
41
|
+
|
|
42
|
+
## 安装
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
dsh plugin --profile web add dsh-code-security
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 卸载
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
dsh plugin --profile web remove dsh-code-security
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
卸载后重启 Web 服务。如需彻底清理,可再手动删除自己 profile `cordis.patch.yml` 中覆盖的插件行。
|
|
55
|
+
|
|
56
|
+
## 使用
|
|
57
|
+
|
|
58
|
+
```text
|
|
59
|
+
secure_scan { target: src }
|
|
60
|
+
secure_diff { base: HEAD }
|
|
61
|
+
secure_fix_verify { target: src }
|
|
62
|
+
secure_baseline { reason: 历史遗留 }
|
|
63
|
+
secure_deps { target: . }
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
策略示例(`.code-security.json`):
|
|
67
|
+
|
|
68
|
+
```json
|
|
69
|
+
{
|
|
70
|
+
"version": 1,
|
|
71
|
+
"exclude": ["vendor/**", "generated/**"],
|
|
72
|
+
"ignore": [{ "ruleId": "SEC-206", "file": "test/**", "reason": "非安全敏感" }],
|
|
73
|
+
"failOn": "high"
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 工程
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pnpm test # 构建并执行测试
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
MIT(见 [LICENSE](../LICENSE))
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# dsh-code-security 验证记录
|
|
2
|
+
|
|
3
|
+
本页整理原 README 的历史验证说明,保留当时的版本、日期与范围。自动测试、启动检查、浏览器操作和真实服务验收分别记录,不能相互替代。更详细的版本验收文件仍保留在仓库中。
|
|
4
|
+
|
|
5
|
+
## 原中文记录
|
|
6
|
+
|
|
7
|
+
2026-09-13 修复:保留宿主 `subprocess.spawn` 的服务对象,避免方法独立传递后因 `this` 丢失而报错。该路径已在隔离宿主进程服务中实测通过。`secure_diff` 已通过真实宿主进程服务读取隔离 Git 仓库差异,正确识别变更文件和新增行。
|
|
8
|
+
|
|
9
|
+
## Original English record
|
|
10
|
+
|
|
11
|
+
2026-09-13 fix: retain the service receiver when calling `subprocess.spawn`, preventing failures caused by passing the method as an unbound callback. Verified against a real isolated host subprocess service. `secure_diff` reads a real isolated Git repository through the host subprocess service and reports the changed file and added line.
|
|
12
|
+
|
|
13
|
+
## 0.3.6 原验证说明
|
|
14
|
+
|
|
15
|
+
验证宿主:官方源码构建的 Harness `0.2.0-rc.1`(commit `407e65c8`)+ Node `24.16.0`(2026-09-28)。31 项插件测试在隔离环境全部通过;同一个宿主里 18 个插件共同加载,注册 10 个工具,工具 schema 与健康检查契约通过。本轮未启用真实端口与外部服务。
|
package/lib/config.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export interface ResolvedSecureConfig {
|
|
|
15
15
|
maxFileBytes: number;
|
|
16
16
|
failOn: Severity;
|
|
17
17
|
stateDir: string;
|
|
18
|
+
stateDirRelative?: string;
|
|
18
19
|
}
|
|
19
20
|
export declare const DEFAULT_EXCLUDE_DIRS: string[];
|
|
20
21
|
export declare function resolveConfig(config: SecureConfig | undefined | null, cwd?: string): ResolvedSecureConfig;
|
package/lib/config.js
CHANGED
|
@@ -21,7 +21,8 @@ export function resolveConfig(config, cwd = process.cwd()) {
|
|
|
21
21
|
}
|
|
22
22
|
const failOn = cfg.failOn === 'critical' || cfg.failOn === 'high' || cfg.failOn === 'medium' || cfg.failOn === 'low' ? cfg.failOn : 'medium';
|
|
23
23
|
const stateDir = typeof cfg.stateDir === 'string' && cfg.stateDir.trim() !== '' ? path.resolve(cwd, cfg.stateDir.trim()) : path.join(cwd, '.code-security');
|
|
24
|
-
|
|
24
|
+
const rawStateDir = typeof cfg.stateDir === 'string' && cfg.stateDir.trim() ? cfg.stateDir.trim() : '.code-security';
|
|
25
|
+
return { maxFiles, maxFileBytes, failOn, stateDir, ...(path.isAbsolute(rawStateDir) ? {} : { stateDirRelative: rawStateDir }) };
|
|
25
26
|
}
|
|
26
27
|
export function optionalString(args, key) {
|
|
27
28
|
const value = args[key];
|
package/lib/diff.d.ts
CHANGED
|
@@ -13,10 +13,13 @@ export interface DiffLine {
|
|
|
13
13
|
export interface DiffFile {
|
|
14
14
|
file: string;
|
|
15
15
|
added: DiffLine[];
|
|
16
|
+
context?: DiffLine[];
|
|
16
17
|
}
|
|
17
18
|
export interface DiffScanResult {
|
|
18
19
|
base: string;
|
|
19
20
|
filesChanged: number;
|
|
21
|
+
filesScanned: number;
|
|
22
|
+
filesSkipped: number;
|
|
20
23
|
addedLines: number;
|
|
21
24
|
findings: Finding[];
|
|
22
25
|
diff: string;
|