Skip to content

Commit 67968ee

Browse files
committed
fix
1 parent f185242 commit 67968ee

File tree

2 files changed

+75
-15
lines changed

2 files changed

+75
-15
lines changed

main.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -358,18 +358,16 @@ func scanFileForSecrets(path string, pipeline *verification.Pipeline) ([]Secret,
358358
// Update confidence based on LLM verification
359359
confidence = result.Confidence
360360

361-
// Only report if LLM confirms it's a real secret
362-
if result.IsRealSecret {
363-
secrets = append(secrets, Secret{
364-
File: fmt.Sprintf("%s (%s) [LLM: %s]", path, secretType, result.Reasoning),
365-
LineNumber: lineNumber,
366-
Line: line,
367-
Type: secretPatterns[index],
368-
Confidence: confidence,
369-
Entropy: entropy,
370-
Context: context,
371-
})
372-
}
361+
// LLM is advisory-only: attach reasoning but do not suppress regex hits.
362+
secrets = append(secrets, Secret{
363+
File: fmt.Sprintf("%s (%s) [LLM: %s]", path, secretType, result.Reasoning),
364+
LineNumber: lineNumber,
365+
Line: line,
366+
Type: secretPatterns[index],
367+
Confidence: confidence,
368+
Entropy: entropy,
369+
Context: context,
370+
})
373371
} else {
374372
// Fall back to non-LLM if verification fails
375373
if confidence != "low" {
@@ -415,8 +413,6 @@ func AdditionalSecretPatterns() []string {
415413
`(?i)(\b(?:or|and)\b\s*[\w-]*\s*=\s*[\w-]*\s*\b(?:or|and)\b\s*[^\s]+)`, // SQL injection
416414
`(?i)(['"\s]exec(?:ute)?\s*[(\s]*\s*@\w+\s*)`, // SQL injection (EXEC, EXECUTE)
417415
`(?i)(['"\s]union\s*all\s*select\s*[\w\s,]+(?:from|into|where)\s*\w+)`, // SQL injection (UNION ALL SELECT)
418-
`(?i)example_pattern_1\s*=\s*"([a-zA-Z0-9\-]+\.example)"`,
419-
`(?i)example_pattern_2\s*=\s*"([0-9]{12}-[a-zA-Z0-9_]{32})"`,
420416
// Private SSH keys
421417
`-----BEGIN\sRSA\sPRIVATE\sKEY-----[\s\S]+-----END\sRSA\sPRIVATE\sKEY-----`,
422418
// S3 Bucket URLs

main_test.go

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package main
22

3-
import "testing"
3+
import (
4+
"os"
5+
"path/filepath"
6+
"strings"
7+
"testing"
8+
)
49

510
func TestDetectContext(t *testing.T) {
611
cases := []struct {
@@ -29,3 +34,62 @@ func TestDetectContext(t *testing.T) {
2934
})
3035
}
3136
}
37+
38+
// Regression test: the demo file should have all fake secrets detected by the core scanner
39+
// without relying on the LLM pipeline.
40+
func TestDemoSecretsDetected(t *testing.T) {
41+
path := filepath.Join("examples", "demo_secrets", "demo_app.py")
42+
43+
secrets, err := scanFileForSecrets(path, nil)
44+
if err != nil {
45+
t.Fatalf("scanFileForSecrets error: %v", err)
46+
}
47+
48+
expected := []string{
49+
"AKIAIOSFODNN7EXAMPLE",
50+
"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
51+
"ghp_1234567890abcdef1234567890abcdef1234",
52+
"AIzaSyA1234567890abcdefGHIJKLMNOPQRSTUV123",
53+
"sk_live_51M8c7uExampleExampleExample0000",
54+
"xoxb-123456789012-1234567890123-ABCDEFGHIJKLMNOPQRSTUV",
55+
"-----BEGIN PRIVATE KEY-----",
56+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9",
57+
"P@ssw0rd123!",
58+
"password123",
59+
}
60+
61+
found := make(map[string]bool)
62+
for _, s := range secrets {
63+
for _, marker := range expected {
64+
if strings.Contains(s.Line, marker) {
65+
found[marker] = true
66+
}
67+
}
68+
}
69+
70+
for _, marker := range expected {
71+
if !found[marker] {
72+
t.Errorf("expected secret containing %q to be detected", marker)
73+
}
74+
}
75+
}
76+
77+
// Basic negative test: a plain text file with no obvious secrets should not produce findings.
78+
func TestNoFalsePositivesOnSafeFile(t *testing.T) {
79+
dir := t.TempDir()
80+
path := filepath.Join(dir, "safe.txt")
81+
content := "this file intentionally contains no secrets, just some example code and configuration values"
82+
83+
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
84+
t.Fatalf("WriteFile: %v", err)
85+
}
86+
87+
secrets, err := scanFileForSecrets(path, nil)
88+
if err != nil {
89+
t.Fatalf("scanFileForSecrets error: %v", err)
90+
}
91+
92+
if len(secrets) != 0 {
93+
t.Fatalf("expected no secrets, got %d", len(secrets))
94+
}
95+
}

0 commit comments

Comments
 (0)