Skip to content

Commit 56a53f1

Browse files
committed
python-webrepl-hardcoded-secret-python
1 parent bf80284 commit 56a53f1

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
id: python-webrepl-hardcoded-secret-python
2+
language: python
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. Use
8+
environment variables to securely provide credentials and other secrets or
9+
retrieve them from a secure vault or Hardware Security Module (HSM).
10+
note: >-
11+
[CWE-798]: Use of Hard-coded Credentials
12+
[OWASP A07:2021]: Identification and Authentication Failures
13+
[REFERENCES]
14+
https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
15+
16+
ast-grep-essentials: true
17+
18+
utils:
19+
webrepl.start(..., password="",...):
20+
kind: call
21+
all:
22+
- has:
23+
stopBy: neighbor
24+
kind: attribute
25+
regex: ^webrepl.start$
26+
- has:
27+
stopBy: neighbor
28+
kind: argument_list
29+
has:
30+
stopBy: neighbor
31+
kind: keyword_argument
32+
all:
33+
- has:
34+
stopBy: neighbor
35+
kind: identifier
36+
regex: ^password$
37+
- has:
38+
stopBy: neighbor
39+
kind: string
40+
has:
41+
stopBy: end
42+
kind: string_content
43+
rule:
44+
kind: call
45+
matches: webrepl.start(..., password="",...)
46+
not:
47+
all:
48+
- has:
49+
stopBy: end
50+
kind: ERROR
51+
- inside:
52+
stopBy: end
53+
kind: ERROR
54+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
id: python-webrepl-hardcoded-secret-python
2+
snapshots:
3+
? |
4+
webrepl.start(password="12345")
5+
: labels:
6+
- source: webrepl.start(password="12345")
7+
style: primary
8+
start: 0
9+
end: 31
10+
- source: webrepl.start
11+
style: secondary
12+
start: 0
13+
end: 13
14+
- source: password
15+
style: secondary
16+
start: 14
17+
end: 22
18+
- source: '12345'
19+
style: secondary
20+
start: 24
21+
end: 29
22+
- source: '"12345"'
23+
style: secondary
24+
start: 23
25+
end: 30
26+
- source: password="12345"
27+
style: secondary
28+
start: 14
29+
end: 30
30+
- source: (password="12345")
31+
style: secondary
32+
start: 13
33+
end: 31
34+
? |
35+
webrepl.start(password="mypassword")
36+
: labels:
37+
- source: webrepl.start(password="mypassword")
38+
style: primary
39+
start: 0
40+
end: 36
41+
- source: webrepl.start
42+
style: secondary
43+
start: 0
44+
end: 13
45+
- source: password
46+
style: secondary
47+
start: 14
48+
end: 22
49+
- source: mypassword
50+
style: secondary
51+
start: 24
52+
end: 34
53+
- source: '"mypassword"'
54+
style: secondary
55+
start: 23
56+
end: 35
57+
- source: password="mypassword"
58+
style: secondary
59+
start: 14
60+
end: 35
61+
- source: (password="mypassword")
62+
style: secondary
63+
start: 13
64+
end: 36
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
id: python-webrepl-hardcoded-secret-python
2+
valid:
3+
- |
4+
webrepl.start(password=os.getenv('PASSWORD'))
5+
invalid:
6+
- |
7+
webrepl.start(password="mypassword")
8+
- |
9+
webrepl.start(password="12345")

0 commit comments

Comments
 (0)