Skip to content

Commit d292cd4

Browse files
committed
gorilla-cookie-store-hardcoded-session-key-go
1 parent 1162b6f commit d292cd4

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
id: gorilla-cookie-store-hardcoded-session-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: expression_list
18+
has:
19+
stopBy: neighbor
20+
kind: call_expression
21+
all:
22+
- has:
23+
stopBy: neighbor
24+
kind: selector_expression
25+
all:
26+
- has:
27+
stopBy: neighbor
28+
kind: identifier
29+
regex: "sessions"
30+
- has:
31+
stopBy: neighbor
32+
kind: field_identifier
33+
regex: "^NewCookieStore$"
34+
- has:
35+
stopBy: neighbor
36+
kind: argument_list
37+
any:
38+
- has:
39+
stopBy: neighbor
40+
kind: type_conversion_expression
41+
all:
42+
- has:
43+
stopBy: neighbor
44+
kind: slice_type
45+
has:
46+
stopBy: neighbor
47+
kind: type_identifier
48+
regex: "^byte$"
49+
- has:
50+
stopBy: neighbor
51+
pattern: $$$
52+
- not:
53+
has:
54+
stopBy: neighbor
55+
kind: call_expression
56+
- has:
57+
stopBy: neighbor
58+
kind: interpreted_string_literal
59+
60+
rule:
61+
kind: expression_list
62+
any:
63+
- matches: MATCH_PATTERN_ONE
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
id: gorilla-cookie-store-hardcoded-session-key-go
2+
snapshots:
3+
? "import (\n\"github.com/gorilla/sessions\"\n)\n \tvar store = sessions.NewCookieStore([]byte(\"hardcoded-session-key-here\"))\n var store = sessions.NewCookieStore(\n []byte(\"new-authentication-key\"),\n []byte(\"new-encryption-key\"),\n []byte(\"old-authentication-key\"),\n []byte(\"old-encryption-key\"),\n )\n"
4+
: labels:
5+
- source: sessions.NewCookieStore([]byte("hardcoded-session-key-here"))
6+
style: primary
7+
start: 55
8+
end: 116
9+
- source: sessions
10+
style: secondary
11+
start: 55
12+
end: 63
13+
- source: NewCookieStore
14+
style: secondary
15+
start: 64
16+
end: 78
17+
- source: sessions.NewCookieStore
18+
style: secondary
19+
start: 55
20+
end: 78
21+
- source: byte
22+
style: secondary
23+
start: 81
24+
end: 85
25+
- source: '[]byte'
26+
style: secondary
27+
start: 79
28+
end: 85
29+
- source: '[]byte'
30+
style: secondary
31+
start: 79
32+
end: 85
33+
- source: '[]byte("hardcoded-session-key-here")'
34+
style: secondary
35+
start: 79
36+
end: 115
37+
- source: ([]byte("hardcoded-session-key-here"))
38+
style: secondary
39+
start: 78
40+
end: 116
41+
- source: sessions.NewCookieStore([]byte("hardcoded-session-key-here"))
42+
style: secondary
43+
start: 55
44+
end: 116
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
id: gorilla-cookie-store-hardcoded-session-key-go
2+
valid:
3+
- |
4+
var store = sessions.NewCookieStore([]byte(os.Getenv("SESSION_KEY")))
5+
invalid:
6+
- |
7+
import (
8+
"github.com/gorilla/sessions"
9+
)
10+
var store = sessions.NewCookieStore([]byte("hardcoded-session-key-here"))
11+
var store = sessions.NewCookieStore(
12+
[]byte("new-authentication-key"),
13+
[]byte("new-encryption-key"),
14+
[]byte("old-authentication-key"),
15+
[]byte("old-encryption-key"),
16+
)

0 commit comments

Comments
 (0)