@cratis/pi 7.150.1 → 7.150.3

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.
@@ -12,7 +12,7 @@ Three layers:
12
12
  | Hard block | `PreToolUse` on a write | `scripts/cratis-guard-writes.sh` | zero | exits **2** — the write does not happen |
13
13
  | Hard block | `PreToolUse` on `Bash` | `scripts/cratis-guard-shell-writes.sh` | zero tokens; one batch Write/Edit classification | exits **2** — a protected reference requires read-only syntax throughout the command; best-effort, not a sandbox |
14
14
  | Hard block | `PreToolUse` on `Bash` | `scripts/cratis-guard-store-mutations.sh` | zero; parses only commands that mention `cratis` | exits **2** — the store-changing `cratis chronicle` command does not run |
15
- | Hard block | `PreToolUse` on `Bash` | `scripts/cratis-guard-secrets.sh` | zero; parses only commands that mention a credential-bearing tool or file | exits **2** — the guard is a **best-effort, defense-in-depth text filter, NOT a sandbox**: it refuses some harmless commands rather than model the whole shell. Real protection requires **OS-level sandboxing or file permissions**. A command is *tainted* when a protected file-name stem appears in any token, including option values, in any letter case, after quotes, backslashes and line continuations are removed. Only search regex text is exempt: `-e`/`--regexp` values, or the first operand when neither `-e` nor `-f` is present. `-f`/`--file` values and all other operands are paths, not exempt patterns. The stems are `.env`, `.pem`, `.p12`, `.pfx`, `id_rsa`, `id_ed25519`, `id_ecdsa`, `id_dsa`, `.netrc`, `.npmrc`, `.pgpass`, `.pypirc`, `.git-credentials`, `.kube/`, `kubeconfig`, `credentials`, `.docker/`, `/environ` and `run/secrets`. Stars, question marks, bracket expressions and grouped pathname patterns count as the characters they can match when the pattern retains at least two literal stem characters. For `credentials` only, an embedded occurrence in a longer directory component or a recognized source filename (for example `Specs/for_ApplicationCredentials/a.cs` or `CredentialsProvider.cs`) is not a stem hit; exact `credentials`, `credentials.*` and a `credentials/` component remain protected. A command is also tainted when an assignment value or any expanded word can contain a stem. A tainted command runs only when it is a single simple command with every word literal: `cat`, `head`, `tail`, `less`, `more`, `wc`, `grep`, `egrep`, `fgrep` or `rg` of paths that are not protected (such as `cat .env.example`); `test` of literal paths; or `cp SOURCE DEST` with no options and a source that is not protected (for example, `cp .env.example example.txt`; the shell-write guard separately refuses `.env` destinations). A single simple `ls` or `stat` may also take glob operands, but not variables, substitutions, wrappers or other shell structure. Tainted searches cannot recurse, search a directory with `rg`, omit `rg` path operands, or use value-taking options other than `-e`/`--regexp`. Every other tainted command is refused, including variables, command substitution, globs for content readers, loops, conditionals, pipes, redirections, here-strings, here-documents, wrappers, `bash -c`, `eval` and transfer tools. Shell-option changes are checked even without a protected stem: modifying `shopt`, `setopt`, `unsetopt` and `emulate` are refused. `extglob` is refused as an option, not merely as text. Shell invocation `-o`/`-O` options, including clustered flags, must name a supported option. Expanded `set` arguments are refused. Only `set` flags `e`, `u`, `x`, `f`, `v`, `E`, `T` and named options `errexit`, `nounset`, `pipefail`, `xtrace`, `verbose`, `noglob`, `errtrace`, `functrace` (including their `+` forms) are supported. The message names the stem: list the directory with `ls`, then name exact non-credential paths, or use `rg -l PATTERN literal-file`. Narrowing to safe literal files is supported remediation, not a workaround; disguising the same secret read behind a variable, glob, wrapper, script or alias remains prohibited. Commands without a stem keep the full analysis. In that analysis a variable can hold any value the command assigns to it anywhere, a positional parameter or an unquoted expansion with glob or space characters is unknown, and an unknown file operand is refused. Residual classes include **shell glob grammar across bash and zsh, option toggles, option arity and quote concatenation**, as well as runtime-generated names, inherited state, filesystem indirection, user-defined commands, external programs and scripts, and searches without a named protected path. These classes are not modeled exhaustively. Use OS-level sandboxing or file permissions, harness isolation and least privilege as the primary boundary. Token files and key-extension globs (`*.key`, `*.jks`) are refused only through the listed reader, input, `dd` and transfer commands; see [`secrets.md`](../rules/secrets.md) |
15
+ | Hard block | `PreToolUse` on `Bash` | `scripts/cratis-guard-secrets.sh` | zero; parses only commands that mention a credential-bearing tool or file | exits **2** — the guard is a **best-effort, defense-in-depth text filter, NOT a sandbox**: it refuses some harmless commands rather than model the whole shell. Real protection requires **OS-level sandboxing or file permissions**. A command is *tainted* when a protected file-name stem appears in any token, including option values, in any letter case, after quotes, backslashes and line continuations are removed. Only search regex text is exempt: `-e`/`--regexp` values, or the first operand when neither `-e` nor `-f` is present. `-f`/`--file` values and all other operands are paths, not exempt patterns. The stems are `.env`, `.pem`, `.p12`, `.pfx`, `id_rsa`, `id_ed25519`, `id_ecdsa`, `id_dsa`, `.netrc`, `.npmrc`, `.pgpass`, `.pypirc`, `.git-credentials`, `.kube/`, `kubeconfig`, `credentials`, `.docker/`, `/environ` and `run/secrets`. The `.env` stem is a whole-stem rule: a letter or digit right after it releases the word (`Org.DS.EnvironmentalReporting`, `Environments.Specs`, `a.environment.txt`), while `.env`, `.env.local`, `.env_local`, `.env-prod`, `app.env` and `.envrc` stay protected, as do named copies such as `app.env.old`, `prod.env.local` and `app.env~` unless the name ends in `.example`, `.sample`, `.template`, `.dist` or `.defaults`, or in a source, documentation, project, build or markup extension (`.csproj`, `.sln`, `.props`, `.targets`, `.css`, `.html`, `.razor`, `.resx`, `.xaml` and similar); `.json`, `.yaml`, `.xml`, `.config`, `.ini`, `.txt` and extensionless names stay protected. Stars, question marks, bracket expressions and grouped pathname patterns count as the characters they can match when the pattern retains at least two literal stem characters. For `credentials` only, an embedded occurrence in a longer directory component or a recognized source, documentation, project, build or markup filename (for example `Specs/for_ApplicationCredentials/a.cs`, `RecordingCredentials.ts`, `credentials.md` or `Credentials.csproj`) is not a stem hit. Source extensions include `.ts`, `.tsx`, `.js`, `.jsx`, `.mjs`, `.cjs`, `.cs`, `.fs`, `.vb`, `.kt`, `.kts`, `.java`, `.go`, `.ex`, `.exs`, `.py`, `.rb`, `.rs`, `.swift`, `.md` and `.mdx`; the build/markup extensions above also qualify. Only resolved literal path words qualify: variables, command substitution, backticks, unquoted globs and brace expansion never receive the source-filename exemption. Exact `credentials`, non-source `credentials.*` and a `credentials/` component remain protected. Secret-carrier extensions (`.json`, `.yaml`, `.yml`, `.xml`, `.ini`, `.toml`, `.txt`, `.conf`, `.properties`, `.config`) do not qualify; an inner carrier suffix such as `credentials.json.ts` stays protected, as do `secrets.yaml`, `secrets.yml` and their dotted copies. `Credentials.ts.bak` is not source, but remains an allowed literal read and a non-secret path for Git operations. A source destination never releases a secret copy source (`cp credentials.json x.ts`). Other protected patterns, including environment files, private keys and kubeconfigs, retain their classification. Literal path-only `git add`, `git checkout` (including `--ours`/`--theirs`), `git restore`, `git rm`, `git mv`, `git diff`, `git log` and `git show` accept non-secret repository paths regardless of extension or credential vocabulary, including `-- <path>` and `HEAD:<path>`. This exemption applies only to positional operands and uses a strict allowlist, not a Git grammar parser: a plain relative path containing only letters, digits, `.`, `_`, `/` and `-`, or an object operand with exactly one colon in `rev:path`. Tokens beginning with `-` never receive the path exemption; both the original option-looking word and its extracted value are checked for sensitive file patterns. Long attached values (`--option=value`), short attached values (`-Fvalue`, `-ovalue`) and separated values receive the same sensitive-file checks, even when an option-looking token follows `--`; secret values such as `token` or `.env` remain refused. The revision may contain only those same characters with an optional trailing `~N` or `^N` (digits required); the path must satisfy the plain-path rule. Absolute paths, `~`, `..` path components, braces, multiple colons, index-stage syntax, pathspec magic, `--no-index` and unresolved expansions receive no Git exemption and fall through to the conservative checks. Secret-file classification always applies to the allowed path component; unsupported operands retain their original spelling for conservative component and protected-stem checks instead of guessing Git's revision/path boundary. Known source credential directories remain usable only after protected ancestor checks; actual secret-file patterns remain refused even behind these prefixes (`git show :0:id_rsa`, `git diff -- ':(literal).envrc'`, `git show HEAD:.env`, `git diff -- credentials.json`, `git add .env`). Unresolved expansions never receive this Git exemption: `cat Cre$(echo 'dentials.json x').cs`, its backtick variant and `git show HEAD:Cre$(echo dentials.json)` are refused rather than inferred to be source paths. A command is also tainted when an assignment value or any expanded word can contain a stem. A tainted command runs only when it is a single simple command with every word literal: `cat`, `head`, `tail`, `less`, `more`, `wc`, `grep`, `egrep`, `fgrep` or `rg` of paths that are not protected (such as `cat .env.example`); `test` of literal paths; or `cp SOURCE DEST` with no options and a source that is not protected (for example, `cp .env.example example.txt`; the shell-write guard separately refuses `.env` destinations). A single simple `ls` or `stat` may also take glob operands, but not variables, substitutions, wrappers or other shell structure. Tainted searches cannot recurse, search a directory with `rg`, omit `rg` path operands, or use value-taking options other than `-e`/`--regexp`. Every other tainted command is refused, including variables, command substitution, globs for content readers, loops, conditionals, pipes, redirections, here-strings, here-documents, wrappers, `bash -c`, `eval` and transfer tools. Shell-option changes are checked even without a protected stem: modifying `shopt`, `setopt`, `unsetopt` and `emulate` are refused. `extglob` is refused as an option, not merely as text. Shell invocation `-o`/`-O` options, including clustered flags, must name a supported option. Expanded `set` arguments are refused. Only `set` flags `e`, `u`, `x`, `f`, `v`, `E`, `T` and named options `errexit`, `nounset`, `pipefail`, `xtrace`, `verbose`, `noglob`, `errtrace`, `functrace` (including their `+` forms) are supported. The message names the stem: list the directory with `ls`, then name exact non-credential paths, or use `rg -l PATTERN literal-file`. Narrowing to safe literal files is supported remediation, not a workaround; disguising the same secret read behind a variable, glob, wrapper, script or alias remains prohibited. Commands without a stem keep the full analysis. In that analysis a variable can hold any value the command assigns to it anywhere, a positional parameter or an unquoted expansion with glob or space characters is unknown, and an unknown file operand is refused. Residual classes include **shell glob grammar across bash and zsh, option toggles, option arity and quote concatenation**, as well as runtime-generated names, inherited state, filesystem indirection, user-defined commands, external programs and scripts, and searches without a named protected path. These classes are not modeled exhaustively. Use OS-level sandboxing or file permissions, harness isolation and least privilege as the primary boundary. A `jq`, `yq`, `gojq`, `jaq`, `awk`, `gawk`, `mawk`, `nawk` or `busybox awk` command is refused like `env` and `printenv` when any of its words, after quote and backslash removal, holds `env`, `ENV`, `ENVIRON`, `strenv`, `envsubst`, `getenv`, `PROCINFO` or `SYMTAB` as a whole token (so a field named `env` is refused while `environment` and `envelope` are readable); the flag layout is not parsed, and programs read from a file (`jq -f`, `awk -f`) or built from variables are not inspected. Token files and key-extension globs (`*.key`, `*.jks`) are refused only through the listed reader, input, `dd` and transfer commands; see [`secrets.md`](../rules/secrets.md) |
16
16
  | Hard block | `PreToolUse` on `Bash` | `scripts/cratis-guard-pr-body.sh` | fetches shared rules only for `gh pr create/edit` | exits **2** for inline bodies, invalid notes or conflicting release labels; warns and allows when offline with no cache |
17
17
  | Cleanup of delivered work | `PostToolUse` on `Bash` (`gh pr merge`, `git pull/merge/worktree`) and `SessionStart` (Pi: `tool_result` and `session_start`) | `scripts/cratis-cleanup-worktrees.sh --hook` | zero when the command is unrelated | never blocks; removes delivered worktrees and branches, reports what it kept |
18
18
  | Quality gate (Claude) | `Stop` | `scripts/cratis-quality-gate.sh` | one build/test run, only when relevant files changed | exits **2** — the turn does not end |
@@ -34,6 +34,29 @@ searches with secret/certificate/key-like prefixes also remain blocked. For ripg
34
34
  symlinks, not filename-only mode. Literal directory checks retain the process-cwd fallback when the
35
35
  payload omits cwd; glob probing does not. Filesystem check/use races remain: this is not a sandbox.
36
36
 
37
+ The shell-write guard classifies **write-target words**, not every word. It lexes the command into
38
+ simple commands. When every command is a reviewed reader or staging verb (`cat`, `head`, `tail`, `wc`,
39
+ `ls`, `rg`, `grep`, `echo`, `git status|diff|log|show|add|commit`, `git ls-files`, `jq`, read-only
40
+ `awk`, and the like) with no redirect, the words of those commands are not classified, so braces,
41
+ brackets and filter text in a read are not refused. Redirect targets, `git commit -F`, `cd` segments and
42
+ every word of any command outside the reviewed set are always classified, and a command the lexer
43
+ cannot parse (expansions, backticks, parentheses, braces, heredocs, unterminated quotes) falls back to
44
+ classifying the whole text, fail-closed. Admissions beyond plain reads, each with its limit:
45
+ `jq` takes no value-taking option, so its filter is a plain operand; `awk` is read-only only as
46
+ `awk [-F sep] 'program' files` with no `>`, `|`, `@`, `system`, `getline`, `close` or `fflush` in the
47
+ program (conservative: `$1 > 5` is refused); a word-leading `*` or `?` glob is accepted only for
48
+ `cat`, `head`, `tail`, `wc`, `ls`, `grep`, `egrep`, `fgrep` and `git ls-files`, and a file named like an
49
+ option can still change what those print, never what they write; and exactly
50
+ `node .cratis/ai/hooks/scripts/cratis-check-pr.mjs` (options `--body-file`, `--label`, `--add-label`,
51
+ `--remove-label`, `--pr`, `--base`, `--repo` with a plain value, and `--strict`) and
52
+ `bash .cratis/ai/hooks/scripts/cratis-cleanup-worktrees.sh` (`--dry-run`, `--quiet`, `--no-fetch`) may
53
+ run: the path must match as one literal word (no `./`, `..`, absolute, variable or glob spelling), nothing
54
+ is admitted after a `cd`, and writes to those files stay refused. The working directory decides which
55
+ copy runs. A write-target word with expansion syntax (`$`, backtick, `~`, parentheses or braces) is judged by every
56
+ suffix that follows a slash in it (`$PWD/.cratis/x` and `~+/.cratis/x` are treated as `.cratis/x` in the working
57
+ directory), without parsing the expansion, and refused if a suffix is protected, which includes a read of a protected path through a variable. This is a
58
+ best-effort lexical check, not enforcement: a variable holding the whole path still passes.
59
+
37
60
  The shell-write reference scan keeps conservative leading-dot intersections: a tool named `Bash`,
38
61
  `SHELL`, and the hook process's options do not establish the execution shell's options. Globbed writes
39
62
  therefore remain blocked. Read operands under protected paths are not write targets: `rg -n`/`-l`,
@@ -116,6 +116,15 @@ function stem_boundary(t, start, finish, stem, nonliteral, a, b, before, afte
116
116
  if (nonliteral == "expanding") literal = t !~ /[][?*()`~^\001-\007]/
117
117
  else literal = !nonliteral && t !~ /[][?*{}()$`~^\001-\007]/
118
118
  if (stem == "/environ" && substr(t, finish + 1, 1) ~ /[a-z0-9_]/) return 0
119
+ # `.env` followed by a letter or digit is part of a longer word (Org.EnvironmentalReporting); `.envrc` stays protected.
120
+ # Allowlist: the boundary is released only when the stem is the literal text and the rest of its path component
121
+ # is plain literal characters. Any expansion, quote, escape, glob or brace there may still resolve to `.envrc`.
122
+ if (stem == ".env" && substr(t, finish + 1, 1) ~ /[a-z0-9]/ && substr(t, finish + 1) !~ /^rc([^a-z0-9]|$)/ &&
123
+ substr(t, start, finish - start + 1) == ".env") {
124
+ component = substr(t, finish + 1)
125
+ sub(/[\/ \t\n].*$/, "", component)
126
+ if (component ~ /^[a-z0-9._-]*$/) return 0
127
+ }
119
128
  if (stem ~ /^\.(key|jks|keystore|kdbx)$/) {
120
129
  if (substr(t, finish + 1, 1) ~ /[a-z0-9_-]/) return 0
121
130
  # Ambiguous key words are credential extensions only at the end of a literal filename.
@@ -132,9 +141,10 @@ function stem_boundary(t, start, finish, stem, nonliteral, a, b, before, afte
132
141
  component = substr(t, left, right - left + 1)
133
142
  if (literal && component !~ /^credentials([.]|$)/ && substr(t, right + 1, 1) == "/") return 0
134
143
  # Never infer a source file from a partial component or an expansion. JSON is not source.
135
- if (literal && code_file(component)) return 0
144
+ if (literal && !nonliteral && (code_file(component) || build_file(component)) &&
145
+ component !~ /credential.*\.(json|yaml|yml|xml|ini|toml|txt|conf|properties|config)([.]|$)/) return 0
136
146
  # The singular word is ordinary vocabulary; it marks a protected file only in credential JSON names.
137
- if (stem == "credential" && literal && component !~ /credential[^\/]*\.json[.]*$/) return 0
147
+ if (stem == "credential" && literal && component !~ /credential[^\/]*\.json([.]|$)/) return 0
138
148
  }
139
149
  before = substr(t, a - 1, 1); after = substr(t, b + 1)
140
150
  return !(before == "$" || before == "-" || (before == "{" && substr(t, a - 2, 1) == "$") || after ~ /^(=|\+=)/)
@@ -300,7 +310,55 @@ function git_metadata(words, count, subcommand, k, w, ended, summary) {
300
310
  }
301
311
  return subcommand != "diff" || summary
302
312
  }
313
+ # Path-only Git operations do not turn credential vocabulary into a secret filename.
314
+ # Exempt only plain relative paths or one-colon object specs with a simple ref.
315
+ # Never interpret complex Git grammar; keep the original operand for conservative checks.
316
+ function git_path_kind(w, pathspec, repo_only, parts, count, k, kind, path, allowed, option, directory) {
317
+ option = w ~ /^-/
318
+ if (option) {
319
+ kind = sensitive_path(w)
320
+ if (kind != "") return kind
321
+ }
322
+ if (w ~ /^--[^=]*=/) sub(/^--[^=]*=/, "", w)
323
+ else if (w ~ /^-[A-Za-z].+/) sub(/^-[A-Za-z]=?/, "", w)
324
+ count = split(w, parts, ":")
325
+ path = w
326
+ allowed = !option && count == 1
327
+ if (!option && !pathspec && count == 2 && parts[1] ~ /^[A-Za-z0-9_.\/-]+([~^][0-9]+)?$/) {
328
+ path = parts[2]
329
+ allowed = 1
330
+ }
331
+ allowed = allowed && path ~ /^[A-Za-z0-9_.\/-]+$/ && path !~ /^\// && path !~ /(^|\/)\.\.(\/|$)/
332
+ if (repo_only && !allowed) return "an operand outside the Git path allowlist"
333
+ if (allowed) w = path
334
+ directory = allowed && tolower(base(w)) == "credentials" && tolower(w) !~ /(^|\/)\.aws\/credentials$/ && directory_operand(w)
335
+ kind = sensitive_path(w)
336
+ if (kind != "" && !(directory && kind == "a credentials file")) return kind
337
+ # Inspect every component without guessing where unsupported revision/pathspec syntax ends.
338
+ count = split(w, parts, /[\/:]/)
339
+ for (k = 1; k <= count; k++) {
340
+ if ((k == count && index(w, ":") == 0) || (k < count && tolower(parts[k]) == "credentials")) continue
341
+ kind = sensitive_path(parts[k])
342
+ if (kind != "") return kind
343
+ }
344
+ if (!allowed && stem_scan(w, "raw") != "") return "a protected Git operand"
345
+ return ""
346
+ }
347
+ function git_paths(A, M, n, k, ended, pathspec) {
348
+ if (A[1] != "git" || A[2] !~ /^(add|checkout|restore|rm|mv|diff|log|show)$/) return 0
349
+ for (k = 1; k <= n; k++) {
350
+ if (expands(A[k], M[k]) || !literal_word(A[k], M[k]) || A[k] ~ /[*?\[]/) return 0
351
+ if (k <= 2) continue
352
+ if (!ended && A[k] == "--") { ended = 1; continue }
353
+ if (!ended && A[2] == "diff" && A[k] ~ /^--no-index($|=)/) return 0
354
+ pathspec = ended || A[2] ~ /^(add|checkout|restore|rm|mv)$/
355
+ # Options are checked for sensitive values but are never positional path exemptions.
356
+ if (git_path_kind(A[k], pathspec, A[k] !~ /^-/) != "") return 0
357
+ }
358
+ return 1
359
+ }
303
360
  function literal_shape(A, M, n, k, j, b, words, count, pattern, ended, w, paths, flags) {
361
+ if (git_paths(A, M, n)) return 1
304
362
  if (metadata_shape(A, M, n)) return 1
305
363
  delete words
306
364
  for (k = 1; k <= n; k++) {
@@ -378,12 +436,14 @@ function split_scan(w, m, k, r, hit) {
378
436
  }
379
437
  return ""
380
438
  }
381
- function end_cmd( k, m, w, j, hit, exempt) {
439
+ function end_cmd( k, m, w, j, hit, exempt, path_git) {
382
440
  flush_word()
383
441
  if (nw > 0) {
384
442
  commands++
385
443
  regex_slots(W, 1, nw)
444
+ path_git = git_paths(W, WM, nw)
386
445
  for (k = 1; k <= nw; k++) {
446
+ if (path_git && W[k] !~ /^-/) continue
387
447
  if (is_assign(W[k])) set_var(W[k], WM[k])
388
448
  exempt = (k in RP) && !WU[k]
389
449
  if (exempt && RP[k] < 0) continue
@@ -396,7 +456,14 @@ function end_cmd( k, m, w, j, hit, exempt) {
396
456
  }
397
457
  if (!exempt && expands(W[k], WM[k])) {
398
458
  resolve(W[k], WM[k])
399
- for (j = 1; j <= nalt; j++) { hit = stem_scan(ALT[j], "resolved"); if (TAINT == "") TAINT = hit }
459
+ for (j = 1; j <= nalt; j++) {
460
+ w = ALT[j]
461
+ if (w ~ /[\001\003]/) {
462
+ gsub(/[\001\003]/, "*", w)
463
+ hit = stem_scan(w, "raw", "expanding")
464
+ } else hit = stem_scan(w, "resolved")
465
+ if (TAINT == "") TAINT = hit
466
+ }
400
467
  }
401
468
  }
402
469
  if (!literal_shape(W, WM, nw)) simple_ok = 0
@@ -642,7 +709,9 @@ function skipopts(A, s, n, vals) {
642
709
  function is_assign(w) { return w ~ /^[A-Za-z_][A-Za-z0-9_]*(\[[^]]*\])?\+?=/ }
643
710
 
644
711
  # ── file classification for the reader commands ──
645
- function code_file(b) { return b ~ /\.(cs|ts|tsx|js|jsx|mjs|cjs|go|py|java|kt|rs|md)$/ }
712
+ function code_file(b) { return b ~ /\.(cs|fs|vb|ts|tsx|js|jsx|mjs|cjs|go|py|java|kt|kts|ex|exs|rb|rs|swift|md|mdx)$/ }
713
+ # Build and markup files cannot hold values, so a dotted Env segment in their names (Cratis.Env.Tool.csproj) is not an env copy.
714
+ function build_file(b) { return b ~ /\.(csproj|fsproj|vbproj|sln|slnx|props|targets|css|scss|less|html|htm|razor|cshtml|resx|xaml)$/ }
646
715
  # A design-token file is not a credential: a stylesheet, or a file under a design, theme or style directory, is
647
716
  # fine unless it sits in a secrets or credentials directory. A bare token.json (an OAuth refresh-token file) is not.
648
717
  function token_ok(l, b) {
@@ -654,13 +723,17 @@ function sensitive_path(w, l, b) {
654
723
  l = tolower(w); b = l; sub(/.*\//, "", b)
655
724
  if (l ~ /(^|\/)\.kube\// || b == "kubeconfig" || b ~ /\.kubeconfig$/) return "a kubeconfig"
656
725
  if (b ~ /^\.env/ || b ~ /\.env$/) { if (b ~ /\.(example|sample|template|dist|defaults?)$/) return ""; return "an .env file" }
726
+ # A named copy or variant (app.env.old, prod.env.local, app.env~) is protected like the file itself; templates and source files are not.
727
+ if (b ~ /.\.env[.~]/ && b !~ /\.(example|sample|template|dist|defaults?)$/ && !code_file(b) && !build_file(b)) return "an .env file"
657
728
  # Unambiguous credential extensions also protect disguised source suffixes; ambiguous words
658
729
  # such as Signing.Key.cs are source unless the credential extension is final.
659
730
  if (b ~ /\.(pem|p12|pfx)([.]|$)/ || b ~ /\.(key|jks|keystore|kdbx)[.]*$/) return "a key or certificate file"
660
731
  if (b == "id_rsa" || b == "id_ed25519" || b == "id_ecdsa" || b == "id_dsa") return "a private key"
661
732
  if (b ~ /(^|[._-])tokens?($|[._-])/ && !code_file(b) && !token_ok(l, b)) return "a token file"
662
733
  if (b == ".netrc" || b == ".npmrc" || b == ".pgpass" || b == ".pypirc" || b == ".git-credentials") return "a credentials file"
663
- if (b == "credentials" || b ~ /credential.*\.json[.]*$/) return "a credentials file"
734
+ if (b == "credentials" || b ~ /credential.*\.json([.]|$)/ ||
735
+ b ~ /credentials.*\.(yaml|yml|xml|ini|toml|txt|conf|properties|config)([.]|$)/ ||
736
+ b ~ /secrets\.ya?ml([.]|$)/) return "a credentials file"
664
737
  if (l ~ /\.docker\/config\.json$/) return "the Docker registry credentials"
665
738
  if (l ~ /\/proc\/[^\/]*\/environ$/) return "a process environment"
666
739
  if (l ~ /^\/(var\/)?run\/secrets\//) return "mounted secrets"
@@ -1268,14 +1341,31 @@ function scan_short(w, shortvals, sed_like, i, c, last) {
1268
1341
  if (sed_like && c == "i") return
1269
1342
  }
1270
1343
  }
1344
+ function report_operand(A, k, b, filenames, kind) {
1345
+ kind = operand_kind(A, k, 0, filenames)
1346
+ if (kind != "" && matched_file != "") report(b " of " kind " (" matched_file ") prints credentials", "list the directory with ls, then name the exact files; for an env template read the .env.example")
1347
+ else if (kind != "" && via_pattern) report(b " of a glob that may match " kind " prints credentials", "list the directory with ls, then name the exact files; for an env template read the .env.example")
1348
+ else if (kind != "") report(b " of " kind " prints credentials", "name the file and the key you need in your report; ask the user to confirm a value instead of printing it; for an env template read the .env.example")
1349
+ }
1350
+ # A jq, yq or awk program that reads the process environment prints every variable, like env and printenv do.
1351
+ # Every word of the command is judged, with quotes and backslashes removed, so no flag or subcommand layout is parsed:
1352
+ # an environment-access identifier (env, ENV, ENVIRON, strenv, envsubst, getenv, PROCINFO, SYMTAB) as a whole token refuses the command.
1353
+ function env_program(b, p, t) {
1354
+ gsub(/[\\"']/, "", p)
1355
+ t = " " p " "
1356
+ if (t !~ /[^A-Za-z0-9_](env|ENV|ENVIRON|strenv|envsubst|getenv|PROCINFO|SYMTAB)[^A-Za-z0-9_]/) return
1357
+ report(b " program reads the process environment, which can hold credentials", "name one non-credential variable with printenv NAME, or test existence with [ -n \"${NAME:-}\" ] && echo set")
1358
+ }
1271
1359
  function reader(A, s, n, b, k, w, mode, havepat, need, afterdd, kind, valued, valued2, shortvals, filenames) {
1272
1360
  b = base(A[s]); mode = ""; valued = " "; valued2 = " "; shortvals = ""
1361
+ if (b == "busybox") { if (base(A[s + 1]) == "awk") reader(A, s + 1, n); return }
1362
+ if (b ~ /^(awk|gawk|mawk|nawk|jq|yq|gojq|jaq)$/) for (k = s + 1; k <= n; k++) env_program(b, A[k])
1273
1363
  if (b ~ /^(rg|grep|egrep|fgrep)$/) {
1274
1364
  for (k = s + 1; k <= n; k++) if (A[k] == "-l" || (b != "rg" && A[k] == "-L") || A[k] ~ /^--files-with(out)?-match(es)?$/) filenames = 1
1275
1365
  for (k = s + 1; k <= n; k++) if (A[k] ~ /^-/ && ((b == "rg" && A[k] == "-L") || A[k] !~ /^(-[lL]|--files-with(out)?-match(es)?|--|-e|-F|--fixed-strings)$/)) filenames = 0
1276
1366
  }
1277
1367
  if (b ~ /^(grep|egrep|fgrep|rg|ag)$/) { mode = "pattern"; shortvals = (b ~ /^(grep|egrep|fgrep)$/) ? "mABCdD" : (b == "rg") ? "mABCdjEMrgtT" : "ABCGgmpW"; valued = " --glob --type --type-not --max-count --include --exclude --exclude-dir --context --after-context --before-context --max-depth --threads " }
1278
- else if (b ~ /^(sed|awk|gawk|jq|yq)$/) { mode = "script"; shortvals = "vF"; valued = " --indent "; valued2 = " --arg --argjson --slurpfile --rawfile " }
1368
+ else if (b ~ /^(sed|awk|gawk|mawk|nawk|jq|yq|gojq|jaq)$/) { mode = "script"; shortvals = "vF"; valued = " --indent "; valued2 = " --arg --argjson --slurpfile --rawfile " }
1279
1369
  # The first operand is the pattern or script unless -e/-f/--regexp/--file/--expression supplies it; only the rest are files.
1280
1370
  havepat = 0
1281
1371
  if (mode != "") for (k = s + 1; k <= n; k++) {
@@ -1291,14 +1381,15 @@ function reader(A, s, n, b, k, w, mode, havepat, need, afterdd, kind, valued,
1291
1381
  if (!afterdd && substr(w, 1, 1) == "-" && length(w) > 1) {
1292
1382
  if (mode != "" && w ~ /^-[a-zA-Z]/) { scan_short(w, shortvals, b == "sed"); if (sc_skip) k++ }
1293
1383
  else if (mode != "" && (w ~ /^--(regexp|file|expression|from-file)$/ || index(valued, " " w " "))) k++
1294
- else if (index(valued2, " " w " ")) k += 2
1384
+ else if (index(valued2, " " w " ")) {
1385
+ # --rawfile/--slurpfile name a file that is read, so it is judged like any other operand.
1386
+ if (w ~ /^--(raw|slurp)file$/ && k + 2 <= n) report_operand(A, k + 2, b, filenames)
1387
+ k += 2
1388
+ }
1295
1389
  continue
1296
1390
  }
1297
1391
  if (need) { need = 0; continue }
1298
- kind = operand_kind(A, k, 0, filenames)
1299
- if (kind != "" && matched_file != "") report(b " of " kind " (" matched_file ") prints credentials", "list the directory with ls, then name the exact files; for an env template read the .env.example")
1300
- else if (kind != "" && via_pattern) report(b " of a glob that may match " kind " prints credentials", "list the directory with ls, then name the exact files; for an env template read the .env.example")
1301
- else if (kind != "") report(b " of " kind " prints credentials", "name the file and the key you need in your report; ask the user to confirm a value instead of printing it; for an env template read the .env.example")
1392
+ report_operand(A, k, b, filenames)
1302
1393
  }
1303
1394
  }
1304
1395
 
@@ -1328,8 +1419,16 @@ function transfer_files(A, s, n, b, k, last, options, kind, w, eq, off, ended
1328
1419
  }
1329
1420
  }
1330
1421
  # Git grep reuses pattern/file separation; ls-files never reaches this content path.
1331
- function git_content(A, s, n, subcommand, k, w) {
1422
+ function git_content(A, s, n, subcommand, k, w, kind, ended, pathspec) {
1332
1423
  subcommand = A[s + 1]
1424
+ if (subcommand ~ /^(add|checkout|restore|rm|mv|diff|log|show)$/) {
1425
+ for (k = s + 2; k <= n; k++) {
1426
+ if (!ended && A[k] == "--") { ended = 1; continue }
1427
+ pathspec = ended || subcommand ~ /^(add|checkout|restore|rm|mv)$/
1428
+ kind = git_path_kind(A[k], pathspec)
1429
+ if (kind != "") report("git " subcommand " names " kind, "name only non-credential source files; list filenames with git ls-files")
1430
+ }
1431
+ }
1333
1432
  if (subcommand !~ /^(grep|show|cat-file)$/) return
1334
1433
  if (subcommand == "grep") reader(A, s + 1, n)
1335
1434
  for (k = s + 2; k <= n; k++) {
@@ -1432,7 +1531,7 @@ function analyze(A, s, n, w, b, k, names, p, config, get, show, first) {
1432
1531
  if (p && names == 0) report(b " -p/-x with no variable name prints the whole environment, including credentials", "printenv with the one non-credential variable you need")
1433
1532
  return
1434
1533
  }
1435
- if (b ~ /^(cat|tac|nl|less|more|head|tail|bat|batcat|strings|xxd|od|hexdump|cut|sort|uniq|base64|wc|grep|egrep|fgrep|rg|ag|sed|awk|gawk|jq|yq)$/) {
1534
+ if (b ~ /^(cat|tac|nl|less|more|head|tail|bat|batcat|strings|xxd|od|hexdump|cut|sort|uniq|base64|wc|grep|egrep|fgrep|rg|ag|sed|awk|gawk|mawk|nawk|busybox|jq|yq|gojq|jaq)$/) {
1436
1535
  reader(A, s, n)
1437
1536
  for (k = 1; k <= nrt; k++) {
1438
1537
  if (REDIRECT_TOKENS[k] > n || operand_kind(A, REDIRECT_TOKENS[k], ROFF[k]) == "") continue
@@ -1459,8 +1558,8 @@ BEGIN {
1459
1558
  nprobe = split(".env .env.local .env.production .envrc id_rsa id_ed25519 id_ecdsa id_dsa credentials token token.json tokens.json github_token .netrc .npmrc .pypirc .pgpass .git-credentials kubeconfig", PROBE, " ")
1460
1559
  nprobe2 = split(".kube/config .aws/credentials .docker/config.json /proc/1/environ /run/secrets/token /var/run/secrets/token", PROBE2, " ")
1461
1560
  nextension = split("pem key p12 pfx jks keystore kdbx kubeconfig env", EXT, " ")
1462
- ndispatch = split("cat tac nl less more head tail bat batcat strings xxd od hexdump cut sort uniq base64 wc dd cp mv ln rsync scp tar zip shopt set setopt unsetopt emulate grep egrep fgrep rg ag sed awk gawk jq yq kubectl oc docker podman docker-compose gh vault aws az gcloud pulumi cratis printenv export declare typeset env bash sh zsh dash ksh eval", DN, " ")
1463
- nstem = split(".env .pem .key .p12 .pfx .jks .keystore .kdbx id_rsa id_ed25519 id_ecdsa id_dsa .netrc .npmrc .pgpass .pypirc .git-credentials .kube/ kubeconfig credentials credential .docker/ /environ run/secrets", STEM, " ")
1561
+ ndispatch = split("cat tac nl less more head tail bat batcat strings xxd od hexdump cut sort uniq base64 wc dd cp mv ln rsync scp tar zip shopt set setopt unsetopt emulate grep egrep fgrep rg ag sed awk gawk mawk nawk busybox jq yq gojq jaq kubectl oc docker podman docker-compose gh vault aws az gcloud pulumi cratis printenv export declare typeset env bash sh zsh dash ksh eval", DN, " ")
1562
+ nstem = split(".env .pem .key .p12 .pfx .jks .keystore .kdbx id_rsa id_ed25519 id_ecdsa id_dsa .netrc .npmrc .pgpass .pypirc .git-credentials .kube/ kubeconfig credentials credential secrets.yaml secrets.yml .docker/ /environ run/secrets", STEM, " ")
1464
1563
  CMD = ENVIRON["GS_COMMAND"]
1465
1564
  for (pass = 1; pass <= 2; pass++) {
1466
1565
  delete queue; queued = 0; qi = 0; delete seen; reports = ""