-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
flake8-bandit
] Added Rule S612
(Use of insecure `logging.config.…
- Loading branch information
Showing
9 changed files
with
82 additions
and
0 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
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,8 @@ | ||
import logging.config | ||
|
||
t = logging.config.listen(9999) | ||
|
||
def verify_func(): | ||
pass | ||
|
||
l = logging.config.listen(9999, verify=verify_func) |
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 |
---|---|---|
|
@@ -1727,6 +1727,9 @@ | |
"S506", | ||
"S508", | ||
"S509", | ||
"S6", | ||
"S61", | ||
"S612", | ||
"S7", | ||
"S70", | ||
"S701", | ||
|
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
40 changes: 40 additions & 0 deletions
40
src/rules/flake8_bandit/rules/logging_config_insecure_listen.rs
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,40 @@ | ||
use ruff_macros::derive_message_formats; | ||
use rustpython_ast::{Expr, Keyword}; | ||
|
||
use crate::ast::helpers::SimpleCallArgs; | ||
use crate::ast::types::Range; | ||
use crate::checkers::ast::Checker; | ||
use crate::define_violation; | ||
use crate::registry::Diagnostic; | ||
use crate::violation::Violation; | ||
|
||
define_violation!( | ||
pub struct LoggingConfigInsecureListen; | ||
); | ||
impl Violation for LoggingConfigInsecureListen { | ||
#[derive_message_formats] | ||
fn message(&self) -> String { | ||
format!("Use of insecure `logging.config.listen` detected") | ||
} | ||
} | ||
|
||
/// S612 | ||
pub fn logging_config_insecure_listen( | ||
checker: &mut Checker, | ||
func: &Expr, | ||
args: &[Expr], | ||
keywords: &[Keyword], | ||
) { | ||
if checker.resolve_call_path(func).map_or(false, |call_path| { | ||
call_path.as_slice() == ["logging", "config", "listen"] | ||
}) { | ||
let call_args = SimpleCallArgs::new(args, keywords); | ||
|
||
if call_args.get_argument("verify", None).is_none() { | ||
checker.diagnostics.push(Diagnostic::new( | ||
LoggingConfigInsecureListen, | ||
Range::from_located(func), | ||
)); | ||
} | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/rules/flake8_bandit/snapshots/ruff__rules__flake8_bandit__tests__S612_S612.py.snap
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,15 @@ | ||
--- | ||
source: src/rules/flake8_bandit/mod.rs | ||
expression: diagnostics | ||
--- | ||
- kind: | ||
LoggingConfigInsecureListen: ~ | ||
location: | ||
row: 3 | ||
column: 4 | ||
end_location: | ||
row: 3 | ||
column: 25 | ||
fix: ~ | ||
parent: ~ | ||
|