-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(python): add cwe-326 inadequate encryption strength rules
- Loading branch information
Showing
6 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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,38 @@ | ||
patterns: | ||
- pattern: $<NAME> = $<KEY> | ||
filters: | ||
- variable: NAME | ||
values: | ||
- SECRET_KEY | ||
- CRYPTOGRAPHY_KEY | ||
- variable: KEY | ||
length_less_than: 12 | ||
languages: | ||
- python | ||
metadata: | ||
description: Usage of weak secret key | ||
remediation_message: |- | ||
## Description | ||
Weak secret keys can compromise data security. To ensure effective encryption, secret keys should be 12 bytes or greater. | ||
## Remediations | ||
- **Do not** use secret keys shorter than 12 bytes. Short keys are easier to crack, putting your data at risk. | ||
```python | ||
SECRET_KEY = "weak" # unsafe | ||
``` | ||
- **Do** ensure your secret keys are 12 bytes or longer to maintain strong encryption and protect sensitive data. | ||
```python | ||
SECRET_KEY = "correct-horse-battery-staple" | ||
``` | ||
## References | ||
- [Django secret key setting and recommended best practice](https://docs.djangoproject.com/en/5.0/ref/settings/#std:setting-SECRET_KEY) | ||
- [django-cryptography documentation](https://django-cryptography.readthedocs.io/en/latest/) | ||
cwe_id: | ||
- 326 | ||
id: python_django_weak_secret_key | ||
documentation_url: https://docs.bearer.com/reference/rules/python_django_weak_secret_key | ||
severity: high |
This file contains 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
This file contains 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
This file contains 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
This file contains 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,20 @@ | ||
const { | ||
createNewInvoker, | ||
getEnvironment, | ||
} = require("../../../helper.js") | ||
const { ruleId, ruleFile, testBase } = getEnvironment(__dirname) | ||
|
||
describe(ruleId, () => { | ||
const invoke = createNewInvoker(ruleId, ruleFile, testBase) | ||
|
||
test("weak_secret_key", () => { | ||
const testCase = "main.py" | ||
|
||
const results = invoke(testCase) | ||
|
||
expect(results).toEqual({ | ||
Missing: [], | ||
Extra: [] | ||
}) | ||
}) | ||
}) |
This file contains 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,7 @@ | ||
SECRET_KEY = "correct-horse-battery-staple" | ||
# bearer:expected python_django_weak_secret_key | ||
SECRET_KEY = "weak" | ||
|
||
CRYPTOGRAPHY_KEY = "correct-horse-battery-staple" | ||
# bearer:expected python_django_weak_secret_key | ||
CRYPTOGRAPHY_KEY = "weak" |