@cratis/pi 7.156.0 → 7.158.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.
|
@@ -108,6 +108,20 @@ script is blocked, write it with the edit/write tool and run the script file ins
|
|
|
108
108
|
Portable bracket classes are kept; ambiguous backslash-bearing classes are widened instead of passed
|
|
109
109
|
as invalid awk regexes.
|
|
110
110
|
|
|
111
|
+
**Allowlisted safe shapes (Cratis/AI#1076, #1153).** A command naming a protected file is admitted only when
|
|
112
|
+
it matches one of these shapes; everything else is refused. Each shape has sibling allow and refuse specs.
|
|
113
|
+
|
|
114
|
+
| Shape | Admitted | Still refused |
|
|
115
|
+
| --- | --- | --- |
|
|
116
|
+
| Source file whose name only contains a credential word (`RecordingCredentials.ts`) for `git add`, `diff`, `checkout`, `restore`, `rm`, `mv` | Files are classified by real secret patterns (whole file stems such as the env file family, key and certificate extensions, cloud and cluster config files), not by substring | Every real secret pattern in any case or subfolder, and index-stage forms (`:2:`, `:3:`) of them |
|
|
117
|
+
| Leading `NAME=value` before another allowlisted shape | A plain value on a name that does not change how programs load or resolve | Loader, path, shell, git and tool-config names, values naming a protected file, expansions |
|
|
118
|
+
| Quoted message, title or body of `git commit` and `gh pr\|issue create\|edit\|comment` | Literal quoted text is data | File-valued options (`-F`, `--file`, `--body-file`), substitutions, trailing positional paths |
|
|
119
|
+
| Here-document body | Quoted delimiter body, or an unquoted body without substitutions, fed to a plain consumer | Substitutions in an unquoted body, any body fed to an interpreter or shell (permanent: write a script file with the edit tool instead) |
|
|
120
|
+
|
|
121
|
+
A symbolic link, or a path below a linked directory, is followed through the working directory (bounded hops);
|
|
122
|
+
a chain that ends at a protected name, loops or cannot be followed is refused, so a source-looking link name
|
|
123
|
+
gives no exemption.
|
|
124
|
+
|
|
111
125
|
Literal `git ls-files` pathspecs are filename metadata, including `-s`/`--stage` and `--debug`,
|
|
112
126
|
so credential-worded source directories do not taint that single command. Literal non-verbose
|
|
113
127
|
`git status`, summary-only `git diff --stat`/`--numstat`/`--shortstat`/`--name-only`/`--name-status`,
|
|
@@ -335,7 +349,7 @@ allowances, not general shell execution permission. Output-to-file options such
|
|
|
335
349
|
`git diff --output=...` are never exempt, even with a non-protected destination on a line
|
|
336
350
|
that references a protected file.
|
|
337
351
|
|
|
338
|
-
`gh` (
|
|
352
|
+
`gh` (apart from the literal publish shape above), `ag`, `sort`, `uniq`, `cut`, `jq`, `yq`, `less`, `more`, `stat`,
|
|
339
353
|
`file`, `diff`, `cmp`, checksum tools, `realpath`, `dirname`, `basename`, `which` and `type`
|
|
340
354
|
are not on this list: their option surfaces are deliberately not analysed here.
|
|
341
355
|
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
# The guard is conservative: a command naming a protected file runs only as a single literal read or template
|
|
14
14
|
# copy, and other such commands must be split into literal calls. Names produced by programs, inherited values,
|
|
15
15
|
# aliases, functions, script files and recursive searches without named files remain outside its text analysis.
|
|
16
|
+
# Allowlisted safe shapes (each commented where it is implemented, each with specs): source-file names classified by
|
|
17
|
+
# real secret patterns, a leading plain NAME=VALUE, quoted commit and pull request text, literal here-document
|
|
18
|
+
# text, and link-target checks. Anything else naming a protected file is refused.
|
|
16
19
|
#
|
|
17
20
|
# Escape hatch for a human who authorized the read — set in the environment the agent harness was started
|
|
18
21
|
# from, never inside the command (an assignment in the command is ignored):
|
|
@@ -44,6 +47,78 @@ command_text="$(jq -r '.tool_input.command // empty' <<<"$input")" || parser_fai
|
|
|
44
47
|
# character: this list must stay a superset of the protected stems the parser can resolve.
|
|
45
48
|
probe=${command_text//\\$'\n'/}
|
|
46
49
|
probe=${probe//[\'\"\\]/}
|
|
50
|
+
# Allowlist for symbolic links: a literal word that is a link, or sits under a linked directory, is followed
|
|
51
|
+
# through the working directory, and the command is refused when the final target is a protected file. This
|
|
52
|
+
# only adds refusals; it never admits a command the text analysis below refuses. The word list is a plain
|
|
53
|
+
# split of the unquoted text, so it can miss a word the awk analysis would see, never the reverse.
|
|
54
|
+
protected_target_name() {
|
|
55
|
+
local lowered base
|
|
56
|
+
[ -d "$1" ] && return 1
|
|
57
|
+
lowered="$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')" || return 1
|
|
58
|
+
base="${lowered##*/}"
|
|
59
|
+
case "$base" in
|
|
60
|
+
.env.example|.env.sample|.env.template|.env.dist|.env.default|.env.defaults) return 1 ;;
|
|
61
|
+
.env|.env.*|*.env|.envrc|id_rsa|id_ed25519|id_ecdsa|id_dsa|*.pem|*.key|*.p12|*.pfx|*.jks|*.keystore|*.kdbx|.netrc|.npmrc|.pgpass|.pypirc|.git-credentials|kubeconfig|*.kubeconfig|credentials|credentials.json|secrets.yaml|secrets.yml|token|token.json|tokens.json|github_token) return 0 ;;
|
|
62
|
+
esac
|
|
63
|
+
case "/$lowered" in
|
|
64
|
+
*/.kube/*|*/.aws/credentials|*/.docker/config.json|/run/secrets/*|/var/run/secrets/*) return 0 ;;
|
|
65
|
+
esac
|
|
66
|
+
return 1
|
|
67
|
+
}
|
|
68
|
+
# Follows a chain of links one step at a time (bash 3.2, BSD readlink: no readlink -f, no realpath). Returns
|
|
69
|
+
# 0 when the chain ends at a protected name or cannot be followed, 1 when it is harmless.
|
|
70
|
+
link_chain_protected() {
|
|
71
|
+
local current="$1" hops=0 target parent
|
|
72
|
+
while [ -L "$current" ]; do
|
|
73
|
+
hops=$((hops + 1))
|
|
74
|
+
[ "$hops" -le 16 ] || return 0
|
|
75
|
+
target="$(readlink -- "$current")" || return 0
|
|
76
|
+
case "$target" in
|
|
77
|
+
/*) current="$target" ;;
|
|
78
|
+
*) parent="${current%/*}"; [ "$parent" != "$current" ] || parent=.; current="$parent/$target" ;;
|
|
79
|
+
esac
|
|
80
|
+
if protected_target_name "$current"; then return 0; fi
|
|
81
|
+
done
|
|
82
|
+
return 1
|
|
83
|
+
}
|
|
84
|
+
linked_protected_word() {
|
|
85
|
+
local word="$1" directory resolved logical
|
|
86
|
+
[ -n "$word" ] || return 1
|
|
87
|
+
case "$word" in
|
|
88
|
+
--*) return 1 ;;
|
|
89
|
+
-?*) word="${word#-?}"; [ -n "$word" ] || return 1 ;;
|
|
90
|
+
esac
|
|
91
|
+
if [ -L "$word" ]; then link_chain_protected "$word"; return; fi
|
|
92
|
+
case "$word" in */*) ;; *) return 1 ;; esac
|
|
93
|
+
directory="${word%/*}"; [ -n "$directory" ] || directory=/
|
|
94
|
+
[ -d "$directory" ] || return 1
|
|
95
|
+
resolved="$(cd -P -- "$directory" 2>/dev/null && pwd -P)" || return 1
|
|
96
|
+
logical="$(cd -- "$directory" 2>/dev/null && pwd)" || return 1
|
|
97
|
+
[ "$resolved" != "$logical" ] || return 1
|
|
98
|
+
resolved="$resolved/${word##*/}"
|
|
99
|
+
if protected_target_name "$resolved"; then return 0; fi
|
|
100
|
+
link_chain_protected "$resolved"
|
|
101
|
+
}
|
|
102
|
+
first_linked_word() {
|
|
103
|
+
local link_words link_word link_count=0
|
|
104
|
+
link_words="$(printf '%s' "$probe" | tr ';|&<>(){}=,' ' ')" || return 0
|
|
105
|
+
cd -- "$1" || return 0
|
|
106
|
+
set -f
|
|
107
|
+
for link_word in $link_words; do
|
|
108
|
+
link_count=$((link_count + 1))
|
|
109
|
+
# A command too long to check word by word is refused rather than partly checked.
|
|
110
|
+
if [ "$link_count" -gt 5000 ]; then printf '%s' "$link_word"; return 0; fi
|
|
111
|
+
if linked_protected_word "$link_word"; then printf '%s' "$link_word"; return 0; fi
|
|
112
|
+
done
|
|
113
|
+
}
|
|
114
|
+
link_cwd="$(jq -r '.cwd // empty' <<<"$input")" || parser_failed
|
|
115
|
+
if [ -n "$link_cwd" ] && [ -d "$link_cwd" ]; then
|
|
116
|
+
linked_word="$(first_linked_word "$link_cwd")" || parser_failed
|
|
117
|
+
if [ -n "$linked_word" ]; then
|
|
118
|
+
printf 'BLOCKED by cratis-guard-secrets: %s is a symbolic link or sits under one, and it resolves to a protected file. Use instead: name the real non-credential file; do not read a protected file through a link.\n' "$linked_word" >&2
|
|
119
|
+
exit 2
|
|
120
|
+
fi
|
|
121
|
+
fi
|
|
47
122
|
probe_lower="$(printf '%s' "$probe" | tr '[:upper:]' '[:lower:]')" || parser_failed
|
|
48
123
|
case "$probe_lower" in
|
|
49
124
|
*kubectl*|*printenv*|*env*|*docker*|*podman*|*"gh "*|*vault*|*pulumi*|*show-secret*|*aws*|*"az "*|*gcloud*|*kubeconfig*|*.kube*|\
|
|
@@ -357,9 +432,75 @@ function git_paths(A, M, n, k, ended, pathspec) {
|
|
|
357
432
|
}
|
|
358
433
|
return 1
|
|
359
434
|
}
|
|
360
|
-
|
|
435
|
+
# Allowlist: a leading NAME=VALUE assignment is admitted before an allowlisted shape only when the name is not
|
|
436
|
+
# one that changes how a program loads, resolves or runs, and the value is plain literal text naming no protected
|
|
437
|
+
# file. A value is never expanded here, so it cannot select what the command reads.
|
|
438
|
+
function safe_assign(w, m, k, name, value) {
|
|
439
|
+
k = index(w, "=")
|
|
440
|
+
if (k < 2 || length(m) != length(w)) return 0
|
|
441
|
+
name = substr(w, 1, k - 1); value = substr(w, k + 1)
|
|
442
|
+
if (name !~ /^[A-Z][A-Z0-9_]*$/) return 0
|
|
443
|
+
# Explicit list of presentation and locale names only; every other name, including any tool or loader
|
|
444
|
+
# configuration variable, is refused.
|
|
445
|
+
if (name !~ /^(NO_COLOR|FORCE_COLOR|CLICOLOR|CLICOLOR_FORCE|CI|COLUMNS|LINES|TZ|LANG|LC_ALL)$/) return 0
|
|
446
|
+
if (value !~ "^[A-Za-z0-9_.,:@%+/-]*$") return 0
|
|
447
|
+
return stem_scan(value, "raw") == ""
|
|
448
|
+
}
|
|
449
|
+
# Allowlist: a quoted value of a message or title option of `git commit` or `gh pr|issue create|edit|comment`
|
|
450
|
+
# is data, because the shell never runs it as a command and these commands only publish it. The value must be
|
|
451
|
+
# quoted throughout and free of expansion; command and backtick substitutions are already queued as nested
|
|
452
|
+
# commands and refuse the whole command. Path-valued options (-F, --file, --body-file, -C) are not in the
|
|
453
|
+
# table, so naming a protected file through them is still refused. Fills MDATA with the data word positions.
|
|
454
|
+
function data_value(w, m) {
|
|
455
|
+
if (w == "" || length(m) != length(w)) return 0
|
|
456
|
+
if (m !~ /[uUcC]/ && !expands(w, m)) return 1
|
|
457
|
+
return w !~ /^-/ && literal_word(w, m) && stem_scan(w, "raw") == ""
|
|
458
|
+
}
|
|
459
|
+
function data_option(w, m, nextw, nextm, k, eq) {
|
|
460
|
+
if (w ~ /^(-m|--message|--title|-t|--body|-b)$/) { if (!data_value(nextw, nextm)) return 0; MDATA[k + 1] = 1; return 2 }
|
|
461
|
+
eq = index(w, "=")
|
|
462
|
+
if (w ~ /^--(message|title|body)=/ && data_value(substr(w, eq + 1), substr(m, eq + 1)) && substr(m, 1, eq) !~ /[cC]/) { MDATA[k] = 1; return 1 }
|
|
463
|
+
return 0
|
|
464
|
+
}
|
|
465
|
+
function plain_value(w, m) { return w != "" && w !~ /^-/ && literal_word(w, m) && stem_scan(w, "raw") == "" }
|
|
466
|
+
function data_shape(A, M, n, k, step, w, numbers) {
|
|
467
|
+
delete MDATA
|
|
468
|
+
if (A[1] == "git" && A[2] == "commit") {
|
|
469
|
+
for (k = 3; k <= n; k++) {
|
|
470
|
+
w = A[k]
|
|
471
|
+
if (w ~ /^(-a|--all|-s|--signoff|-q|--quiet|-v|--verbose|-n|--no-verify|--allow-empty|--no-edit)$/) continue
|
|
472
|
+
if (w ~ /^-[asqnv]+m$/) { if (!data_value(A[k + 1], M[k + 1])) return 0; MDATA[++k] = 1; continue }
|
|
473
|
+
step = data_option(w, M[k], A[k + 1], M[k + 1], k)
|
|
474
|
+
if (step == 0 || (w ~ /^(-t|--title|-b|--body|--title=.*|--body=.*)$/)) return 0
|
|
475
|
+
k += step - 1
|
|
476
|
+
}
|
|
477
|
+
return 1
|
|
478
|
+
}
|
|
479
|
+
if (A[1] != "gh" || A[2] !~ /^(pr|issue)$/ || A[3] !~ /^(create|edit|comment)$/) return 0
|
|
480
|
+
for (k = 4; k <= n; k++) {
|
|
481
|
+
w = A[k]
|
|
482
|
+
if (w ~ /^(--draft|--fill|--no-maintainer-edit)$/) continue
|
|
483
|
+
if (w ~ /^[0-9]+$/ && !numbers++) continue
|
|
484
|
+
if (w ~ /^(--base|-B|--head|-H|--label|-l|--assignee|-a|--repo|-R|--milestone|--reviewer|-r|--project|-p)$/) {
|
|
485
|
+
if (!plain_value(A[k + 1], M[k + 1])) return 0
|
|
486
|
+
k++; continue
|
|
487
|
+
}
|
|
488
|
+
step = data_option(w, M[k], A[k + 1], M[k + 1], k)
|
|
489
|
+
if (step == 0 || w ~ /^(-m|--message|--message=.*)$/) return 0
|
|
490
|
+
k += step - 1
|
|
491
|
+
}
|
|
492
|
+
return 1
|
|
493
|
+
}
|
|
494
|
+
function literal_shape(A, M, n, k, j, b, words, count, pattern, ended, w, paths, flags, m) {
|
|
361
495
|
if (git_paths(A, M, n)) return 1
|
|
362
496
|
if (metadata_shape(A, M, n)) return 1
|
|
497
|
+
if (data_shape(A, M, n)) return 1
|
|
498
|
+
for (k = 1; k <= n && is_assign(A[k]); k++) if (!safe_assign(A[k], M[k])) return 0
|
|
499
|
+
if (k > 1 && k <= n) {
|
|
500
|
+
delete SA; delete SM
|
|
501
|
+
for (m = 0; k <= n; k++) { SA[++m] = A[k]; SM[m] = M[k] }
|
|
502
|
+
return literal_shape(SA, SM, m)
|
|
503
|
+
}
|
|
363
504
|
delete words
|
|
364
505
|
for (k = 1; k <= n; k++) {
|
|
365
506
|
if (is_assign(A[k]) || !literal_word(A[k], M[k])) return 0
|
|
@@ -517,7 +658,9 @@ function end_cmd( k, m, w, j, hit, exempt, path_git, paths_only) {
|
|
|
517
658
|
paths_only = nonreader(W, WM, nw)
|
|
518
659
|
regex_slots(W, 1, nw)
|
|
519
660
|
path_git = git_paths(W, WM, nw)
|
|
661
|
+
msg_shape = data_shape(W, WM, nw)
|
|
520
662
|
for (k = 1; k <= nw; k++) {
|
|
663
|
+
if (msg_shape && (k in MDATA)) continue
|
|
521
664
|
if (path_git && W[k] !~ /^-/) continue
|
|
522
665
|
if (is_assign(W[k])) set_var(W[k], WM[k])
|
|
523
666
|
if (paths_only && ((k in DATA) || sensitive_path(W[k]) == "")) continue
|
|
@@ -575,7 +718,44 @@ function cmdsub(s, i, n, start, depth, c, j) {
|
|
|
575
718
|
enqueue(substr(s, start, i - start))
|
|
576
719
|
return i + 1
|
|
577
720
|
}
|
|
578
|
-
|
|
721
|
+
# An unquoted here-document delimiter lets the shell run command and backtick substitutions in the body, so
|
|
722
|
+
# their text is analyzed like any other command. A quoted delimiter makes the body plain data.
|
|
723
|
+
function heredoc_substitutions(body, i, n, c, j) {
|
|
724
|
+
n = length(body); i = 1
|
|
725
|
+
while (i <= n) {
|
|
726
|
+
c = substr(body, i, 1)
|
|
727
|
+
if (c == "\\") { i += 2; continue }
|
|
728
|
+
if (c == "$" && substr(body, i + 1, 1) == "(") { i = cmdsub(body, i + 2, n); continue }
|
|
729
|
+
if (c == "`") {
|
|
730
|
+
complex = 1
|
|
731
|
+
j = index(substr(body, i + 1), "`")
|
|
732
|
+
if (j == 0) { enqueue(substr(body, i + 1)); break }
|
|
733
|
+
enqueue(substr(body, i + 1, j - 1)); i += j + 1; continue
|
|
734
|
+
}
|
|
735
|
+
i++
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
# Program text fed to an interpreter can read any file, so a body that names a protected file is refused.
|
|
739
|
+
# This stays a best-effort text check: the stems below are matched at word boundaries so ordinary program text
|
|
740
|
+
# (process.env.NAME, a key property) is not a finding.
|
|
741
|
+
function interpreter_hit(body, t, k, stem, from, p, before, after, kind) {
|
|
742
|
+
t = tolower(body)
|
|
743
|
+
for (k = 1; k <= ninterp; k++) {
|
|
744
|
+
stem = INTERP[k]; from = 1
|
|
745
|
+
while ((p = index(substr(t, from), stem)) > 0) {
|
|
746
|
+
p += from - 1
|
|
747
|
+
before = (p > 1) ? substr(t, p - 1, 1) : ""
|
|
748
|
+
after = substr(t, p + length(stem), 1)
|
|
749
|
+
kind = INTERP_KIND[k]
|
|
750
|
+
if (kind == "env" && before !~ /[]a-z0-9_)]/ && after !~ /[a-z0-9_]/) return stem
|
|
751
|
+
if (kind == "ext" && (after == "\"" || after == "\047" || after == "`")) return stem
|
|
752
|
+
if (kind == "name" && after !~ /[a-z0-9_]/) return stem
|
|
753
|
+
from = p + 1
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
return ""
|
|
757
|
+
}
|
|
758
|
+
function read_heredocs(s, i, n, h, e, line, cmp, body, hit) {
|
|
579
759
|
for (h = 1; h <= nheredoc; h++) {
|
|
580
760
|
body = ""
|
|
581
761
|
while (i <= n) {
|
|
@@ -587,12 +767,16 @@ function read_heredocs(s, i, n, h, e, line, cmp, body) {
|
|
|
587
767
|
body = body line "\n"
|
|
588
768
|
}
|
|
589
769
|
if (hd_shell) enqueue(body)
|
|
770
|
+
else {
|
|
771
|
+
if (!HDQ[h]) heredoc_substitutions(body)
|
|
772
|
+
if (hd_interp && (hit = interpreter_hit(body)) != "") { complex = 1; if (TAINT == "") TAINT = hit }
|
|
773
|
+
}
|
|
590
774
|
}
|
|
591
|
-
nheredoc = 0; hd_shell = 0
|
|
775
|
+
nheredoc = 0; hd_shell = 0; hd_interp = 0
|
|
592
776
|
return i
|
|
593
777
|
}
|
|
594
778
|
function tokenize(s, i, n, c, c2, j, dash, delim) {
|
|
595
|
-
n = length(s); i = 1; nw = 0; word = ""; wmask = ""; inword = 0; wquoted = 0; wplain = 0; wunquoted = 0; nheredoc = 0; hd_shell = 0; quote_boundary = 0
|
|
779
|
+
n = length(s); i = 1; nw = 0; word = ""; wmask = ""; inword = 0; wquoted = 0; wplain = 0; wunquoted = 0; nheredoc = 0; hd_shell = 0; hd_interp = 0; quote_boundary = 0
|
|
596
780
|
delete W; delete WP; delete WM
|
|
597
781
|
while (i <= n) {
|
|
598
782
|
c = substr(s, i, 1)
|
|
@@ -661,14 +845,15 @@ function tokenize(s, i, n, c, c2, j, dash, delim) {
|
|
|
661
845
|
flush_word(); i += 2; dash = 0
|
|
662
846
|
if (substr(s, i, 1) == "-") { dash = 1; i++ }
|
|
663
847
|
while (substr(s, i, 1) == " " || substr(s, i, 1) == "\t") i++
|
|
664
|
-
delim = ""
|
|
848
|
+
delim = ""; delim_quoted = 0
|
|
665
849
|
while (i <= n) {
|
|
666
850
|
c = substr(s, i, 1)
|
|
667
851
|
if (c ~ /[ \t\n;&|()<>]/) break
|
|
668
852
|
if (c != "\047" && c != "\"" && c != "\\") delim = delim c
|
|
853
|
+
else delim_quoted = 1
|
|
669
854
|
i++
|
|
670
855
|
}
|
|
671
|
-
nheredoc++; HD[nheredoc] = delim; HDDASH[nheredoc] = dash
|
|
856
|
+
nheredoc++; HD[nheredoc] = delim; HDDASH[nheredoc] = dash; HDQ[nheredoc] = delim_quoted
|
|
672
857
|
continue
|
|
673
858
|
}
|
|
674
859
|
if (c == "<") {
|
|
@@ -1603,6 +1788,7 @@ function analyze(A, s, n, w, b, k, names, p, config, get, show, first) {
|
|
|
1603
1788
|
}
|
|
1604
1789
|
if (expands(A[s], mask_of(A, s))) return dyn_command(A, s, n)
|
|
1605
1790
|
b = base(A[s])
|
|
1791
|
+
if (nheredoc > 0 && b ~ /^(node|nodejs|deno|bun|python[0-9.]*|ruby|perl|php|lua|osascript|pwsh|powershell|dotnet|java|jshell|rscript|tclsh|julia|groovy|tsx|ts-node)$/) hd_interp = 1
|
|
1606
1792
|
if (A[s] == "git") git_content(A, s, n)
|
|
1607
1793
|
shell_config(A, s, n, b)
|
|
1608
1794
|
collect_bindings(A, s, n, b)
|
|
@@ -1690,11 +1876,13 @@ BEGIN {
|
|
|
1690
1876
|
nprobe2 = split(".kube/config .aws/credentials .docker/config.json /proc/1/environ /run/secrets/token /var/run/secrets/token", PROBE2, " ")
|
|
1691
1877
|
nextension = split("pem key p12 pfx jks keystore kdbx kubeconfig env", EXT, " ")
|
|
1692
1878
|
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, " ")
|
|
1879
|
+
ninterp = split(".env|env .env.local|name .env.production|name .envrc|name id_rsa|name id_ed25519|name id_ecdsa|name id_dsa|name .netrc|name .npmrc|name .pgpass|name .pypirc|name .git-credentials|name kubeconfig|name .kube/|name .aws/|name .docker/config.json|name credentials.json|name secrets.yaml|name secrets.yml|name .pem|ext .key|ext .p12|ext .pfx|ext .jks|ext .keystore|ext .kdbx|ext", INTERP_SPEC, " ")
|
|
1880
|
+
for (i = 1; i <= ninterp; i++) { split(INTERP_SPEC[i], L, "|"); INTERP[i] = L[1]; INTERP_KIND[i] = L[2] }
|
|
1693
1881
|
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, " ")
|
|
1694
1882
|
CMD = ENVIRON["GS_COMMAND"]
|
|
1695
1883
|
for (pass = 1; pass <= 2; pass++) {
|
|
1696
1884
|
delete queue; queued = 0; qi = 0; delete seen; reports = ""
|
|
1697
|
-
nheredoc = 0; hd_shell = 0; commands = 0; complex = 0; simple_ok = 1; TAINT = ""
|
|
1885
|
+
nheredoc = 0; hd_shell = 0; hd_interp = 0; commands = 0; complex = 0; simple_ok = 1; TAINT = ""
|
|
1698
1886
|
enqueue(CMD)
|
|
1699
1887
|
while (qi < queued) { qi++; tokenize(queue[qi]) }
|
|
1700
1888
|
if (pass == 1 && bindings > 0) continue
|
|
@@ -421,8 +421,29 @@ function find_allowed( i, w, predicates) {
|
|
|
421
421
|
}
|
|
422
422
|
return predicates > 0
|
|
423
423
|
}
|
|
424
|
+
# Allowlist: `gh pr|issue create|edit|comment` publishes text, it never writes a repository file. Only a title or
|
|
425
|
+
# body given as a literal word is admitted; a file-valued option (--body-file, -F), an expansion, an escape or
|
|
426
|
+
# a glob refuses, and every other option value must be plain text.
|
|
427
|
+
function gh_publish_allowed( i, w) {
|
|
428
|
+
for (i = 4; i <= argc; i++) {
|
|
429
|
+
w = W[i]
|
|
430
|
+
if (globbed[i]) return 0
|
|
431
|
+
if (w ~ /^(--title|-t|--body|-b)$/) {
|
|
432
|
+
if (++i > argc || globbed[i] || W[i] ~ /[$`\\]/) return 0
|
|
433
|
+
continue
|
|
434
|
+
}
|
|
435
|
+
if (w ~ /^(--base|-B|--head|-H|--label|-l|--assignee|-a|--repo|-R|--milestone|--reviewer|-r|--project|-p)$/) {
|
|
436
|
+
if (++i > argc || W[i] !~ /^[A-Za-z0-9_.,:@%+\/-]+$/ || W[i] ~ /^-/ || W[i] ~ /(^|\/)\./) return 0
|
|
437
|
+
continue
|
|
438
|
+
}
|
|
439
|
+
if (w ~ /^(--draft|--fill)$/ || w ~ /^[0-9]+$/) continue
|
|
440
|
+
return 0
|
|
441
|
+
}
|
|
442
|
+
return 1
|
|
443
|
+
}
|
|
424
444
|
function gh_allowed( i, w, subcommand, read) {
|
|
425
445
|
subcommand = W[2] " " W[3]
|
|
446
|
+
if (subcommand ~ /^(pr|issue) (create|edit|comment)$/) return gh_publish_allowed()
|
|
426
447
|
read = subcommand ~ /^(repo (view|list)|issue (view|list|status)|pr (view|list|status|diff|checks)|release (view|list)|run (view|list|watch)|search (issues|prs|repos|commits|code))$/
|
|
427
448
|
if (W[2] != "api" && !read) return 0
|
|
428
449
|
for (i = W[2] == "api" ? 3 : 4; i <= argc; i++) {
|