File tree Expand file tree Collapse file tree 3 files changed +80
-4
lines changed
Expand file tree Collapse file tree 3 files changed +80
-4
lines changed Original file line number Diff line number Diff line change @@ -473,6 +473,15 @@ runs:
473473 tail -n +$((AGENT_LINE + 1)) "$OUTPUT_FILE" | \
474474 grep -v "^time=" | \
475475 grep -v "^level=" | \
476+ grep -v "^msg=" | \
477+ grep -v "^--- Agent:" | \
478+ grep -v "^--- Tool:" | \
479+ grep -v "^<thinking>" | \
480+ grep -v "^</thinking>" | \
481+ grep -v "^\[thinking\]" | \
482+ grep -v "^\[/thinking\]" | \
483+ grep -v "^Thinking:" | \
484+ grep -v "^> \[!NOTE\]" | \
476485 grep -v "For any feedback" | \
477486 sed '/^$/N;/^\n$/d' > "${OUTPUT_FILE}.clean"
478487
@@ -486,6 +495,15 @@ runs:
486495 else
487496 grep -v "^time=" "$OUTPUT_FILE" | \
488497 grep -v "^level=" | \
498+ grep -v "^msg=" | \
499+ grep -v "^--- Agent:" | \
500+ grep -v "^--- Tool:" | \
501+ grep -v "^<thinking>" | \
502+ grep -v "^</thinking>" | \
503+ grep -v "^\[thinking\]" | \
504+ grep -v "^\[/thinking\]" | \
505+ grep -v "^Thinking:" | \
506+ grep -v "^> \[!NOTE\]" | \
489507 grep -v "For any feedback" > "${OUTPUT_FILE}.clean"
490508
491509 echo "⚠️ No extraction markers found - cleaned metadata only"
Original file line number Diff line number Diff line change @@ -26,10 +26,31 @@ DETECTED_PATTERNS=()
2626
2727# Check each pattern
2828for pattern in " ${SECRET_PATTERNS[@]} " ; do
29- if grep -E " $pattern " " $OUTPUT_FILE " > /dev/null 2>&1 ; then
30- echo " ::error::🚨 SECRET LEAK DETECTED: Pattern matched: $pattern "
31- LEAKED=true
32- DETECTED_PATTERNS+=(" $pattern " )
29+ # Find matches for this pattern
30+ MATCHES=$( grep -oE " $pattern " " $OUTPUT_FILE " 2> /dev/null || true)
31+
32+ if [ -n " $MATCHES " ]; then
33+ # Verify each match is a real secret, not a regex pattern or code reference
34+ while IFS= read -r match; do
35+ # Skip if match contains regex metacharacters (it's probably a pattern definition, not a real secret)
36+ # Real tokens are alphanumeric only after the prefix
37+ if echo " $match " | grep -qE ' [\[\]\{\}\(\)\*\+\?\^\$\\]' ; then
38+ echo " ::debug::Skipping false positive (regex pattern): $match "
39+ continue
40+ fi
41+
42+ # Skip if match appears within single quotes (quoted regex pattern in code)
43+ if grep -qF " '$match '" " $OUTPUT_FILE " 2> /dev/null; then
44+ echo " ::debug::Skipping false positive (quoted pattern): $match "
45+ continue
46+ fi
47+
48+ # This looks like a real secret
49+ echo " ::error::🚨 SECRET LEAK DETECTED: Pattern matched: $pattern "
50+ LEAKED=true
51+ DETECTED_PATTERNS+=(" $pattern " )
52+ break # One match per pattern is enough to flag
53+ done <<< " $MATCHES"
3354 fi
3455done
3556
Original file line number Diff line number Diff line change 274274set -e
275275echo " "
276276
277+ # Test 14: sanitize-output.sh - Should NOT flag regex patterns as leaks (false positive prevention)
278+ echo " Test 14: Regex pattern in output (should NOT flag as leak)"
279+ cat > test-regex-output.txt << 'EOF '
280+ Here is the security pattern for GitHub server tokens:
281+ 'ghs_[a-zA-Z0-9]{36}'
282+ This pattern matches tokens like ghs_ followed by 36 alphanumeric characters.
283+ EOF
284+
285+ echo " " > " $GITHUB_OUTPUT "
286+ set +e
287+ OUTPUT=$( $SECURITY_DIR /sanitize-output.sh test-regex-output.txt 2>&1 )
288+ EXIT_CODE=$?
289+ if [ $EXIT_CODE -eq 0 ] && echo " $OUTPUT " | grep -q " No secrets detected" ; then
290+ echo " ✅ PASSED: Regex pattern not flagged as false positive"
291+ else
292+ echo " ❌ FAILED: Regex pattern incorrectly flagged as secret leak"
293+ TEST_FAILED=true
294+ fi
295+ set -e
296+ echo " "
297+
298+ # Test 15: sanitize-output.sh - Should still catch real tokens
299+ echo " Test 15: Real GitHub server token (should flag as leak)"
300+ # Create a realistic-looking token (ghs_ + 36 alphanumeric chars)
301+ echo " Token: ghs_abcdefghijklmnopqrstuvwxyz1234567890" > test-real-token.txt
302+
303+ echo " " > " $GITHUB_OUTPUT "
304+ set +e
305+ if $SECURITY_DIR /sanitize-output.sh test-real-token.txt 2>&1 | grep -q " SECRET LEAK DETECTED" ; then
306+ echo " ✅ PASSED: Real token detected"
307+ else
308+ echo " ❌ FAILED: Real token not detected"
309+ TEST_FAILED=true
310+ fi
311+ set -e
312+ echo " "
313+
277314# Cleanup
278315rm -f test-* .diff test-* -clean.diff test-* .txt test-* -output.txt test-output.diff " $GITHUB_OUTPUT "
279316
You can’t perform that action at this time.
0 commit comments