Skip to content

Add Security Rules for Hardcoding Secrets in Python Applications #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
441 changes: 441 additions & 0 deletions rules/python/security/python-pyjwt-hardcoded-secret-python.yml

Large diffs are not rendered by default.

168 changes: 168 additions & 0 deletions rules/python/security/python-redis-hardcoded-secret-python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
id: python-redis-hardcoded-secret-python
severity: warning
language: python
message: >-
A secret is hard-coded in the application. Secrets stored in source
code, such as credentials, identifiers, and other types of sensitive data,
can be leaked and used by internal or external malicious actors. Use
environment variables to securely provide credentials and other secrets or
retrieve them from a secure vault or Hardware Security Module (HSM).
note: >-
[CWE-798] Use of Hard-coded Credentials.
[REFERENCES]
- https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
utils:
redis.Redis(..., password="...",...):
kind: call
all:
- has:
stopBy: neighbor
kind: attribute
pattern: redis.Redis
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: end
kind: keyword_argument
all:
- has:
stopBy: neighbor
kind: identifier
regex: ^password$
- has:
stopBy: neighbor
kind: string
has:
stopBy: end
kind: string_content
redis.Redis(..., password="...",...)_with_instance:
kind: call
all:
- has:
stopBy: neighbor
kind: attribute
pattern: redis.Redis
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: end
kind: keyword_argument
all:
- has:
stopBy: neighbor
kind: identifier
regex: ^password$
- has:
stopBy: neighbor
kind: identifier
pattern: $P
- inside:
stopBy: end
kind: expression_statement
follows:
stopBy: end
kind: expression_statement
has:
stopBy: neighbor
kind: assignment
all:
- has:
stopBy: end
kind: identifier
paatern: $P
- has:
stopBy: neighbor
kind: string
has:
stopby: end
kind: string_content
Redis(..., password="...",...):
kind: call
all:
- has:
stopBy: neighbor
kind: identifier
pattern: Redis
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: end
kind: keyword_argument
all:
- has:
stopBy: neighbor
kind: identifier
regex: ^password$
- has:
stopBy: neighbor
kind: string
has:
stopBy: end
kind: string_content
- inside:
stopBy: end
kind: module
has:
stopBy: end
kind: import_from_statement
pattern: from redis import Redis
Redis(..., password="...",...)_with_instance:
kind: call
all:
- has:
stopBy: neighbor
kind: identifier
pattern: Redis
- has:
stopBy: neighbor
kind: argument_list
has:
stopBy: end
kind: keyword_argument
all:
- has:
stopBy: neighbor
kind: identifier
regex: ^password$
- has:
stopBy: neighbor
kind: identifier
pattern: $S
nthChild: 2
- inside:
stopBy: end
kind: expression_statement
follows:
stopBy: end
kind: expression_statement
has:
stopBy: neighbor
kind: assignment
all:
- has:
stopBy: end
kind: identifier
pattern: $S
- has:
stopBy: neighbor
kind: string
has:
stopby: end
kind: string_content
- inside:
stopBy: end
kind: module
has:
stopBy: end
kind: import_from_statement
pattern: from redis import Redis
rule:
kind: call
any:
- matches: redis.Redis(..., password="...",...)
- matches: redis.Redis(..., password="...",...)_with_instance
- matches: Redis(..., password="...",...)
- matches: Redis(..., password="...",...)_with_instance
Loading