claude-dev-env 8.119.0 → 8.119.2

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.
Files changed (41) hide show
  1. package/bin/git_hooks_installer.mjs +26 -2
  2. package/bin/git_hooks_installer.test.mjs +36 -0
  3. package/bin/install-transaction.mjs +3 -1
  4. package/bin/install.mjs +12 -8
  5. package/bin/install.test.mjs +89 -0
  6. package/bin/install.transaction.test.mjs +34 -0
  7. package/bin/merge_profile_settings.mjs +3 -2
  8. package/bin/merge_profile_settings.test.mjs +25 -1
  9. package/bin/profile-stop-gate.mjs +2 -1
  10. package/bin/profile-stop-gate.test.mjs +26 -1
  11. package/bin/write-file-atomically.mjs +148 -0
  12. package/bin/write-file-atomically.test.mjs +263 -0
  13. package/hooks/blocking/followup_pr_dedupe.py +71 -13
  14. package/hooks/blocking/merge_review_gate.py +4 -0
  15. package/hooks/blocking/merge_review_gate_parts/create_folders.py +6 -2
  16. package/hooks/blocking/merge_review_gate_parts/open_request.py +40 -15
  17. package/hooks/blocking/resolve_thread_reply_gate.py +116 -1
  18. package/hooks/blocking/test_cloud_graphql_gate.py +4 -0
  19. package/hooks/blocking/test_followup_pr_dedupe.py +99 -0
  20. package/hooks/blocking/test_gh_global_account_switch_gate.py +4 -0
  21. package/hooks/blocking/test_headless_claude_broker_gate.py +4 -0
  22. package/hooks/blocking/test_merge_review_gate.py +133 -0
  23. package/hooks/blocking/test_python_windows_invocation_gate.py +4 -0
  24. package/hooks/blocking/test_resolve_thread_reply_gate.py +430 -0
  25. package/hooks/blocking/tests/test_create_folders.py +7 -0
  26. package/hooks/blocking/tests/test_open_request.py +21 -0
  27. package/hooks/features/conduct-gates.md +3 -3
  28. package/hooks/hooks_constants/followup_pr_dedupe_constants.py +5 -0
  29. package/hooks/hooks_constants/merge_review_gate_constants.py +5 -0
  30. package/hooks/hooks_constants/pytest_invocation.py +24 -9
  31. package/hooks/hooks_constants/resolve_thread_reply_gate_constants.py +21 -1
  32. package/hooks/hooks_constants/test_pytest_invocation.py +25 -0
  33. package/hooks/hooks_constants/test_shell_command_mutation.py +11 -0
  34. package/hooks/hooks_constants/transcript_skill_scan_constants.py +22 -0
  35. package/hooks/session/test_npx_pele_guidance.py +4 -0
  36. package/hooks/test_transcript_skill_scan.py +72 -0
  37. package/hooks/transcript_skill_scan.py +138 -4
  38. package/hooks/validators/config/security_checks_constants.py +88 -0
  39. package/hooks/validators/security_checks.py +186 -1
  40. package/hooks/validators/test_security_checks.py +149 -0
  41. 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 not _is_secret_metadata(
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:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-dev-env",
3
- "version": "8.119.0",
3
+ "version": "8.119.2",
4
4
  "description": "Claude Code development standards — rules, hooks, agents, commands, and skills",
5
5
  "type": "module",
6
6
  "bin": {