Skip to content

Commit 1790240

Browse files
authored
Add new pattern (#222)
1 parent b8e72be commit 1790240

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

detect_secrets/plugins/keyword.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,16 @@
223223
),
224224
flags=re.IGNORECASE,
225225
)
226+
DATA_PUT_PASSWORD_REGEX = re.compile(
227+
# Matches patterns like data.put("password", "bar") or data.put('password', 'bar')
228+
r'data\.put\({whitespace}{quote}{denylist}{quote}{whitespace},{whitespace}{quote}({secret}){quote}{whitespace}\)'.format(
229+
denylist=DENYLIST_REGEX_WITH_PREFIX,
230+
quote=QUOTE,
231+
whitespace=OPTIONAL_WHITESPACE,
232+
secret=SECRET,
233+
),
234+
re.IGNORECASE,
235+
)
226236
CONFIG_DENYLIST_REGEX_TO_GROUP = {
227237
FOLLOWED_BY_COLON_REGEX: 4,
228238
PRECEDED_BY_EQUAL_COMPARISON_SIGNS_QUOTES_REQUIRED_REGEX: 2,
@@ -248,6 +258,7 @@
248258
FOLLOWED_BY_EQUAL_SIGNS_QUOTES_REQUIRED_REGEX: 5,
249259
FOLLOWED_BY_QUOTES_AND_SEMICOLON_REGEX: 3,
250260
FOLLOWED_BY_ARROW_FUNCTION_SIGN_QUOTES_REQUIRED_REGEX: 4,
261+
DATA_PUT_PASSWORD_REGEX: 2,
251262
}
252263

253264
TERRAFORM_DENYLIST_REGEX_TO_GROUP = {

tests/plugins/keyword_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@
162162
(LONG_LINE, None), # Long line test
163163
('password => ""', None),
164164
('password => {}'.format(COMMON_SECRET), None),
165+
('data.put("password", "{}")'.format(COMMON_SECRET), COMMON_SECRET),
166+
('data.put("secret", "{}")'.format(COMMON_SECRET), COMMON_SECRET),
165167
]
166168

167169
QUOTES_REQUIRED_TEST_CASES = [

0 commit comments

Comments
 (0)