Skip to content

fix(security): detect ENCRYPTED PRIVATE KEY variant; gate truncated-PEM mask on base64 body (#3084) - #3085

Merged
topcheer merged 1 commit into
mainfrom
fix-3084-pem
Oct 2, 2026
Merged

topcheer merged 1 commit into
mainfrom
fix-3084-pem

Conversation

@topcheer

@topcheer topcheer commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Closes #3084

修复要点

  • V2 (high): secretdetect.go private_key_block 前缀枚举加 ENCRYPTED ——-----BEGIN ENCRYPTED PRIVATE KEY-----(openssl pkcs8 -topk8 加密私钥标准形态)此前漏检且无兜底,检测层与显示层 [A-Z ]* 前缀类的第 5 次 drift 收口。
  • V1 (medium): display_redact.go private_key_truncated 模式加 base64 体门控:裸头后须跟换行 + ≥20 个 base64 字符才触发遮蔽。字面讨论 PEM 格式的文档/教学文本(裸头后接普通说明文字)不再被压成星号到文末;真截断密钥(头+base64 体无 END)仍整段遮蔽。

测试证据

zz_issue3084_test.go(2 组断言):

  1. ENCRYPTED 形态触发 private_key_block high finding;RSA 形态无回归
  2. 字面提及裸头的 prose 原样保留;真截断密钥体仍遮蔽;完整块仍由原模式处理

go test -tags goolm ./internal/security/ 全绿(含 #3082 引入的 zz_issue3081 与既有套件),gofmt / pre-commit(vet+build)过。

…EM mask on base64 body (#3084)

Co-Authored-By: ggcode <noreply@ggcode.dev>
@topcheer

topcheer commented Oct 2, 2026

Copy link
Copy Markdown
Owner Author

[watchdog] 复核:通过。改动小而聚焦,两处正则都核对过源码语义:(1) ENCRYPTED 前缀加入 private_key_block alternation 正确,与显示层 [A-Z ]* 前缀类覆盖对齐,检测/显示漂移消除;(2) truncated-PEM gate 要求 header 后紧跟 [\r\n]+ + ≥20 个 base64 字符才 mask 到 buffer 尾——openssl 标准输出(64 列、无空行)满足此形态,纯 prose 提及不再被 mask。顺序依赖(complete-block pattern 先行)在注释中已声明。测试覆盖 prose/truncated/complete 三场景 + 检测层回归,充分。风险:无。

微点(不阻塞):测试文件名 zz_issue3084_test.go 的 zz_ 前缀 unusual,若非有意的编译顺序考虑,下个 PR 顺手改为 issue3084_test.go 更符合仓库惯例。

@topcheer topcheer left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

治理席 diff 级复核(#3084):无阻塞,批准合并。

V2(ENCRYPTED 检测):detection 层前缀交替组补 ENCRYPTED,对齐 display 层 [A-Z ]* 类——第 5 次 detection/display drift 关闭。RSA 回归探针钉住。
V1(truncated 门控):[\r\n]+[A-Za-z0-9+/=]{20,}.* 门控精确——header 后需真 base64 体才 mask,散文提及(prose 行含空格/普通词)不再误杀;恰好收窄了 #3082 复核时记录的 over-mask 观察(贪婪到 buffer 尾保留但有了前置门槛,保守方向)。truncated 泄漏断言+complete 块回归齐备。

本地验证:git archive 隔离树 security 全包绿。CI rerun 后全绿(lsp TestIssue993 flake 已按协议本地×5复现+rerun 处置,记录在案)。按 #3082/#3087 前例条件完备,我方将执行 admin merge 关 #3084。

@topcheer
topcheer merged commit dd056c9 into main Oct 2, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[code-review] secretdetect misses ENCRYPTED PRIVATE KEY variant (high); display_redact truncated-PEM pattern over-masks literal PEM discussion (medium)

1 participant