mirror of https://github.com/astral-sh/ruff
[bandit]: Do not treat "passed" as "password" for `S105`/`S106`/`S107` (#3222)
This commit is contained in:
parent
84e96cdcd9
commit
cd9fbeb560
|
|
@ -61,3 +61,13 @@ if token == "3\t4":
|
||||||
|
|
||||||
if token == "5\r6":
|
if token == "5\r6":
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# These should not be flagged
|
||||||
|
passed_msg = "You have passed!"
|
||||||
|
compassion = "Please don't match!"
|
||||||
|
impassable = "You shall not pass!"
|
||||||
|
passwords = ""
|
||||||
|
passphrases = ""
|
||||||
|
tokens = ""
|
||||||
|
secrets = ""
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
|
use regex::Regex;
|
||||||
use rustpython_parser::ast::{Constant, Expr, ExprKind};
|
use rustpython_parser::ast::{Constant, Expr, ExprKind};
|
||||||
|
|
||||||
use crate::checkers::ast::Checker;
|
use crate::checkers::ast::Checker;
|
||||||
|
|
||||||
const PASSWORD_NAMES: [&str; 7] = [
|
static PASSWORD_CANDIDATE_REGEX: Lazy<Regex> =
|
||||||
"password", "pass", "passwd", "pwd", "secret", "token", "secrete",
|
Lazy::new(|| Regex::new(r"(^|_)(pas+wo?r?d|pass(phrase)?|pwd|token|secrete?)($|_)").unwrap());
|
||||||
];
|
|
||||||
|
|
||||||
pub fn string_literal(expr: &Expr) -> Option<&str> {
|
pub fn string_literal(expr: &Expr) -> Option<&str> {
|
||||||
match &expr.node {
|
match &expr.node {
|
||||||
|
|
@ -18,9 +19,7 @@ pub fn string_literal(expr: &Expr) -> Option<&str> {
|
||||||
|
|
||||||
// Maybe use regex for this?
|
// Maybe use regex for this?
|
||||||
pub fn matches_password_name(string: &str) -> bool {
|
pub fn matches_password_name(string: &str) -> bool {
|
||||||
PASSWORD_NAMES
|
PASSWORD_CANDIDATE_REGEX.is_match(string)
|
||||||
.iter()
|
|
||||||
.any(|name| string.to_lowercase().contains(name))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_untyped_exception(type_: Option<&Expr>, checker: &Checker) -> bool {
|
pub fn is_untyped_exception(type_: Option<&Expr>, checker: &Checker) -> bool {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue