claude-dev-env 8.119.1 → 8.120.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hooks/blocking/followup_pr_dedupe.py +71 -13
- package/hooks/blocking/gh_api_budget_gate.py +286 -0
- package/hooks/blocking/merge_review_gate.py +4 -0
- package/hooks/blocking/merge_review_gate_parts/create_folders.py +6 -2
- package/hooks/blocking/merge_review_gate_parts/open_request.py +40 -15
- package/hooks/blocking/resolve_thread_reply_gate.py +116 -1
- package/hooks/blocking/test_bash_dispatcher_interpreter_starts.py +8 -3
- package/hooks/blocking/test_bash_pre_tool_use_dispatcher.py +1 -0
- package/hooks/blocking/test_cloud_graphql_gate.py +4 -0
- package/hooks/blocking/test_followup_pr_dedupe.py +99 -0
- package/hooks/blocking/test_gh_api_budget_gate.py +602 -0
- package/hooks/blocking/test_gh_global_account_switch_gate.py +4 -0
- package/hooks/blocking/test_headless_claude_broker_gate.py +4 -0
- package/hooks/blocking/test_merge_review_gate.py +133 -0
- package/hooks/blocking/test_python_windows_invocation_gate.py +4 -0
- package/hooks/blocking/test_resolve_thread_reply_gate.py +430 -0
- package/hooks/blocking/tests/test_create_folders.py +7 -0
- package/hooks/blocking/tests/test_open_request.py +21 -0
- package/hooks/features/bash-dispatchers.md +3 -0
- package/hooks/features/conduct-gates.md +3 -3
- package/hooks/hooks_constants/bash_pre_tool_use_dispatcher_constants.py +4 -0
- package/hooks/hooks_constants/followup_pr_dedupe_constants.py +5 -0
- package/hooks/hooks_constants/gh_api_budget.py +186 -0
- package/hooks/hooks_constants/gh_api_budget_gate_constants.py +215 -0
- package/hooks/hooks_constants/gh_argument_lists.py +169 -0
- package/hooks/hooks_constants/gh_shell_loop_scan.py +386 -0
- package/hooks/hooks_constants/merge_review_gate_constants.py +5 -0
- package/hooks/hooks_constants/pytest_invocation.py +24 -9
- package/hooks/hooks_constants/resolve_thread_reply_gate_constants.py +21 -1
- package/hooks/hooks_constants/test_bash_pre_tool_use_dispatcher_constants.py +5 -1
- package/hooks/hooks_constants/test_gh_api_budget.py +125 -0
- package/hooks/hooks_constants/test_gh_argument_lists.py +49 -0
- package/hooks/hooks_constants/test_gh_shell_loop_scan.py +50 -0
- package/hooks/hooks_constants/test_pytest_invocation.py +25 -0
- package/hooks/hooks_constants/test_shell_command_mutation.py +11 -0
- package/hooks/hooks_constants/transcript_skill_scan_constants.py +22 -0
- package/hooks/session/test_npx_pele_guidance.py +4 -0
- package/hooks/test_transcript_skill_scan.py +72 -0
- package/hooks/transcript_skill_scan.py +138 -4
- package/hooks/validators/config/security_checks_constants.py +88 -0
- package/hooks/validators/security_checks.py +186 -1
- package/hooks/validators/test_security_checks.py +149 -0
- package/package.json +1 -1
|
@@ -12,6 +12,7 @@ import sys
|
|
|
12
12
|
from pathlib import Path
|
|
13
13
|
from typing import List
|
|
14
14
|
|
|
15
|
+
from .config import security_checks_constants as secret_constants
|
|
15
16
|
from .validator_base import Violation, source_text, syntax_tree
|
|
16
17
|
|
|
17
18
|
|
|
@@ -76,6 +77,190 @@ def _is_secret_metadata(variable_name: str, literal_text: str) -> bool:
|
|
|
76
77
|
return _is_resource_name_metadata(variable_name, literal_text)
|
|
77
78
|
|
|
78
79
|
|
|
80
|
+
def _bare_word(word: str) -> str | None:
|
|
81
|
+
"""Return a word without edge punctuation, or None for a word to report.
|
|
82
|
+
|
|
83
|
+
A word that holds a format placeholder comes back empty when nothing but
|
|
84
|
+
punctuation stands beside the placeholder, and as None when letters do.
|
|
85
|
+
"""
|
|
86
|
+
stripped_word = word.strip(secret_constants.WORD_EDGE_PUNCTUATION)
|
|
87
|
+
word_without_placeholders = secret_constants.FORMAT_PLACEHOLDER_PATTERN.sub(
|
|
88
|
+
"", stripped_word
|
|
89
|
+
)
|
|
90
|
+
if word_without_placeholders == stripped_word:
|
|
91
|
+
return stripped_word or None
|
|
92
|
+
remainder = word_without_placeholders.strip(secret_constants.WORD_EDGE_PUNCTUATION)
|
|
93
|
+
return None if remainder else ""
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _is_capitals_word(bare_word: str) -> bool:
|
|
97
|
+
return len(bare_word) > 1 and bare_word.isupper()
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _is_plain_word(bare_word: str, is_lead_word: bool) -> bool:
|
|
101
|
+
if not (bare_word.isascii() and bare_word.isalpha()):
|
|
102
|
+
return False
|
|
103
|
+
if _is_capitals_word(bare_word):
|
|
104
|
+
return len(bare_word) <= secret_constants.MAXIMUM_CAPITALS_WORD_LENGTH
|
|
105
|
+
if len(bare_word) > secret_constants.MAXIMUM_ORDINARY_WORD_LENGTH:
|
|
106
|
+
return False
|
|
107
|
+
if secret_constants.UNPRONOUNCEABLE_RUN_PATTERN.search(bare_word):
|
|
108
|
+
return False
|
|
109
|
+
return bare_word.islower() or (is_lead_word and bare_word[1:].islower())
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _has_only_plain_words(all_bare_words: list[str | None]) -> bool:
|
|
113
|
+
for each_index, each_word in enumerate(all_bare_words):
|
|
114
|
+
if each_word is None:
|
|
115
|
+
return False
|
|
116
|
+
if each_word and not _is_plain_word(each_word, is_lead_word=each_index == 0):
|
|
117
|
+
return False
|
|
118
|
+
all_capitals_words = [
|
|
119
|
+
each_word for each_word in all_bare_words if _is_capitals_word(each_word or "")
|
|
120
|
+
]
|
|
121
|
+
return len(all_capitals_words) <= secret_constants.MAXIMUM_CAPITALS_WORD_COUNT
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _has_unknown_short_word(all_lowered_words: list[str]) -> bool:
|
|
125
|
+
return any(
|
|
126
|
+
0 < len(each_word) <= secret_constants.MAXIMUM_SHORT_WORD_LENGTH
|
|
127
|
+
and each_word not in secret_constants.ALL_SENTENCE_FUNCTION_WORDS
|
|
128
|
+
for each_word in all_lowered_words
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _has_label_before_value(all_words: list[str]) -> bool:
|
|
133
|
+
return any(
|
|
134
|
+
each_word.endswith(secret_constants.LABEL_CLOSING_MARK)
|
|
135
|
+
for each_word in all_words[:-1]
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def _has_auth_scheme_before_value(all_lowered_words: list[str]) -> bool:
|
|
140
|
+
if all_lowered_words[0] in secret_constants.ALL_AUTH_SCHEME_LEAD_WORDS:
|
|
141
|
+
return True
|
|
142
|
+
return any(
|
|
143
|
+
each_word in secret_constants.ALL_AUTH_SCHEME_WORDS
|
|
144
|
+
for each_word in all_lowered_words[:-1]
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _has_equal_length_group(all_bare_words: list[str]) -> bool:
|
|
149
|
+
run_length = 0
|
|
150
|
+
previous_length = 0
|
|
151
|
+
for each_word in all_bare_words:
|
|
152
|
+
is_group_word = len(each_word) >= secret_constants.MINIMUM_GROUP_WORD_LENGTH
|
|
153
|
+
run_length = (
|
|
154
|
+
run_length + 1 if is_group_word and len(each_word) == previous_length else 1
|
|
155
|
+
)
|
|
156
|
+
previous_length = len(each_word) if is_group_word else 0
|
|
157
|
+
if run_length >= secret_constants.MINIMUM_GROUP_RUN_LENGTH:
|
|
158
|
+
return True
|
|
159
|
+
return False
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _reads_as_message(literal_text: str) -> bool:
|
|
163
|
+
"""Return whether a string literal reads as a message a person wrote.
|
|
164
|
+
|
|
165
|
+
The default verdict is "not a message". A value is a message only when
|
|
166
|
+
every sign agrees: four or more words with one space between them; each
|
|
167
|
+
one a short plain lowercase word, a lead word with one capital, one short
|
|
168
|
+
capitals word at most, or a format placeholder that stands alone; a
|
|
169
|
+
sentence function word among them; no other word of one or two letters;
|
|
170
|
+
no authentication scheme word before another word; no label that ends in
|
|
171
|
+
a colon before another word; and no run of three words of one length, as
|
|
172
|
+
a grouped key has.
|
|
173
|
+
|
|
174
|
+
Args:
|
|
175
|
+
literal_text: The string value assigned to a sensitive name.
|
|
176
|
+
|
|
177
|
+
Returns:
|
|
178
|
+
Whether the value is prose with nothing key-shaped in it.
|
|
179
|
+
"""
|
|
180
|
+
all_words = literal_text.split(secret_constants.WORD_SEPARATOR)
|
|
181
|
+
if len(all_words) < secret_constants.MINIMUM_MESSAGE_WORD_COUNT:
|
|
182
|
+
return False
|
|
183
|
+
if all_words != literal_text.split():
|
|
184
|
+
return False
|
|
185
|
+
all_bare_words = [_bare_word(each_word) for each_word in all_words]
|
|
186
|
+
if not _has_only_plain_words(all_bare_words):
|
|
187
|
+
return False
|
|
188
|
+
all_lowered_words = [(each_word or "").lower() for each_word in all_bare_words]
|
|
189
|
+
if _has_auth_scheme_before_value(all_lowered_words):
|
|
190
|
+
return False
|
|
191
|
+
if _has_unknown_short_word(all_lowered_words):
|
|
192
|
+
return False
|
|
193
|
+
if _has_label_before_value(all_words) or _has_equal_length_group(all_lowered_words):
|
|
194
|
+
return False
|
|
195
|
+
return not secret_constants.ALL_SENTENCE_FUNCTION_WORDS.isdisjoint(
|
|
196
|
+
all_lowered_words
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def _has_pointer_segments(
|
|
201
|
+
pointer_text: str,
|
|
202
|
+
separator: str,
|
|
203
|
+
segment_pattern: re.Pattern[str],
|
|
204
|
+
minimum_segment_count: int,
|
|
205
|
+
) -> bool:
|
|
206
|
+
all_segments = pointer_text.split(separator)
|
|
207
|
+
if len(all_segments) < minimum_segment_count:
|
|
208
|
+
return False
|
|
209
|
+
if not all(segment_pattern.fullmatch(each_segment) for each_segment in all_segments):
|
|
210
|
+
return False
|
|
211
|
+
lowered_text = pointer_text.lower()
|
|
212
|
+
return any(
|
|
213
|
+
each_word in lowered_text for each_word in secret_constants.ALL_POINTER_VALUE_WORDS
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def _names_the_variable_or_flag_it_points_to(
|
|
218
|
+
variable_name: str, literal_text: str
|
|
219
|
+
) -> bool:
|
|
220
|
+
"""Return whether a pointer-named constant holds a variable or flag name.
|
|
221
|
+
|
|
222
|
+
The name must end in a suffix that says the value points somewhere, and
|
|
223
|
+
the value must be letters-only segments that hold a word such as token
|
|
224
|
+
or key, the way the name of a variable or flag for a credential does.
|
|
225
|
+
"""
|
|
226
|
+
if variable_name.endswith(secret_constants.ALL_VARIABLE_NAME_SUFFIXES):
|
|
227
|
+
return _has_pointer_segments(
|
|
228
|
+
literal_text,
|
|
229
|
+
secret_constants.NAME_SEGMENT_SEPARATOR,
|
|
230
|
+
secret_constants.VARIABLE_NAME_SEGMENT_PATTERN,
|
|
231
|
+
secret_constants.MINIMUM_VARIABLE_SEGMENT_COUNT,
|
|
232
|
+
)
|
|
233
|
+
is_flag_name = variable_name.endswith(secret_constants.ALL_FLAG_NAME_SUFFIXES)
|
|
234
|
+
if not (is_flag_name and literal_text.startswith(secret_constants.FLAG_LEAD)):
|
|
235
|
+
return False
|
|
236
|
+
return _has_pointer_segments(
|
|
237
|
+
literal_text.removeprefix(secret_constants.FLAG_LEAD),
|
|
238
|
+
secret_constants.FLAG_SEGMENT_SEPARATOR,
|
|
239
|
+
secret_constants.FLAG_SEGMENT_PATTERN,
|
|
240
|
+
secret_constants.MINIMUM_FLAG_SEGMENT_COUNT,
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def _is_password_name(variable_name: str) -> bool:
|
|
245
|
+
if any(
|
|
246
|
+
each_word in variable_name
|
|
247
|
+
for each_word in secret_constants.ALL_PASSWORD_NAME_WORDS
|
|
248
|
+
):
|
|
249
|
+
return True
|
|
250
|
+
all_name_segments = variable_name.split(secret_constants.NAME_SEGMENT_SEPARATOR)
|
|
251
|
+
return not secret_constants.ALL_PASSWORD_NAME_SEGMENTS.isdisjoint(all_name_segments)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _is_secret_value(variable_name: str, literal_text: str) -> bool:
|
|
255
|
+
if _is_secret_metadata(variable_name, literal_text):
|
|
256
|
+
return False
|
|
257
|
+
if _is_password_name(variable_name):
|
|
258
|
+
return True
|
|
259
|
+
if _names_the_variable_or_flag_it_points_to(variable_name, literal_text):
|
|
260
|
+
return False
|
|
261
|
+
return not _reads_as_message(literal_text)
|
|
262
|
+
|
|
263
|
+
|
|
79
264
|
def check_hardcoded_secrets(tree: ast.AST, filename: str) -> List[Violation]:
|
|
80
265
|
MINIMUM_SECRET_LENGTH = 3
|
|
81
266
|
violations: List[Violation] = []
|
|
@@ -89,7 +274,7 @@ def check_hardcoded_secrets(tree: ast.AST, filename: str) -> List[Violation]:
|
|
|
89
274
|
if isinstance(node.value, ast.Constant) and isinstance(
|
|
90
275
|
node.value.value, str
|
|
91
276
|
):
|
|
92
|
-
if len(node.value.value) > MINIMUM_SECRET_LENGTH and
|
|
277
|
+
if len(node.value.value) > MINIMUM_SECRET_LENGTH and _is_secret_value(
|
|
93
278
|
var_name, node.value.value
|
|
94
279
|
):
|
|
95
280
|
violations.append(
|
|
@@ -53,6 +53,135 @@ password_key = "password"
|
|
|
53
53
|
''',
|
|
54
54
|
)
|
|
55
55
|
|
|
56
|
+
ALL_CLEARED_NAME_VALUE_PAIRS = (
|
|
57
|
+
("FAIL_NO_TOKENS", "No tokens were found in the response."),
|
|
58
|
+
("FAIL_NO_TOKENS", "no tokens were found in the response"),
|
|
59
|
+
("SECRET_MISSING_MESSAGE", "Set the secret in the environment before the run."),
|
|
60
|
+
("AUTH_FAILURE_TEMPLATE", "Sign in failed for {account_name}, try again"),
|
|
61
|
+
("AUTH_FAILURE_TEMPLATE", "The call for {account_name!r} took {elapsed:.2f} seconds"),
|
|
62
|
+
("token_hint", "paste a token below"),
|
|
63
|
+
("TOKEN_MESSAGE", "The HTTP call was refused by the server."),
|
|
64
|
+
("SERVICE_TOKEN_ENV", "SERVICE_API_TOKEN"),
|
|
65
|
+
("SERVICE_AUTH_ENV_VAR", "MAX_TOKENS"),
|
|
66
|
+
("MAXIMUM_TOKENS_FLAG", "--max-tokens"),
|
|
67
|
+
("TOKEN_OPTION", "--token"),
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
ALL_AUTH_HEADER_NAME_VALUE_PAIRS = (
|
|
71
|
+
("AUTH_HEADER_VALUE", "Bearer abcdefghijklmnopqrstuvwxyz"),
|
|
72
|
+
("AUTH_HEADER_VALUE", "Bearer xyz"),
|
|
73
|
+
("AUTH_HEADER_VALUE", "Token abcdefghijklmnop"),
|
|
74
|
+
("AUTH_HEADER_VALUE", "Bearer is the word"),
|
|
75
|
+
("AUTH_VALUE", "Authorization is Bearer abcdefghijklmn"),
|
|
76
|
+
("AUTH_VALUE", "the Bearer abcdefghijklmn"),
|
|
77
|
+
("AUTH_VALUE", "a Basic dxnlcjpwyxnz"),
|
|
78
|
+
("AUTH_VALUE", "send the basic word in the call"),
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
ALL_WRAPPED_KEY_NAME_VALUE_PAIRS = (
|
|
82
|
+
("FAIL_NO_TOKENS", "aaaa1111bbbb"),
|
|
83
|
+
("SERVICE_API_KEY", "Use zq_live_abcdefghijklmnopqrstuvwx here"),
|
|
84
|
+
("SERVICE_API_KEY", "Key zq-live-abcdefghijklmnop."),
|
|
85
|
+
("SERVICE_TOKEN", "Use AbCdEfGhIjKlMnOpQrStUvWx for the call"),
|
|
86
|
+
("SERVICE_SECRET", "Key wJalrXUtnFEMI/KzMDENG/bPxRfiCYEXAMPLEKEY"),
|
|
87
|
+
("SERVICE_TOKEN", "zqzq-abcdefghij-klmnopqrst is the one."),
|
|
88
|
+
("SERVICE_TOKEN", "{prefix} AbCdEfGhIjKlMnOp"),
|
|
89
|
+
("SERVICE_TOKEN", "Token:\tabcdefghijklmnopqrstuvwxyzabcdef"),
|
|
90
|
+
("SERVICE_TOKEN", "Send the abcdefghijklmnopqrstuvwxyz with each call."),
|
|
91
|
+
("SERVICE_TOKEN", "{zq-live-abcdefghijklmnop} is the key for it"),
|
|
92
|
+
("SERVICE_TOKEN", "the token for it is {AbCdEf123456GhIjKl}"),
|
|
93
|
+
("SERVICE_TOKEN", "the token for it is {hunter2}"),
|
|
94
|
+
("SERVICE_TOKEN", "the key for it is zq{live}abc"),
|
|
95
|
+
("SERVICE_TOKEN", "the key for it is {}hunter"),
|
|
96
|
+
("SERVICE_TOKEN", "the key for it is {name:swordfish}"),
|
|
97
|
+
("SERVICE_TOKEN", "use qwxzjkvbnmplrt for the call"),
|
|
98
|
+
("SERVICE_TOKEN", "Send the abcdefghijklmn with each call."),
|
|
99
|
+
("SERVICE_TOKEN", "the key is\nswordfish in the pond"),
|
|
100
|
+
("SERVICE_TOKEN", "the key is swordfish in the pond"),
|
|
101
|
+
("SERVICE_TOKEN", "the key is \u0661\u0662\u0663 in the pond"),
|
|
102
|
+
("SERVICE_TOKEN", "the key is hunt\u0435r in the pond"),
|
|
103
|
+
("SERVICE_SECRET", "::: is the !!! in it"),
|
|
104
|
+
("SERVICE_SECRET", "the token is 'swordfish' for it"),
|
|
105
|
+
("SERVICE_SECRET", "the token is: swordfish in the pond"),
|
|
106
|
+
("SERVICE_SECRET", "login: admin swordfish for the store"),
|
|
107
|
+
("SERVICE_SECRET", "it is Swordfish in the pond"),
|
|
108
|
+
("AUTH_HINT", "Open the page with ?access_token=abcdef to sign in."),
|
|
109
|
+
("AUTH_NOTE", "The store is at https://admin:hunterpass@example.test/db."),
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
ALL_VARIABLE_OR_FLAG_SHAPED_NAME_VALUE_PAIRS = (
|
|
113
|
+
("DB_PASSWORD", "PROD_DB_PASS"),
|
|
114
|
+
("DB_PASSWORD", "HUNTER_TWO"),
|
|
115
|
+
("DB_PASSWORD", "--swordfish"),
|
|
116
|
+
("DB_PASSWORD", "--open-sesame"),
|
|
117
|
+
("SERVICE_SECRET", "PROD_SERVICE_PASS"),
|
|
118
|
+
("SERVICE_TOKEN_ENV", "--swordfish"),
|
|
119
|
+
("SERVICE_TOKEN_FLAG", "PROD_SERVICE_PASS"),
|
|
120
|
+
("SERVICE_TOKEN_ENV", "prod_service_pass"),
|
|
121
|
+
("SERVICE_AUTH_ENV", "AKIAIOSFODNNEXAMPLE"),
|
|
122
|
+
("SERVICE_AUTH_ENV", "HUNTER_TWO"),
|
|
123
|
+
("SERVICE_AUTH_ENV", "TOKEN_X9K2"),
|
|
124
|
+
("SERVICE_SECRET_ENV_NAME", "XKLQZPMTVTOKENXKLQZPMTV"),
|
|
125
|
+
("DB_PASSWORD_ENV", "DB_PASSWORD"),
|
|
126
|
+
("DB_PASSWORD_FLAG", "--open-sesame"),
|
|
127
|
+
("SECRET_OPTION", "--swordfish"),
|
|
128
|
+
("SECRET_OPTION", "--token9"),
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
ALL_PASSPHRASE_NAME_VALUE_PAIRS = (
|
|
132
|
+
("SERVICE_TOKEN", "Correct horse battery staple"),
|
|
133
|
+
("SECRET_PHRASE", "correct horse battery staple."),
|
|
134
|
+
("PASSWORD", "Open Sesame"),
|
|
135
|
+
("PASSWORD", "Admin admin"),
|
|
136
|
+
("PASSWORD", "P@ssword One!"),
|
|
137
|
+
("DB_PASSWORD", "Password: swordfish"),
|
|
138
|
+
("SERVICE_SECRET", "Password: swordfish"),
|
|
139
|
+
("SERVICE_SECRET", "The secret: swordfish in the pond"),
|
|
140
|
+
("PASSWORD", "The password is swordfish."),
|
|
141
|
+
("PASSWORD_ERROR", "My secret password"),
|
|
142
|
+
("PASSWORD_HINT", "It was the best of times."),
|
|
143
|
+
("SECRET_PASSPHRASE", "it was the best of times"),
|
|
144
|
+
("SECRET_PHRASE", "it was the best of times"),
|
|
145
|
+
("SECRET_ANSWER", "the name of the first dog"),
|
|
146
|
+
("SECRET_PASS", "it is in the pond"),
|
|
147
|
+
("AUTH_PASS", "open the pod bay doors"),
|
|
148
|
+
("AUTH_PASSCODE", "it is in the pond"),
|
|
149
|
+
("SERVICE_TOKEN", "swordfish is it"),
|
|
150
|
+
("SERVICE_API_KEY", "the key is zq live abc"),
|
|
151
|
+
("SERVICE_TOKEN", "my voice is my passport"),
|
|
152
|
+
("SERVICE_TOKEN", "the Secret swordfish"),
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
ALL_GROUPED_KEY_NAME_VALUE_PAIRS = (
|
|
156
|
+
("SECRET_KEY", "QUJD REVG R0hJ SktM"),
|
|
157
|
+
("APP_PASSWORD", "Abcd efgh ijkl mnop"),
|
|
158
|
+
("SERVICE_SECRET", "Abcd efgh ijkl mnop"),
|
|
159
|
+
("SERVICE_SECRET", "that with from this"),
|
|
160
|
+
("SERVICE_SECRET", "that with from this."),
|
|
161
|
+
("SERVICE_SECRET", "abcd efgh ijkl with."),
|
|
162
|
+
("SERVICE_SECRET", "wxyz on abcd efgh ijkl"),
|
|
163
|
+
("SERVICE_SECRET", "the AKIA IOSFO DNNEX AMPLE"),
|
|
164
|
+
("SERVICE_SECRET", "QUJD REVG ROHJ SKTM a"),
|
|
165
|
+
("SERVICE_SECRET", "AKIA is the ABCDE"),
|
|
166
|
+
("SERVICE_SECRET", "a 123 456 789 012"),
|
|
167
|
+
("SERVICE_TOKEN", "the code is 123 456"),
|
|
168
|
+
("SERVICE_TOKEN", "the code is 123"),
|
|
169
|
+
("DB_AUTH_URL", "Host db.example.test user admin pass swordfish"),
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
ALL_REPORTED_NAME_VALUE_PAIRS = (
|
|
173
|
+
*ALL_AUTH_HEADER_NAME_VALUE_PAIRS,
|
|
174
|
+
*ALL_WRAPPED_KEY_NAME_VALUE_PAIRS,
|
|
175
|
+
*ALL_VARIABLE_OR_FLAG_SHAPED_NAME_VALUE_PAIRS,
|
|
176
|
+
*ALL_PASSPHRASE_NAME_VALUE_PAIRS,
|
|
177
|
+
*ALL_GROUPED_KEY_NAME_VALUE_PAIRS,
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _assignment_tree(variable_name: str, literal_text: str) -> ast.AST:
|
|
182
|
+
return ast.parse(f"{variable_name} = {literal_text!r}")
|
|
183
|
+
|
|
184
|
+
|
|
56
185
|
GOOD_PARAMETERIZED_SQL = '''
|
|
57
186
|
def get_user(user_id):
|
|
58
187
|
cursor.execute("SELECT * FROM users WHERE id = %s", (user_id,))
|
|
@@ -133,6 +262,26 @@ class TestHardcodedSecrets:
|
|
|
133
262
|
violations = check_hardcoded_secrets(tree, "test.py")
|
|
134
263
|
assert len(violations) == 1
|
|
135
264
|
|
|
265
|
+
@pytest.mark.parametrize(
|
|
266
|
+
("variable_name", "literal_text"), ALL_CLEARED_NAME_VALUE_PAIRS
|
|
267
|
+
)
|
|
268
|
+
def test_message_or_pointer_value_under_sensitive_name_passes(
|
|
269
|
+
self, variable_name: str, literal_text: str
|
|
270
|
+
) -> None:
|
|
271
|
+
tree = _assignment_tree(variable_name, literal_text)
|
|
272
|
+
violations = check_hardcoded_secrets(tree, "test.py")
|
|
273
|
+
assert violations == []
|
|
274
|
+
|
|
275
|
+
@pytest.mark.parametrize(
|
|
276
|
+
("variable_name", "literal_text"), ALL_REPORTED_NAME_VALUE_PAIRS
|
|
277
|
+
)
|
|
278
|
+
def test_secret_shaped_value_fails(
|
|
279
|
+
self, variable_name: str, literal_text: str
|
|
280
|
+
) -> None:
|
|
281
|
+
tree = _assignment_tree(variable_name, literal_text)
|
|
282
|
+
violations = check_hardcoded_secrets(tree, "test.py")
|
|
283
|
+
assert len(violations) == 1
|
|
284
|
+
|
|
136
285
|
|
|
137
286
|
class TestSqlInjection:
|
|
138
287
|
def test_parameterized_query_passes(self) -> None:
|