-
Notifications
You must be signed in to change notification settings - Fork 95
/
secret-gcp.go
83 lines (67 loc) · 1.54 KB
/
secret-gcp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package jsluice
import (
"regexp"
"strings"
)
func gcpKeyMatcher() SecretMatcher {
gcpKey := regexp.MustCompile("^AIza[a-zA-Z0-9+_-]+$")
return SecretMatcher{"(string) @matches", func(n *Node) *Secret {
str := n.RawString()
// Prefix check is nice and fast so we'll do that first
// Remember that there are a *lot* of strings in JS files :D
if !strings.HasPrefix(str, "AIza") {
return nil
}
if !gcpKey.MatchString(str) {
return nil
}
data := map[string]string{
"key": str,
}
match := &Secret{
Kind: "gcpKey",
Severity: SeverityLow,
Data: data,
}
// If the key is in an object we want to include that whole object as context
parent := n.Parent()
if parent == nil || parent.Type() != "pair" {
return match
}
grandparent := parent.Parent()
if grandparent == nil || grandparent.Type() != "object" {
return match
}
match.Context = grandparent.AsObject().AsMap()
return match
}}
}
func firebaseMatcher() SecretMatcher {
// Firebase objects
return SecretMatcher{"(object) @matches", func(n *Node) *Secret {
o := n.AsObject()
mustHave := map[string]bool{
"apiKey": true,
"authDomain": true,
"projectId": true,
"storageBucket": true,
}
count := 0
for _, k := range o.GetKeys() {
if mustHave[k] {
count++
}
}
if count != len(mustHave) {
return nil
}
if !strings.HasPrefix(o.GetStringI("apiKey", ""), "AIza") {
return nil
}
return &Secret{
Kind: "firebase",
Severity: SeverityHigh,
Data: o.AsMap(),
}
}}
}