Skip to content

Commit f9fba71

Browse files
committed
python-peewee-mysql-hardcoded-secret-python
1 parent b287e03 commit f9fba71

3 files changed

+93
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
id: python-peewee-mysql-hardcoded-secret-python
2+
severity: warning
3+
language: python
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+
[REFERENCES]
13+
- https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
14+
15+
ast-grep-essentials: true
16+
17+
utils:
18+
$DB(..., password="...",...):
19+
# $DB(..., password="...",...)
20+
kind: call
21+
all:
22+
- has:
23+
stopBy: neighbor
24+
pattern: $DB
25+
regex: ^MySQLDatabase$|^peewee.MySQLDatabase$|^MySQLConnectorDatabase$|^playhouse.mysql_ext.MySQLConnectorDatabase$|^MariaDBConnectorDatabase$|^playhouse.mysql_ext.MariaDBConnectorDatabase$|^PooledMySQLDatabase$|^playhouse.pool.PooledMySQLDatabase$
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$|^passwd$
37+
- has:
38+
stopBy: neighbor
39+
kind: string
40+
has:
41+
stopBy: neighbor
42+
kind: string_content
43+
rule:
44+
kind: call
45+
matches: $DB(..., password="...",...)
46+
not:
47+
all:
48+
- has:
49+
stopBy: end
50+
kind: ERROR
51+
- inside:
52+
stopBy: end
53+
kind: ERROR
54+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
id: python-peewee-mysql-hardcoded-secret-python
2+
snapshots:
3+
'mysql_db1 = MySQLDatabase(''my_app'', user=''app'', password=''db_password'', host=''10.1.0.8'', port=3306) ':
4+
labels:
5+
- source: MySQLDatabase('my_app', user='app', password='db_password', host='10.1.0.8', port=3306)
6+
style: primary
7+
start: 12
8+
end: 99
9+
- source: MySQLDatabase
10+
style: secondary
11+
start: 12
12+
end: 25
13+
- source: password
14+
style: secondary
15+
start: 48
16+
end: 56
17+
- source: db_password
18+
style: secondary
19+
start: 58
20+
end: 69
21+
- source: '''db_password'''
22+
style: secondary
23+
start: 57
24+
end: 70
25+
- source: password='db_password'
26+
style: secondary
27+
start: 48
28+
end: 70
29+
- source: ('my_app', user='app', password='db_password', host='10.1.0.8', port=3306)
30+
style: secondary
31+
start: 25
32+
end: 99
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
id: python-peewee-mysql-hardcoded-secret-python
2+
valid:
3+
- |
4+
mysql_db1 = MySQLDatabe('my_app', user='app', password=os.env['password'], host='10.1.0.8', port=3306)
5+
invalid:
6+
- |
7+
mysql_db1 = MySQLDatabase('my_app', user='app', password='db_password', host='10.1.0.8', port=3306)

0 commit comments

Comments
 (0)