-
Notifications
You must be signed in to change notification settings - Fork 6
Add security rules for tormysql and webrepl libraries in Python applications #112
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
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6090ccf
python-tormysql-empty-password-python
4371f5c
python-tormysql-hardcoded-secret-python
228f507
python-webrepl-empty-password-python
89d4332
modified code of python-tormysql-empty-password-python
df27814
modified code of python-tormysql-hardcoded-secret-python
bb3a320
modified code of python-webrepl-empty-password-python
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
206 changes: 206 additions & 0 deletions
206
rules/python/security/python-tormysql-empty-password-python.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
id: python-tormysql-empty-password-python | ||
language: python | ||
severity: warning | ||
message: >- | ||
The application creates a database connection with an empty password. | ||
This can lead to unauthorized access by either an internal or external | ||
malicious actor. To prevent this vulnerability, enforce authentication | ||
when connecting to a database by using environment variables to securely | ||
provide credentials or retrieving them from a secure vault or HSM | ||
(Hardware Security Module). | ||
note: >- | ||
[CWE-287]: Improper Authentication | ||
[OWASP A07:2021]: Identification and Authentication Failures | ||
[REFERENCES] | ||
https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html | ||
utils: | ||
match_expression_statement: | ||
kind: expression_statement | ||
has: | ||
stopBy: end | ||
kind: call | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: attribute | ||
field: function | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
field: object | ||
regex: "^tormysql$" | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
field: attribute | ||
regex: "^ConnectionPool$" | ||
- has: | ||
stopBy: end | ||
kind: argument_list | ||
field: arguments | ||
has: | ||
stopBy: end | ||
kind: keyword_argument | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
field: name | ||
regex: "^password$" | ||
- has: | ||
kind: string | ||
field: value | ||
all: | ||
- has: | ||
kind: string_start | ||
not: | ||
precedes: | ||
stopBy: end | ||
kind: string_content | ||
- has: | ||
kind: string_end | ||
|
||
match_expression_statement_with_identifier: | ||
kind: expression_statement | ||
has: | ||
stopBy: end | ||
kind: call | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: attribute | ||
field: function | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
field: object | ||
regex: "^tormysql$" | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
field: attribute | ||
regex: "^ConnectionPool$" | ||
- has: | ||
stopBy: end | ||
kind: argument_list | ||
field: arguments | ||
has: | ||
stopBy: end | ||
kind: keyword_argument | ||
all: | ||
- has: | ||
kind: identifier | ||
field: name | ||
regex: "^password$" | ||
- has: | ||
kind: identifier | ||
field: value | ||
pattern: $PASS | ||
follows: | ||
stopBy: end | ||
kind: expression_statement | ||
has: | ||
stopBy: end | ||
kind: assignment | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
pattern: $PASS | ||
- has: | ||
stopBy: end | ||
kind: string | ||
match_direct_expression_with_passwd: | ||
kind: call | ||
all: | ||
- has: | ||
kind: attribute | ||
field: function | ||
all: | ||
- has: | ||
kind: identifier | ||
field: object | ||
regex: "^tormysql$" | ||
- has: | ||
kind: identifier | ||
field: attribute | ||
regex: "^ConnectionPool$" | ||
- has: | ||
kind: argument_list | ||
field: arguments | ||
has: | ||
kind: keyword_argument | ||
all: | ||
- has: | ||
kind: identifier | ||
field: name | ||
regex: ^(passwd|password)$ | ||
- has: | ||
kind: string | ||
field: value | ||
all: | ||
- has: | ||
kind: string_start | ||
- has: | ||
kind: string_end | ||
inside: | ||
stopBy: end | ||
kind: return_statement | ||
inside: | ||
stopBy: end | ||
kind: function_definition | ||
has: | ||
kind: identifier | ||
field: name | ||
match_direct_expression_with_passwd_without_return: | ||
kind: call | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: attribute | ||
field: function | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
field: object | ||
regex: "^tormysql$" | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
field: attribute | ||
regex: "^ConnectionPool$" | ||
- has: | ||
stopBy: end | ||
kind: argument_list | ||
field: arguments | ||
has: | ||
stopBy: end | ||
kind: keyword_argument | ||
all: | ||
- has: | ||
kind: identifier | ||
field: name | ||
regex: ^(passwd)$ | ||
- has: | ||
kind: string | ||
all: | ||
- has: | ||
kind: string_start | ||
- has: | ||
kind: string_end | ||
inside: | ||
stopBy: end | ||
kind: assignment | ||
inside: | ||
stopBy: end | ||
kind: expression_statement | ||
|
||
rule: | ||
any: | ||
- matches: match_expression_statement | ||
- matches: match_expression_statement_with_identifier | ||
- matches: match_direct_expression_with_passwd | ||
- matches: match_direct_expression_with_passwd_without_return | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
159 changes: 159 additions & 0 deletions
159
rules/python/security/python-tormysql-hardcoded-secret-python.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
id: python-tormysql-hardcoded-secret-python | ||
language: python | ||
severity: warning | ||
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 crede ntials and other secrets or | ||
retrieve them from a secure vault or Hardware Security Module (HSM). | ||
note: >- | ||
[CWE-798]: Use of Hard-coded Credentials | ||
[OWASP A07:2021]: Identification and Authentication Failures | ||
[REFERENCES] | ||
https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html | ||
utils: | ||
match_expression_statement: | ||
kind: expression_statement | ||
has: | ||
stopBy: end | ||
kind: call | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: attribute | ||
field: function | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
field: object | ||
regex: "^tormysql$" | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
field: attribute | ||
regex: "^ConnectionPool$" | ||
- has: | ||
stopBy: end | ||
kind: argument_list | ||
field: arguments | ||
has: | ||
stopBy: end | ||
kind: keyword_argument | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
field: name | ||
regex: ^(password|passwd)$ | ||
- has: | ||
kind: string | ||
all: | ||
- has: | ||
kind: string_start | ||
- has: | ||
kind: string_content | ||
- has: | ||
kind: string_end | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
match_expression_statement_with_identifier: | ||
kind: expression_statement | ||
has: | ||
stopBy: end | ||
kind: call | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: attribute | ||
field: function | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
field: object | ||
regex: "^tormysql$" | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
field: attribute | ||
regex: "^ConnectionPool$" | ||
- has: | ||
stopBy: end | ||
kind: argument_list | ||
field: arguments | ||
has: | ||
stopBy: end | ||
kind: keyword_argument | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
field: name | ||
regex: "^password$" | ||
- has: | ||
stopBy: end | ||
kind: identifier | ||
field: value | ||
pattern: $PASS | ||
follows: | ||
stopBy: end | ||
kind: expression_statement | ||
has: | ||
stopBy: end | ||
kind: assignment | ||
all: | ||
- has: | ||
kind: identifier | ||
pattern: $PASS | ||
- has: | ||
kind: string | ||
all: | ||
- has: | ||
kind: string_start | ||
- has: | ||
kind: string_content | ||
- has: | ||
kind: string_end | ||
match_call_with_return: | ||
kind: call | ||
all: | ||
- has: | ||
kind: attribute | ||
field: function | ||
all: | ||
- has: | ||
kind: identifier | ||
field: object | ||
regex: "^tormysql$" | ||
- has: | ||
kind: identifier | ||
field: attribute | ||
regex: "^ConnectionPool$" | ||
- has: | ||
kind: argument_list | ||
field: arguments | ||
has: | ||
kind: keyword_argument | ||
all: | ||
- has: | ||
kind: identifier | ||
field: name | ||
regex: "^password$" | ||
- has: | ||
kind: string | ||
field: value | ||
all: | ||
- has: | ||
kind: string_start | ||
- has: | ||
kind: string_content | ||
- has: | ||
kind: string_end | ||
inside: | ||
stopBy: end | ||
kind: return_statement | ||
rule: | ||
any: | ||
- matches: match_expression_statement | ||
- matches: match_expression_statement_with_identifier | ||
- matches: match_call_with_return |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.