[flake8-bandit] Check S105 for annotated assignment#15059
Merged
MichaReiser merged 2 commits intoastral-sh:mainfrom Dec 19, 2024
tarasmatsyk:fix-S105-false-negative
Merged
[flake8-bandit] Check S105 for annotated assignment#15059MichaReiser merged 2 commits intoastral-sh:mainfrom tarasmatsyk:fix-S105-false-negative
flake8-bandit] Check S105 for annotated assignment#15059MichaReiser merged 2 commits intoastral-sh:mainfrom
tarasmatsyk:fix-S105-false-negative
Conversation
Contributor
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| S105 | 4 | 4 | 0 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+4 -0 violations, +0 -0 fixes in 2 projects; 53 projects unchanged)
latchbio/latch (+2 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
+ src/latch_sdk_config/latch.py:64:23: S105 Possible hardcoded password assigned to: "get_secret" + src/latch_sdk_config/latch.py:65:29: S105 Possible hardcoded password assigned to: "get_secret_local"
zulip/zulip (+2 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
+ zerver/migrations/0209_user_profile_no_empty_password.py:69:44: S105 Possible hardcoded password assigned to: "USER_PASSWORD_CHANGED" + zerver/tests/test_signup.py:934:32: S105 Possible hardcoded password assigned to: "password"
Changes by rule (1 rules affected)
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| S105 | 4 | 4 | 0 | 0 | 0 |
dhruvmanila
approved these changes
Dec 19, 2024
Comment on lines
+1661
to
+1669
| if let Some(value) = value.as_deref() { | ||
| if checker.enabled(Rule::HardcodedPasswordString) { | ||
| flake8_bandit::rules::assign_hardcoded_password_string( | ||
| checker, | ||
| value, | ||
| std::slice::from_ref(target), | ||
| ); | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
I think we should switch the condition so that we only check when the rule is enabled
Suggested change
| if let Some(value) = value.as_deref() { | |
| if checker.enabled(Rule::HardcodedPasswordString) { | |
| flake8_bandit::rules::assign_hardcoded_password_string( | |
| checker, | |
| value, | |
| std::slice::from_ref(target), | |
| ); | |
| } | |
| } | |
| if checker.enabled(Rule::HardcodedPasswordString) { | |
| if let Some(value) = value.as_deref() { | |
| flake8_bandit::rules::assign_hardcoded_password_string( | |
| checker, | |
| value, | |
| std::slice::from_ref(target), | |
| ); | |
| } | |
| } |
Contributor
Author
There was a problem hiding this comment.
done,
I was using Rule::LambdaAssignment as an example:
https://github.com/astral-sh/ruff/blob/main/crates/ruff_linter/src/checkers/ast/analyze/statement.rs#L1633
flake8-bandit] Check S105 for annotated assignment
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
A follow up PR on #14991
Ruff ignores hardcoded passwords for typed variables. Add a rule to catch passwords in typed code bases
Test Plan
Includes 2 more test typed variables