fix(#2198): remove dead scan exports, correct injection-scan docs

scanEntropyAnomalies + shannonEntropy were dead exports with zero
production callers — the live hooks (gsd-prompt-guard.js,
gsd-read-injection-scanner.js) inline their own pattern subsets for
hook independence and never called these functions.

Changes:
- Remove scanEntropyAnomalies + shannonEntropy from src/security.cts
- Remove scanEntropyAnomalies test block from tests/security.test.cjs
- Correct REQ-SCAN-INJ-02/-03 in FEATURES.md (EN/zh-CN/ja-JP) to
  describe what actually runs live (injection patterns, invisible
  Unicode) vs CI-only (base64-decode, codebase scan)
- Correct docs/security/baseline.md §2.4 to clarify live hooks inline
  patterns, not import from security.cts
- Add regression test asserting the corrected contract
- scanForInjection retained: it serves as the CI codebase-scanner engine
This commit is contained in:
Tom Boucher
2026-07-11 23:48:05 -04:00
parent 96b632d4eb
commit 8022c5c864
9 changed files with 132 additions and 134 deletions

View File

@@ -2267,15 +2267,15 @@ Test suite that scans all agent, workflow, and command files for embedded inject
### 99. Improved Prompt Injection Scanner
**Hook:** `gsd-prompt-guard.js`
**Script:** `scripts/prompt-injection-scan.sh`
**Hook:** `gsd-prompt-guard.js`, `gsd-read-injection-scanner.js`
**Script:** `scripts/prompt-injection-scan.sh`, `scripts/base64-scan.sh`
**Purpose:** Enhanced detection of prompt injection attempts in planning artifacts, adding invisible Unicode character detection, encoding obfuscation patterns, and entropy-based analysis.
**Purpose:** Defense-in-depth detection of prompt injection attempts in planning artifacts and ingested content. Live hooks inline their own pattern subsets for hook independence (they do not import from `security.cts`). The CI scanner (`scanForInjection` in `security.cts`) provides a centralized engine for codebase-wide scanning in tests.
**Requirements:**
- REQ-SCAN-INJ-01: Scanner MUST detect invisible Unicode characters (zero-width spaces, soft hyphens, etc.)
- REQ-SCAN-INJ-02: Scanner MUST detect encoding obfuscation patterns (base64-encoded instructions, homoglyphs)
- REQ-SCAN-INJ-03: Scanner MUST apply entropy analysis to flag high-entropy strings in unexpected positions
- REQ-SCAN-INJ-01: Live hooks MUST detect invisible Unicode characters (zero-width spaces, soft hyphens, Unicode tag block U+E0000–E007F)
- REQ-SCAN-INJ-02: Live hooks MUST detect known injection patterns (instruction override, role manipulation, system-prompt extraction, fake message boundaries). Base64-decode scanning is a CI-time control (`scripts/base64-scan.sh`), not a live hook — live hooks match a base64-exfiltration phrase regex only, they do not decode.
- REQ-SCAN-INJ-03: ~~Scanner MUST apply entropy analysis~~ — Entropy analysis (`scanEntropyAnomalies`) was removed in #2198 as dead code (zero production callers; live hooks do not perform entropy analysis). This requirement is deferred pending a maintainable live implementation.
- REQ-SCAN-INJ-04: Scanner MUST remain advisory-only — detection is logged, not blocking
---

View File

@@ -2195,15 +2195,15 @@ Claude が GSD ワークフローコンテキスト外でファイル編集を
### 99. 改善されたプロンプトインジェクションスキャナー
**フック:** `gsd-prompt-guard.js`
**スクリプト:** `scripts/prompt-injection-scan.sh`
**フック:** `gsd-prompt-guard.js`、`gsd-read-injection-scanner.js`
**スクリプト:** `scripts/prompt-injection-scan.sh`、`scripts/base64-scan.sh`
**目的:** プランニングアーティファクト内のプロンプトインジェクション試みの検出を強化し、不可視 Unicode 文字検出、エンコードの難読化パターン、エントロピーベースの分析を追加します。
**目的:** プランニングアーティファクトおよび取り込んだコンテンツ内のプロンプトインジェクション試行の多層防御検出。ライブフックはフック独立性のために独自のパターンサブセットをインライン化します(`security.cts` からインポートしません)。CIスキャナー(`security.cts` の `scanForInjection`)は、テストでのコードベース全体スキャン用の集中エンジンを提供します。
**要件:**
- REQ-SCAN-INJ-01: スキャナーは不可視 Unicode 文字(ゼロ幅スペース、ソフトハイフンなど)を検出しなければならない
- REQ-SCAN-INJ-02: スキャナーはエンコードの難読化パターン(base64 エンコードされた命令、ホモグリフ)を検出しなければならない
- REQ-SCAN-INJ-03: スキャナーは予期しない位置の高エントロピー文字列にフラグを立てるためにエントロピー分析を適用しなければならない
- REQ-SCAN-INJ-01: ライブフックは不可視 Unicode 文字(ゼロ幅スペース、ソフトハイフン、Unicode タグブロック U+E0000–E007F)を検出しなければならない
- REQ-SCAN-INJ-02: ライブフックは既知のインジェクションパターン(命令オーバーライド、ロール操作、システムプロンプト抽出、偽のメッセージ境界)を検出しなければならない。Base64 デコードスキャンは CI 時制御(`scripts/base64-scan.sh`)であり、ライブフックではない — ライブフックは base64 持ち出しフレーズ正規表現のみを一致させ、デコードはしない。
- REQ-SCAN-INJ-03: ~~スキャナーはエントロピー分析を適用しなければならない~~ — エントロピー分析(`scanEntropyAnomalies`)は #2198 でデッドコードとして削除された(本番呼び出し元ゼロ;ライブフックはエントロピー分析を実行しない)。この要件は保守可能なライブ実装まで保留。
- REQ-SCAN-INJ-04: スキャナーは勧告的のみでなければならない — 検出はログに記録されるが、ブロッキングではない
---

View File

@@ -133,11 +133,16 @@ file before the job passes.
### 2.4 Locale-safe text scanning
**Control:** Text output and user-facing strings are scanned for locale-unsafe
constructs (non-ASCII homoglyphs, bidirectional override characters, invisible
Unicode) that could be used to obscure malicious content in diffs or logs.
**Control:** Text output and user-facing strings are scanned for invisible
Unicode and bidirectional override characters that could be used to obscure
malicious content in diffs or logs. The live hooks
(`gsd-prompt-guard.js`, `gsd-read-injection-scanner.js`) inline their own
Unicode-detection patterns for hook independence — they do not call
`scanForInjection` from `security.cts`. The centralized `scanForInjection`
function serves as the CI codebase-scanner engine
(`tests/prompt-injection-scan.security.test.cjs`).
**Why it matters:** Unicode homoglyph and BiDi attacks are documented
**Why it matters:** Unicode invisible-character and BiDi attacks are documented
supply-chain vectors (CVE-2021-42574 — "Trojan Source"). Detecting them at scan
time prevents invisible payload injection in source and output files.

View File

@@ -2211,15 +2211,15 @@ PreToolUse 钩子,检测 Claude 在 GSD 工作流上下文之外尝试文件
### 99. 改进的提示注入扫描器
**钩子:** `gsd-prompt-guard.js`
**脚本:** `scripts/prompt-injection-scan.sh`
**钩子:** `gsd-prompt-guard.js`、`gsd-read-injection-scanner.js`
**脚本:** `scripts/prompt-injection-scan.sh`、`scripts/base64-scan.sh`
**目的:** 增强对规划构件中提示注入尝试的检测,添加不可见 Unicode 字符检测、编码混淆模式和基于熵的分析。
**目的:** 对规划构件和摄入内容中提示注入尝试的深度防御检测。实时钩子为保持独立性内联了自己的模式子集(不导入 `security.cts`)。CI 扫描器(`security.cts` 中的 `scanForInjection`)为测试中的全代码库扫描提供集中引擎。
**需求:**
- REQ-SCAN-INJ-01:扫描器必须检测不可见 Unicode 字符(零宽空格、软连字符等)
- REQ-SCAN-INJ-02:扫描器必须检测编码混淆模式(base64 编码的指令、同形字)
- REQ-SCAN-INJ-03:扫描器必须应用熵分析以标记意外位置的高熵字符串
- REQ-SCAN-INJ-01:实时钩子必须检测不可见 Unicode 字符(零宽空格、软连字符、Unicode 标签块 U+E0000–E007F)
- REQ-SCAN-INJ-02:实时钩子必须检测已知注入模式(指令覆盖、角色操纵、系统提示提取、伪造消息边界)。Base64 解码扫描是 CI 时控制(`scripts/base64-scan.sh`),不是实时钩子 — 实时钩子仅匹配 base64 外泄短语正则,不解码。
- REQ-SCAN-INJ-03:~~扫描器必须应用熵分析~~ — 熵分析(`scanEntropyAnomalies`)在 #2198 中作为死代码被移除(零生产调用者;实时钩子不执行熵分析)。此需求推迟到有可维护的实时实现时。
- REQ-SCAN-INJ-04:扫描器必须保持仅建议性 — 检测会被记录,而不会阻止
---