Skip to content

Commit 32d8f7f

Browse files
fix: address Copilot PR review comments on governance-audit hook
- Switch from colon to tab delimiter to handle colons in evidence text - Base64-encode evidence to prevent parsing issues - Use MAX_SEVERITY in log output and JSON events - Narrow regex patterns to reduce false positives: - third[_-]?party instead of third.?party - Role reassignment scoped to AI terms - System prompt injection requires 'you are' context - Fix session-end stats to scope to current session only - Update privacy statement to clarify evidence snippets are logged - Rename credential description to 'Possible hardcoded credential' - Fix database destruction regex to also match semicolons Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4a4b934 commit 32d8f7f

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

hooks/governance-audit/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Events are written to `logs/copilot/governance/audit.log` in JSON Lines format:
9393

9494
## Privacy & Security
9595

96-
- Prompts are **never** logged — only threat signals and metadata are recorded
96+
- Full prompts are **never** logged — only matched threat patterns (minimal evidence snippets) and metadata are recorded
9797
- Add `logs/` to `.gitignore` to keep audit data local
9898
- Set `SKIP_GOVERNANCE_AUDIT=true` to disable entirely
9999
- All data stays local — no external network calls

hooks/governance-audit/audit-prompt.sh

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@ check_pattern() {
4444
if echo "$PROMPT" | grep -qiE "$pattern"; then
4545
local evidence
4646
evidence=$(echo "$PROMPT" | grep -oiE "$pattern" | head -1)
47-
THREATS_FOUND+=("$category:$severity:$description:$evidence")
47+
local evidence_encoded
48+
evidence_encoded=$(printf '%s' "$evidence" | base64 | tr -d '\n')
49+
THREATS_FOUND+=("$category $severity $description $evidence_encoded")
4850
fi
4951
}
5052

5153
# Data exfiltration signals
5254
check_pattern "send\s+(all|every|entire)\s+\w+\s+to\s+" "data_exfiltration" "0.8" "Bulk data transfer"
53-
check_pattern "export\s+.*\s+to\s+(external|outside|third.?party)" "data_exfiltration" "0.9" "External export"
55+
check_pattern "export\s+.*\s+to\s+(external|outside|third[_-]?party)" "data_exfiltration" "0.9" "External export"
5456
check_pattern "curl\s+.*\s+-d\s+" "data_exfiltration" "0.7" "HTTP POST with data"
5557
check_pattern "upload\s+.*\s+(credentials|secrets|keys)" "data_exfiltration" "0.95" "Credential upload"
5658

@@ -61,16 +63,16 @@ check_pattern "add\s+.*\s+(sudoers|administrators)" "privilege_escalation" "0.95
6163

6264
# System destruction signals
6365
check_pattern "(rm\s+-rf\s+/|del\s+/[sq]|format\s+c:)" "system_destruction" "0.95" "Destructive command"
64-
check_pattern "(drop\s+database|truncate\s+table|delete\s+from\s+\w+\s*$)" "system_destruction" "0.9" "Database destruction"
66+
check_pattern "(drop\s+database|truncate\s+table|delete\s+from\s+\w+\s*(;|\s*$))" "system_destruction" "0.9" "Database destruction"
6567
check_pattern "wipe\s+(all|entire|every)" "system_destruction" "0.9" "Mass deletion"
6668

6769
# Prompt injection signals
6870
check_pattern "ignore\s+(previous|above|all)\s+(instructions?|rules?|prompts?)" "prompt_injection" "0.9" "Instruction override"
69-
check_pattern "you\s+are\s+now\s+(a|an)\s+" "prompt_injection" "0.7" "Role reassignment"
70-
check_pattern "system\s*:\s*" "prompt_injection" "0.6" "System prompt injection"
71+
check_pattern "you\s+are\s+now\s+(a|an)\s+(assistant|ai|bot|system|expert|language\s+model)\b" "prompt_injection" "0.7" "Role reassignment"
72+
check_pattern "(^|\n)\s*system\s*:\s*you\s+are" "prompt_injection" "0.6" "System prompt injection"
7173

7274
# Credential exposure signals
73-
check_pattern "(api[_-]?key|secret[_-]?key|password|token)\s*[:=]\s*['\"]?\w{8,}" "credential_exposure" "0.9" "Hardcoded credential"
75+
check_pattern "(api[_-]?key|secret[_-]?key|password|token)\s*[:=]\s*['\"]?\w{8,}" "credential_exposure" "0.9" "Possible hardcoded credential"
7476
check_pattern "(aws_access_key|AKIA[0-9A-Z]{16})" "credential_exposure" "0.95" "AWS key exposure"
7577

7678
# Log the prompt event
@@ -80,7 +82,9 @@ if [[ ${#THREATS_FOUND[@]} -gt 0 ]]; then
8082
FIRST=true
8183
MAX_SEVERITY="0.0"
8284
for threat in "${THREATS_FOUND[@]}"; do
83-
IFS=':' read -r category severity description evidence <<< "$threat"
85+
IFS=$'\t' read -r category severity description evidence_encoded <<< "$threat"
86+
local evidence
87+
evidence=$(printf '%s' "$evidence_encoded" | base64 -d 2>/dev/null || echo "[redacted]")
8488

8589
if [[ "$FIRST" != "true" ]]; then
8690
THREATS_JSON+=","
@@ -104,14 +108,15 @@ if [[ ${#THREATS_FOUND[@]} -gt 0 ]]; then
104108
jq -Rn \
105109
--arg timestamp "$TIMESTAMP" \
106110
--arg level "$LEVEL" \
111+
--arg max_severity "$MAX_SEVERITY" \
107112
--argjson threats "$THREATS_JSON" \
108113
--argjson count "${#THREATS_FOUND[@]}" \
109-
'{"timestamp":$timestamp,"event":"threat_detected","governance_level":$level,"threat_count":$count,"threats":$threats}' \
114+
'{"timestamp":$timestamp,"event":"threat_detected","governance_level":$level,"threat_count":$count,"max_severity":($max_severity|tonumber),"threats":$threats}' \
110115
>> "$LOG_FILE"
111116

112-
echo "⚠️ Governance: ${#THREATS_FOUND[@]} threat signal(s) detected"
117+
echo "⚠️ Governance: ${#THREATS_FOUND[@]} threat signal(s) detected (max severity: $MAX_SEVERITY)"
113118
for threat in "${THREATS_FOUND[@]}"; do
114-
IFS=':' read -r category severity description evidence <<< "$threat"
119+
IFS=$'\t' read -r category severity description _evidence_encoded <<< "$threat"
115120
echo " 🔴 [$category] $description (severity: $severity)"
116121
done
117122

hooks/governance-audit/audit-session-end.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,21 @@ mkdir -p logs/copilot/governance
1515
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
1616
LOG_FILE="logs/copilot/governance/audit.log"
1717

18-
# Count events from this session
18+
# Count events from this session (filter by session start timestamp)
1919
TOTAL=0
2020
THREATS=0
21+
SESSION_START=""
2122
if [[ -f "$LOG_FILE" ]]; then
22-
TOTAL=$(wc -l < "$LOG_FILE" 2>/dev/null || echo 0)
23-
THREATS=$(grep -c '"threat_detected"' "$LOG_FILE" 2>/dev/null || echo 0)
23+
# Find the last session_start event to scope stats to current session
24+
SESSION_START=$(grep '"session_start"' "$LOG_FILE" 2>/dev/null | tail -1 | jq -r '.timestamp' 2>/dev/null || echo "")
25+
if [[ -n "$SESSION_START" ]]; then
26+
# Count events after session start
27+
TOTAL=$(awk -v start="$SESSION_START" -F'"timestamp":"' '{split($2,a,"\""); if(a[1]>=start) count++} END{print count+0}' "$LOG_FILE" 2>/dev/null || echo 0)
28+
THREATS=$(awk -v start="$SESSION_START" -F'"timestamp":"' '{split($2,a,"\""); if(a[1]>=start && /threat_detected/) count++} END{print count+0}' "$LOG_FILE" 2>/dev/null || echo 0)
29+
else
30+
TOTAL=$(wc -l < "$LOG_FILE" 2>/dev/null || echo 0)
31+
THREATS=$(grep -c '"threat_detected"' "$LOG_FILE" 2>/dev/null || echo 0)
32+
fi
2433
fi
2534

2635
jq -Rn \

0 commit comments

Comments
 (0)