|
| 1 | +/* |
| 2 | +·━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━· |
| 3 | +: : |
| 4 | +: █▀ █ █▀▀ · Blazing-fast pentesting suite : |
| 5 | +: ▄█ █ █▀ · BSD 3-Clause License : |
| 6 | +: : |
| 7 | +: (c) 2022-2026 vmfunc, xyzeva, : |
| 8 | +: lunchcat alumni & contributors : |
| 9 | +: : |
| 10 | +·━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━· |
| 11 | +*/ |
| 12 | + |
| 13 | +package js |
| 14 | + |
| 15 | +import ( |
| 16 | + "strings" |
| 17 | + "testing" |
| 18 | +) |
| 19 | + |
| 20 | +func FuzzScanSecrets(f *testing.F) { |
| 21 | + f.Add(`const key = "AKIAIOSFODNN7EXAMPLE"`, "https://example.com/app.js") |
| 22 | + f.Add(`apikey: "sk-1234567890abcdefghij"`, "") |
| 23 | + f.Add("ghp_0123456789abcdefghijklmnopqrstuvwxyz01", "src") |
| 24 | + f.Add("-----BEGIN RSA PRIVATE KEY-----", "") |
| 25 | + f.Add(`var token = ""`, "") |
| 26 | + f.Add("", "") |
| 27 | + f.Add("aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", "js") |
| 28 | + |
| 29 | + f.Fuzz(func(t *testing.T, content, srcURL string) { |
| 30 | + for _, m := range ScanSecrets(content, srcURL) { |
| 31 | + // a reported match must be a non-empty run lifted verbatim from the |
| 32 | + // input; anything else means the capture-group indexing is off |
| 33 | + if m.Match == "" { |
| 34 | + t.Fatalf("empty Match for rule %q", m.Rule) |
| 35 | + } |
| 36 | + if !strings.Contains(content, m.Match) { |
| 37 | + t.Fatalf("Match %q (rule %q) not found in input", m.Match, m.Rule) |
| 38 | + } |
| 39 | + } |
| 40 | + }) |
| 41 | +} |
0 commit comments