Skip to content

Commit 8996b7a

Browse files
authored
#404 - Add Arrow Key Assignment Operator Regex to Keyword Plugin (#567)
* Add regex for the arrow function assignment operator followed by quotes to keyword plugin * Revert local dependency changes
1 parent 3c8ee74 commit 8996b7a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

detect_secrets/plugins/keyword.py

+12
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,17 @@
202202
),
203203
flags=re.IGNORECASE,
204204
)
205+
FOLLOWED_BY_ARROW_FUNCTION_SIGN_QUOTES_REQUIRED_REGEX = re.compile(
206+
# e.g. my_password => "bar" or my_password => bar
207+
r'{denylist}({closing})?{whitespace}=>?{whitespace}({quote})({secret})(\3)'.format(
208+
denylist=DENYLIST_REGEX,
209+
closing=CLOSING,
210+
quote=QUOTE,
211+
whitespace=OPTIONAL_WHITESPACE,
212+
secret=SECRET,
213+
),
214+
flags=re.IGNORECASE,
215+
)
205216
CONFIG_DENYLIST_REGEX_TO_GROUP = {
206217
FOLLOWED_BY_COLON_REGEX: 4,
207218
PRECEDED_BY_EQUAL_COMPARISON_SIGNS_QUOTES_REQUIRED_REGEX: 2,
@@ -226,6 +237,7 @@
226237
PRECEDED_BY_EQUAL_COMPARISON_SIGNS_QUOTES_REQUIRED_REGEX: 2,
227238
FOLLOWED_BY_EQUAL_SIGNS_QUOTES_REQUIRED_REGEX: 5,
228239
FOLLOWED_BY_QUOTES_AND_SEMICOLON_REGEX: 3,
240+
FOLLOWED_BY_ARROW_FUNCTION_SIGN_QUOTES_REQUIRED_REGEX: 4,
229241
}
230242
REGEX_BY_FILETYPE = {
231243
FileType.GO: GOLANG_DENYLIST_REGEX_TO_GROUP,

tests/plugins/keyword_test.py

+4
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,16 @@
142142
('if (db_pass !== "{}") {{'.format(COMMON_SECRET), COMMON_SECRET),
143143
('password "{}";'.format(COMMON_SECRET), COMMON_SECRET),
144144
('password = {}'.format(COMMON_SECRET), None), # Secret without quotes
145+
('password = "{}"'.format(COMMON_SECRET), COMMON_SECRET),
146+
('password => "{}"'.format(COMMON_SECRET), COMMON_SECRET),
145147
('api_key = ""', None), # Nothing in the quotes
146148
("secret: ''", None), # Nothing in the quotes
147149
('password: ${link}', None), # Has a ${ followed by a }
148150
('some_key = "real_secret"', None), # We cannot make 'key' a Keyword, too noisy)
149151
('private_key "hopenobodyfindsthisone\';', None), # Double-quote does not match single-quote)
150152
(LONG_LINE, None), # Long line test
153+
('password => ""', None),
154+
('password => {}'.format(COMMON_SECRET), None),
151155
]
152156

153157

0 commit comments

Comments
 (0)