Skip to content
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

[flake8-bandit] Check S105 for annotated assignment #15059

Merged
merged 2 commits into from
Dec 19, 2024

Conversation

tarasmatsyk
Copy link
Contributor

@tarasmatsyk tarasmatsyk commented Dec 19, 2024

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

@MichaReiser MichaReiser added the rule Implementing or modifying a lint rule label Dec 19, 2024
Copy link
Contributor

github-actions bot commented Dec 19, 2024

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+4 -0 violations, +0 -0 fixes in 3 projects; 52 projects unchanged)

latchbio/latch (+2 -0 violations, +0 -0 fixes)

+ 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"

pandas-dev/pandas (+0 -0 violations, +0 -0 fixes)


zulip/zulip (+2 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --no-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

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

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),
);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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),
);
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dhruvmanila dhruvmanila changed the title [flake8-bandit] Fix false negative S105 for typed variables [flake8-bandit] Check S105 for annotated assignment Dec 19, 2024
@MichaReiser MichaReiser enabled auto-merge (squash) December 19, 2024 12:22
@MichaReiser MichaReiser merged commit 85e71ba into astral-sh:main Dec 19, 2024
20 checks passed
@tarasmatsyk tarasmatsyk deleted the fix-S105-false-negative branch December 19, 2024 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants