-
Notifications
You must be signed in to change notification settings - Fork 6
Add security rules for detecting empty passwords in database connections #144
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
Merged
ganeshpatro321
merged 18 commits into
coderabbitai:main
from
ESS-ENN:python-mysql-mssql-empty-hardcoded-password
Jan 30, 2025
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
bb7b8e1
removed missing-secure-java
308e947
Merge branch 'coderabbitai:main' into main
ESS-ENN 46efd55
Merge branch 'coderabbitai:main' into main
ESS-ENN 3ac0204
Merge branch 'coderabbitai:main' into main
ESS-ENN 7caba92
Merge branch 'coderabbitai:main' into main
ESS-ENN d3a2776
Merge branch 'coderabbitai:main' into main
ESS-ENN 2e86380
Merge branch 'coderabbitai:main' into main
ESS-ENN b072db7
Merge branch 'coderabbitai:main' into main
ESS-ENN 65dce29
Merge branch 'coderabbitai:main' into main
ESS-ENN 12bb3aa
httponly-false-csharp
ESS-ENN 2c5ea88
use-of-md5-digest-utils-java
ESS-ENN d3067f1
removing use-of-md5-digest-utils and httponly-false-csharp
ESS-ENN 56d4011
Merge branch 'coderabbitai:main' into main
ESS-ENN f7f1d72
Merge branch 'coderabbitai:main' into main
ESS-ENN 23d7b53
python-pymysql-empty-password-python test file updated
ESS-ENN cd0e79b
python-pymysql-hardcoded-secret-python
ESS-ENN 8abb6a4
python-pymssql-empty-password-python
ESS-ENN 8d65c98
python-pymssql-hardcoded-secret-python
ESS-ENN 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
88 changes: 88 additions & 0 deletions
88
rules/python/security/python-pymssql-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,88 @@ | ||
id: python-pymssql-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 | ||
|
||
ast-grep-essentials: true | ||
|
||
utils: | ||
mssql.connect(..., password="",...): | ||
kind: call | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: attribute | ||
regex: ^pymssql.connect$|^pymssql._mssql.connect$ | ||
- has: | ||
stopBy: neighbor | ||
kind: argument_list | ||
has: | ||
stopBy: neighbor | ||
kind: keyword_argument | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: identifier | ||
regex: ^password$ | ||
- has: | ||
stopBy: neighbor | ||
kind: string | ||
not: | ||
has: | ||
stopBy: end | ||
kind: string_content | ||
# $mssql.connect(..., password="",...): | ||
# kind: call | ||
# all: | ||
# - has: | ||
# stopBy: neighbor | ||
# kind: attribute | ||
# regex: ^_mssql.connect$ | ||
# - has: | ||
# stopBy: neighbor | ||
# kind: argument_list | ||
# has: | ||
# stopBy: neighbor | ||
# kind: keyword_argument | ||
# all: | ||
# - has: | ||
# stopBy: neighbor | ||
# kind: identifier | ||
# regex: ^password$ | ||
# - has: | ||
# stopBy: neighbor | ||
# kind: string | ||
# not: | ||
# has: | ||
# stopBy: end | ||
# kind: string_content | ||
# - inside: | ||
# stopBy: end | ||
# follows: | ||
# stopBy: end | ||
# kind: import_from_statement | ||
# pattern: from pymssql import _mssql | ||
rule: | ||
kind: call | ||
any: | ||
- matches: mssql.connect(..., password="",...) | ||
# - matches: $mssql.connect(..., password="",...) | ||
not: | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: ERROR | ||
- inside: | ||
stopBy: end | ||
kind: ERROR | ||
85 changes: 85 additions & 0 deletions
85
rules/python/security/python-pymssql-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,85 @@ | ||
id: python-pymssql-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 credentials 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 | ||
|
||
ast-grep-essentials: true | ||
|
||
utils: | ||
mssql.connect(..., password="",...): | ||
kind: call | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: attribute | ||
regex: ^pymssql.connect$|^pymssql._mssql.connect$ | ||
- has: | ||
stopBy: neighbor | ||
kind: argument_list | ||
has: | ||
stopBy: neighbor | ||
kind: keyword_argument | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: identifier | ||
regex: ^password$ | ||
- has: | ||
stopBy: neighbor | ||
kind: string | ||
has: | ||
stopBy: end | ||
kind: string_content | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# $mssql.connect(..., password="",...): | ||
# kind: call | ||
# all: | ||
# - has: | ||
# stopBy: neighbor | ||
# kind: attribute | ||
# regex: ^_mssql.connect$ | ||
# - has: | ||
# stopBy: neighbor | ||
# kind: argument_list | ||
# has: | ||
# stopBy: neighbor | ||
# 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 | ||
# follows: | ||
# stopBy: end | ||
# kind: import_from_statement | ||
# pattern: from pymssql import _mssql | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rule: | ||
kind: call | ||
any: | ||
- matches: mssql.connect(..., password="",...) | ||
# - matches: $mssql.connect(..., password="",...) | ||
not: | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: ERROR | ||
- inside: | ||
stopBy: end | ||
kind: ERROR |
56 changes: 56 additions & 0 deletions
56
rules/python/security/python-pymysql-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,56 @@ | ||
id: python-pymysql-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 | ||
|
||
ast-grep-essentials: true | ||
|
||
utils: | ||
pymysql.connect(..., password="",...): | ||
kind: call | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: attribute | ||
regex: ^pymysql.connect$ | ||
- has: | ||
stopBy: neighbor | ||
kind: argument_list | ||
has: | ||
stopBy: neighbor | ||
kind: keyword_argument | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: identifier | ||
regex: ^password$ | ||
- has: | ||
stopBy: neighbor | ||
kind: string | ||
not: | ||
has: | ||
stopBy: end | ||
kind: string_content | ||
ESS-ENN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rule: | ||
kind: call | ||
matches: pymysql.connect(..., password="",...) | ||
not: | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: ERROR | ||
- inside: | ||
stopBy: end | ||
kind: ERROR | ||
|
54 changes: 54 additions & 0 deletions
54
rules/python/security/python-pymysql-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,54 @@ | ||
id: python-pymysql-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 credentials 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 | ||
|
||
ast-grep-essentials: true | ||
|
||
utils: | ||
pymysql.connect(..., password="",...): | ||
kind: call | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: attribute | ||
regex: ^pymysql.connect$ | ||
- has: | ||
stopBy: neighbor | ||
kind: argument_list | ||
has: | ||
stopBy: neighbor | ||
kind: keyword_argument | ||
all: | ||
- has: | ||
stopBy: neighbor | ||
kind: identifier | ||
regex: ^password$ | ||
- has: | ||
stopBy: neighbor | ||
kind: string | ||
has: | ||
stopBy: end | ||
kind: string_content | ||
rule: | ||
kind: call | ||
matches: pymysql.connect(..., password="",...) | ||
not: | ||
all: | ||
- has: | ||
stopBy: end | ||
kind: ERROR | ||
- inside: | ||
stopBy: end | ||
kind: ERROR | ||
|
84 changes: 84 additions & 0 deletions
84
tests/__snapshots__/python-pymssql-empty-password-python-snapshot.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,84 @@ | ||
id: python-pymssql-empty-password-python | ||
snapshots: | ||
? "conn1 = pymssql._mssql.connect(\n server='SQL01',\n user='user',\n password='',\n database='mydatabase',\n) \n" | ||
: labels: | ||
- source: |- | ||
pymssql._mssql.connect( | ||
server='SQL01', | ||
user='user', | ||
password='', | ||
database='mydatabase', | ||
) | ||
style: primary | ||
start: 8 | ||
end: 106 | ||
- source: pymssql._mssql.connect | ||
style: secondary | ||
start: 8 | ||
end: 30 | ||
- source: password | ||
style: secondary | ||
start: 67 | ||
end: 75 | ||
- source: '''''' | ||
style: secondary | ||
start: 76 | ||
end: 78 | ||
- source: password='' | ||
style: secondary | ||
start: 67 | ||
end: 78 | ||
- source: |- | ||
( | ||
server='SQL01', | ||
user='user', | ||
password='', | ||
database='mydatabase', | ||
) | ||
style: secondary | ||
start: 30 | ||
end: 106 | ||
? | | ||
conn1 = pymssql.connect( | ||
server='SQL01', | ||
user='user', | ||
password='', | ||
database='mydatabase', | ||
) | ||
: labels: | ||
- source: |- | ||
pymssql.connect( | ||
server='SQL01', | ||
user='user', | ||
password='', | ||
database='mydatabase', | ||
) | ||
style: primary | ||
start: 8 | ||
end: 99 | ||
- source: pymssql.connect | ||
style: secondary | ||
start: 8 | ||
end: 23 | ||
- source: password | ||
style: secondary | ||
start: 60 | ||
end: 68 | ||
- source: '''''' | ||
style: secondary | ||
start: 69 | ||
end: 71 | ||
- source: password='' | ||
style: secondary | ||
start: 60 | ||
end: 71 | ||
- source: |- | ||
( | ||
server='SQL01', | ||
user='user', | ||
password='', | ||
database='mydatabase', | ||
) | ||
style: secondary | ||
start: 23 | ||
end: 99 |
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.