Skip to content

Commit 1162b6f

Browse files
committed
gorilla-csrf-hardcoded-auth-key-go
1 parent 55859ed commit 1162b6f

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
id: gorilla-csrf-hardcoded-auth-key-go
2+
language: go
3+
severity: warning
4+
message: >-
5+
A secret is hard-coded in the application. Secrets stored in source
6+
code, such as credentials, identifiers, and other types of sensitive data,
7+
can be leaked and used by internal or external malicious actors. It is
8+
recommended to rotate the secret and retrieve them from a secure secret
9+
vault or Hardware Security Module (HSM), alternatively environment
10+
variables can be used if allowed by your company policy.
11+
note: >-
12+
[CWE-798] Use of Hard-coded Credentials.
13+
[REFERENCES]
14+
- https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures
15+
utils:
16+
MATCH_PATTERN_ONE:
17+
kind: call_expression
18+
all:
19+
- has:
20+
stopBy: neighbor
21+
kind: selector_expression
22+
all:
23+
- has:
24+
stopBy: neighbor
25+
kind: identifier
26+
regex: "^csrf$"
27+
- has:
28+
stopBy: neighbor
29+
kind: field_identifier
30+
regex: "^Protect$"
31+
- has:
32+
stopBy: neighbor
33+
kind: argument_list
34+
any:
35+
- has:
36+
stopBy: neighbor
37+
kind: type_conversion_expression
38+
all:
39+
- has:
40+
stopBy: neighbor
41+
kind: slice_type
42+
has:
43+
stopBy: neighbor
44+
kind: type_identifier
45+
regex: "^byte$"
46+
- has:
47+
stopBy: neighbor
48+
kind: interpreted_string_literal
49+
- has:
50+
stopBy: neighbor
51+
kind: interpreted_string_literal
52+
- inside:
53+
stopBy: end
54+
kind: function_declaration
55+
follows:
56+
stopBy: end
57+
kind: import_declaration
58+
has:
59+
stopBy: end
60+
kind: import_spec
61+
regex: "github.com/gorilla/csrf"
62+
rule:
63+
kind: call_expression
64+
any:
65+
- matches: MATCH_PATTERN_ONE
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
id: gorilla-csrf-hardcoded-auth-key-go
2+
snapshots:
3+
? |
4+
import (
5+
"github.com/gorilla/csrf"
6+
)
7+
func main() {
8+
http.ListenAndServe(":8000",
9+
csrf.Protect([]byte("32-byte-long-auth-key"))(r))
10+
}
11+
: labels:
12+
- source: csrf.Protect([]byte("32-byte-long-auth-key"))
13+
style: primary
14+
start: 84
15+
end: 129
16+
- source: csrf
17+
style: secondary
18+
start: 84
19+
end: 88
20+
- source: Protect
21+
style: secondary
22+
start: 89
23+
end: 96
24+
- source: csrf.Protect
25+
style: secondary
26+
start: 84
27+
end: 96
28+
- source: byte
29+
style: secondary
30+
start: 99
31+
end: 103
32+
- source: '[]byte'
33+
style: secondary
34+
start: 97
35+
end: 103
36+
- source: '"32-byte-long-auth-key"'
37+
style: secondary
38+
start: 104
39+
end: 127
40+
- source: '[]byte("32-byte-long-auth-key")'
41+
style: secondary
42+
start: 97
43+
end: 128
44+
- source: ([]byte("32-byte-long-auth-key"))
45+
style: secondary
46+
start: 96
47+
end: 129
48+
- source: '"github.com/gorilla/csrf"'
49+
style: secondary
50+
start: 9
51+
end: 34
52+
- source: |-
53+
import (
54+
"github.com/gorilla/csrf"
55+
)
56+
style: secondary
57+
start: 0
58+
end: 36
59+
- source: |-
60+
func main() {
61+
http.ListenAndServe(":8000",
62+
csrf.Protect([]byte("32-byte-long-auth-key"))(r))
63+
}
64+
style: secondary
65+
start: 37
66+
end: 138
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
id: gorilla-csrf-hardcoded-auth-key-go
2+
valid:
3+
- |
4+
import (
5+
"github.com/gorilla/csrf"
6+
)
7+
func main() {
8+
http.ListenAndServe(":8000",
9+
csrf.Protect([]byte(os.Getenv("CSRF_AUTH_KEY")))(r))
10+
}
11+
invalid:
12+
- |
13+
import (
14+
"github.com/gorilla/csrf"
15+
)
16+
func main() {
17+
http.ListenAndServe(":8000",
18+
csrf.Protect([]byte("32-byte-long-auth-key"))(r))
19+
}

0 commit comments

Comments
 (0)