Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions detect_secrets/plugins/keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,21 @@
secret=SECRET,
),
)
FOLLOWED_BY_TO_AND_QUOTES_REGEX = re.compile(
# e.g. "password" to "secretpw"
# e.g. "password" to 123
r'({denylist})({quote}){whitespace}to{whitespace}({quote})?({secret})(\3)'.format(
denylist=DENYLIST_REGEX,
whitespace=OPTIONAL_WHITESPACE,
quote=QUOTE,
secret=SECRET
),
)
DENYLIST_REGEX_TO_GROUP = {
FOLLOWED_BY_COLON_REGEX: 4,
FOLLOWED_BY_EQUAL_SIGNS_REGEX: 4,
FOLLOWED_BY_QUOTES_AND_SEMICOLON_REGEX: 3,
FOLLOWED_BY_TO_AND_QUOTES_REGEX: 4,
}
GOLANG_DENYLIST_REGEX_TO_GROUP = {
FOLLOWED_BY_COLON_EQUAL_SIGNS_REGEX: 4,
Expand All @@ -245,6 +256,7 @@
FOLLOWED_BY_COLON_QUOTES_REQUIRED_REGEX: 5,
FOLLOWED_BY_EQUAL_SIGNS_QUOTES_REQUIRED_REGEX: 4,
FOLLOWED_BY_QUOTES_AND_SEMICOLON_REGEX: 3,
FOLLOWED_BY_TO_AND_QUOTES_REGEX: 4,
}
QUOTES_REQUIRED_FILETYPES = {
FileType.CLS,
Expand Down
19 changes: 19 additions & 0 deletions tests/plugins/keyword_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@
],
},
}
FOLLOWED_BY_TO_AND_QUOTES_RE = {
'negatives': {
'quotes_required': [
'"password" to ""', # Nothing in the quotes
'"password" to "fake"', # 'fake' in the secret
'"apikey" to "${FOO}"', # Starts with ${ and ends with }
'password to hopenobodyfindsthisone', # no quotes
],
},
'positives': {
'quotes_required': [
'"password" to "m{{h}o)p${e]nob(ody[finds>-_$#thisone}}"',
'"apikey" to "m{{h}o)p${e]nob(ody[finds>-_$#thisone}}"',
],
},
}

QUOTES_REQUIRED_FILE_EXTENSIONS = (
'.cls',
Expand All @@ -163,6 +179,7 @@
+ FOLLOWED_BY_EQUAL_SIGNS_RE.get('negatives').get('quotes_required')
+ FOLLOWED_BY_EQUAL_SIGNS_RE.get('negatives').get('quotes_not_required')
+ FOLLOWED_BY_QUOTES_AND_SEMICOLON_RE.get('negatives').get('quotes_required')
+ FOLLOWED_BY_TO_AND_QUOTES_RE.get('negatives').get('quotes_required')
+ FOLLOWED_BY_EQUAL_SIGNS_OPTIONAL_BRACKETS_OPTIONAL_AT_SIGN_QUOTES_REQUIRED_REGEX.get(
'negatives',
).get('quotes_required'),
Expand All @@ -172,6 +189,7 @@
+ FOLLOWED_BY_COLON_RE.get('positives').get('quotes_not_required')
+ FOLLOWED_BY_EQUAL_SIGNS_RE.get('positives').get('quotes_required')
+ FOLLOWED_BY_EQUAL_SIGNS_RE.get('positives').get('quotes_not_required')
+ FOLLOWED_BY_TO_AND_QUOTES_RE.get('positives').get('quotes_required')
+ FOLLOWED_BY_QUOTES_AND_SEMICOLON_RE.get('positives').get('quotes_required'),
)

Expand Down Expand Up @@ -233,6 +251,7 @@ def test_analyze_with_line_exclude(self, file_content):
FOLLOWED_BY_COLON_RE.get('positives').get('quotes_required')
+ FOLLOWED_BY_EQUAL_SIGNS_RE.get('positives').get('quotes_required')
+ FOLLOWED_BY_QUOTES_AND_SEMICOLON_RE.get('positives').get('quotes_required')
+ FOLLOWED_BY_TO_AND_QUOTES_RE.get('positives').get('quotes_required')
) for file_extension in QUOTES_REQUIRED_FILE_EXTENSIONS
),
)
Expand Down