-
Notifications
You must be signed in to change notification settings - Fork 9
refactor(rules): deduplicate hardcoded-secret regex (closes #274) #277
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
Changes from all commits
719b001
4da90db
7d25b94
1ef8152
c91f715
f2ed293
85957e0
96b9aee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| use crate::impl_rule; | ||
| use crate::rules::common::{is_secret_value_long_enough, make_finding, walk_tree}; | ||
| use crate::rules::common::{ | ||
| is_secret_value_long_enough, make_finding, walk_tree, CSHARP_HARDCODED_SECRET_PATTERN, | ||
| }; | ||
| use crate::{Language, Severity}; | ||
| use regex::Regex; | ||
|
|
||
|
|
@@ -443,10 +445,7 @@ impl_rule! { | |
| fn check(_self, source, tree) { | ||
|
|
||
| let mut findings = Vec::new(); | ||
| let secret_pattern = Regex::new( | ||
| r"(?i)(password|secret|api_?key|apikey|token|credential|private_?key|connection_?string|connectionstring)", | ||
| ) | ||
| .unwrap(); | ||
| let secret_pattern = Regex::new(CSHARP_HARDCODED_SECRET_PATTERN).unwrap(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The old inline C# pattern was |
||
|
|
||
| walk_tree(tree.root_node(), source, &mut |node, src| { | ||
| // variable_declarator: string password = "hardcoded" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
connectionstringalternativeconnection_?string(with_?making the underscore optional) already matchesconnectionstring, so the explicitconnectionstringalternative at the end is redundant. This was present in the originalcsharp.rsinline pattern too, but now that it's being lifted into a shared constant it's worth cleaning up.