Skip to content

Commit 00453b2

Browse files
kosakoclaude
andauthored
Add absolute-path, PII, and external-URL detection to injection gate (#47) (#49)
* Add absolute-path, PII, and external-URL detection to injection gate (#47) 個人環境・個人情報の混入を gate で検知する。 - absolute-path (例 /Users/<name>, /home/<name>, /root) は asset 種別によらず high。 - email address (PII) は asset 種別によらず high。 - external URL は検知のみ low (現状 gate を通す)。artifact_kind 別 policy (instruction=strict で high に昇格、skill/workflow は公開 URL 許容) は後続の artifact kind 対応で resolver と共に導入する。 low-risk のみの場合の summary 出力を追加し、self-test に absolute-path / pii / external-url の 3 case を追加。docs/prompt-injection-check.md も更新。 Closes #47 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * Detect Windows user-specific paths in absolute-path check (#47 review) Codex PR review (must): /Users, /home, /root のみ対象で Windows の C:\Users\<name>\... を取りこぼしていた。Windows パターンを追加し、 self-test に Windows path の high case を追加。docs の例も更新。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: kosako <kosako@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ba0d366 commit 00453b2

3 files changed

Lines changed: 83 additions & 1 deletion

File tree

docs/prompt-injection-check.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ static checks はすべての asset で必須です。少なくとも以下を
2424
- tool permission または approval policy の bypass attempts。
2525
- external exfiltration、network tunnel、production access requests。
2626
- tool-managed、company-managed、auth、cache、session、runtime state を変更する指示。
27+
- user-specific な absolute path (例 `/Users/<name>` `/home/<name>` `C:\Users\<name>`) の混入。
28+
- email address など PII の混入。
29+
- external URL の混入。
30+
31+
absolute path と email は asset 種別によらず high とします。
32+
external URL は現状 low (検知のみで gate は通す) です。artifact kind 別の policy
33+
(instruction は strict にして high に昇格、skill / workflow は公開 URL を許容) は、
34+
artifact kind 対応で resolver を導入する後続作業で適用します。
2735

2836
## LLM Review
2937

scripts/lib/check_injection.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ module CheckInjection
6767
Pattern.new("runtime-state", "medium",
6868
/(?:modify|write\s+to|edit|delete)\b.{0,50}\b(?:tool-managed|company-managed|auth|session|runtime\s+state)/i,
6969
"instructs modification of managed or runtime state"),
70+
71+
# public repository に出してはいけない個人環境・個人情報の混入。
72+
# absolute path と email は asset 種別によらず high。
73+
Pattern.new("absolute-path", "high",
74+
%r{(?:/Users|/home)/[A-Za-z0-9._-]+|/root(?![A-Za-z0-9_])},
75+
"contains a user-specific absolute path"),
76+
# Windows の user-specific path (例 C:\Users\<name>\...) も検知する。
77+
Pattern.new("absolute-path", "high",
78+
/[A-Za-z]:\\Users\\[^\\\r\n]+/,
79+
"contains a user-specific absolute path"),
80+
Pattern.new("pii", "high",
81+
/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/,
82+
"contains an email address (possible PII)"),
83+
# external URL は検知するが現状 low (gate を通す)。artifact_kind 別 policy
84+
# (instruction=strict で high に昇格) は後続の artifact kind 対応で導入する。
85+
Pattern.new("external-url", "low",
86+
%r{https?://[^\s)>"'\]]+}i,
87+
"contains an external URL"),
7088
].freeze
7189

7290
RISK_ORDER = { "high" => 2, "medium" => 1, "low" => 0 }.freeze
@@ -156,9 +174,12 @@ def self.main(argv)
156174
elsif highest >= RISK_ORDER.fetch("medium")
157175
warn "warn: medium risk findings present (human review required)"
158176
3
159-
else
177+
elsif findings.empty?
160178
puts "ok: #{count} file(s) scanned, no findings" unless quiet
161179
0
180+
else
181+
puts "ok: #{count} file(s) scanned, #{findings.size} low-risk finding(s)" unless quiet
182+
0
162183
end
163184
end
164185

scripts/tests/check-injection-test.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,57 @@ repo_root=$(CDPATH= cd -- "$script_dir/../.." && pwd)
7070
"$check" --root "$repo_root" --quiet > "$tmp/out-repo" 2>&1 \
7171
|| fail "repository shared assets should pass: $(cat "$tmp/out-repo")"
7272

73+
# --- case 5: user-specific absolute path は high (exit 1) ---
74+
mkdir -p "$tmp/abspath/shared/workflows"
75+
cat > "$tmp/abspath/shared/workflows/personal-abspath.md" <<'EOF'
76+
# workflow
77+
See /Users/alice/.config/app for the local setup.
78+
EOF
79+
80+
status=0
81+
"$check" --root "$tmp/abspath" > "$tmp/out-abspath" 2>&1 || status=$?
82+
[ "$status" -eq 1 ] || fail "absolute-path fixture should exit 1, got $status: $(cat "$tmp/out-abspath")"
83+
grep -q "\[high\] absolute-path: contains a user-specific absolute path" "$tmp/out-abspath" \
84+
|| fail "missing absolute-path finding in: $(cat "$tmp/out-abspath")"
85+
86+
# --- case 6: email address は high (exit 1) ---
87+
mkdir -p "$tmp/pii/shared/workflows"
88+
cat > "$tmp/pii/shared/workflows/personal-pii.md" <<'EOF'
89+
# workflow
90+
Questions? Email alice@example.com for help.
91+
EOF
92+
93+
status=0
94+
"$check" --root "$tmp/pii" > "$tmp/out-pii" 2>&1 || status=$?
95+
[ "$status" -eq 1 ] || fail "pii fixture should exit 1, got $status: $(cat "$tmp/out-pii")"
96+
grep -q "\[high\] pii: contains an email address" "$tmp/out-pii" \
97+
|| fail "missing pii finding in: $(cat "$tmp/out-pii")"
98+
99+
# --- case 7: external URL は low (検知のみ、exit 0 で pass) ---
100+
mkdir -p "$tmp/url/shared/workflows"
101+
cat > "$tmp/url/shared/workflows/personal-url.md" <<'EOF'
102+
# workflow
103+
Reference: https://example.com/docs for background.
104+
EOF
105+
106+
"$check" --root "$tmp/url" > "$tmp/out-url" 2>&1 \
107+
|| fail "external-url fixture should pass (low only): $(cat "$tmp/out-url")"
108+
grep -q "\[low\] external-url: contains an external URL" "$tmp/out-url" \
109+
|| fail "missing external-url finding in: $(cat "$tmp/out-url")"
110+
grep -q "low-risk finding" "$tmp/out-url" \
111+
|| fail "missing low-risk summary in: $(cat "$tmp/out-url")"
112+
113+
# --- case 8: Windows の user-specific path も high (exit 1) ---
114+
mkdir -p "$tmp/winpath/shared/workflows"
115+
cat > "$tmp/winpath/shared/workflows/personal-winpath.md" <<'EOF'
116+
# workflow
117+
Open C:\Users\alice\AppData\Roaming\app for config.
118+
EOF
119+
120+
status=0
121+
"$check" --root "$tmp/winpath" > "$tmp/out-winpath" 2>&1 || status=$?
122+
[ "$status" -eq 1 ] || fail "windows path fixture should exit 1, got $status: $(cat "$tmp/out-winpath")"
123+
grep -q "\[high\] absolute-path: contains a user-specific absolute path" "$tmp/out-winpath" \
124+
|| fail "missing windows absolute-path finding in: $(cat "$tmp/out-winpath")"
125+
73126
echo "ok: check-injection self-test passed"

0 commit comments

Comments
 (0)