@cratis/pi 7.170.5 → 7.170.6
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.
|
@@ -44,6 +44,11 @@ Reader glob probes skip directories only when decoded options establish a nonrec
|
|
|
44
44
|
unknown or recursive grep options keep directory matches conservative. Simple sed print/substitution
|
|
45
45
|
programs are data only without in-place edits, execution, or file writes; `-f` remains a file operand.
|
|
46
46
|
GitHub API endpoints are normalized before checking sensitive paths.
|
|
47
|
+
GitHub output filters (`--jq`/`-q`, `--template`/`-t`) may select response fields such as `.env`,
|
|
48
|
+
but may not read the process environment through `env` or `$ENV`, including within expressions.
|
|
49
|
+
Quoted strings and comments in jq filters remain data. Bundled filter flags are checked too;
|
|
50
|
+
`-t` is a title or subject only for `pr`/`issue`/`release` create/edit, `pr merge`, and
|
|
51
|
+
`ssh-key`/`gpg-key` add. API endpoint names never opt out of template checks.
|
|
47
52
|
|
|
48
53
|
The shell-write guard classifies **write-target words**, not every word. It lexes the command into
|
|
49
54
|
simple commands. When every command is a reviewed reader or staging verb (`cat`, `head`, `tail`, `wc`,
|
|
@@ -595,7 +595,18 @@ function sed_slots(A, s, n, i, w, program, explicit, ended, scripts) {
|
|
|
595
595
|
return scripts > 0
|
|
596
596
|
}
|
|
597
597
|
# Only fully modeled literal non-readers can distinguish data slots from paths.
|
|
598
|
-
function
|
|
598
|
+
function gh_reader_bundle(A, i, n, j, flag) {
|
|
599
|
+
for (j = 2; j <= length(A[i]); j++) {
|
|
600
|
+
flag = substr(A[i], j, 1)
|
|
601
|
+
if (flag ~ /^[icwd]$/) continue
|
|
602
|
+
if (flag != "q" && flag != "t") return 0
|
|
603
|
+
DATA[i] = 1
|
|
604
|
+
if (j == length(A[i])) { if (++i > n) return 0; DATA[i] = 1 }
|
|
605
|
+
return i
|
|
606
|
+
}
|
|
607
|
+
return i
|
|
608
|
+
}
|
|
609
|
+
function nonreader(A, M, n, i, w, first, read, nexti) {
|
|
599
610
|
delete DATA
|
|
600
611
|
for (i = 1; i <= n; i++) if (expands(A[i], M[i]) || index(A[i], "`") || A[i] ~ /^</) return 0
|
|
601
612
|
first = tolower(base(A[1]))
|
|
@@ -627,9 +638,11 @@ function nonreader(A, M, n, i, w, first, read) {
|
|
|
627
638
|
for (i = A[2] == "api" ? 3 : 4; i <= n; i++) {
|
|
628
639
|
w = A[i]
|
|
629
640
|
if (w ~ /^>/) { if (w == ">" || w == ">>") i++; continue }
|
|
641
|
+
if (w ~ /^--(jq|template)=/) { DATA[i] = 1; continue }
|
|
630
642
|
if (w ~ /^(--jq|-q|--template|-t)$/) { if (++i > n) return 0; DATA[i] = 1; continue }
|
|
631
643
|
if (w ~ /^(--json|--repo|-R|--limit|-L|--hostname|--header|-H)$/) { if (++i > n) return 0; DATA[i] = 1; continue }
|
|
632
644
|
if (A[2] == "api" && w ~ /^(--method|-X)$/) { if (++i > n || A[i] !~ /^(GET|HEAD)$/) return 0; continue }
|
|
645
|
+
if (w ~ /^-[^-]/) { nexti = gh_reader_bundle(A, i, n); if (!nexti) return 0; i = nexti; continue }
|
|
633
646
|
if (w ~ /^-/ && w !~ /^(--paginate|--slurp|--include|--silent|--log|--log-failed|--web)$/) return 0
|
|
634
647
|
if (A[2] != "api") DATA[i] = 1
|
|
635
648
|
}
|
|
@@ -885,7 +898,19 @@ function tokenize(s, i, n, c, c2, j, dash, delim) {
|
|
|
885
898
|
}
|
|
886
899
|
|
|
887
900
|
# ── option parsing shared by the CLIs: positionals P/PI, output format, -f/--format value, --raw ──
|
|
888
|
-
function
|
|
901
|
+
function gh_short_options(A, i, shortvals, output_filters, j, f, rest, value) {
|
|
902
|
+
for (j = 2; j <= length(A[i]); j++) {
|
|
903
|
+
f = substr(A[i], j, 1)
|
|
904
|
+
if (!index(shortvals, f)) continue
|
|
905
|
+
rest = substr(A[i], j + 1)
|
|
906
|
+
if (rest == "") value = A[++i]
|
|
907
|
+
else { value = rest; sub(/^=/, "", value) }
|
|
908
|
+
if (f == "q" || (f == "t" && output_filters == 1)) check_gh_filter(value)
|
|
909
|
+
return i
|
|
910
|
+
}
|
|
911
|
+
return i
|
|
912
|
+
}
|
|
913
|
+
function kparse(A, s, n, shortvals, output_filters, i, w, eq, key, val, f, rest) {
|
|
889
914
|
delete P; delete PI
|
|
890
915
|
np = 0; outfmt = ""; fmtval = ""; tmpl = ""; tmplfile = 0; dd = 0; raw = 0
|
|
891
916
|
for (i = s; i <= n; i++) {
|
|
@@ -894,7 +919,11 @@ function kparse(A, s, n, shortvals, i, w, eq, key, val, f, rest) {
|
|
|
894
919
|
if (substr(w, 1, 2) == "--") {
|
|
895
920
|
eq = index(w, "="); key = w; val = ""
|
|
896
921
|
if (eq) { key = substr(w, 1, eq - 1); val = substr(w, eq + 1) }
|
|
897
|
-
if (key == "--
|
|
922
|
+
if (output_filters && (key == "--jq" || key == "--template")) {
|
|
923
|
+
if (!eq) { i++; val = A[i] }
|
|
924
|
+
check_gh_filter(val)
|
|
925
|
+
}
|
|
926
|
+
else if (key == "--output") { if (!eq) { i++; val = A[i] } outfmt = tolower(val) }
|
|
898
927
|
else if (key == "--format") { if (!eq) { i++; val = A[i] } fmtval = val }
|
|
899
928
|
else if (key == "--template") {
|
|
900
929
|
if (!eq) { i++; val = A[i] } tmpl = val
|
|
@@ -906,6 +935,7 @@ function kparse(A, s, n, shortvals, i, w, eq, key, val, f, rest) {
|
|
|
906
935
|
continue
|
|
907
936
|
}
|
|
908
937
|
if (substr(w, 1, 1) == "-" && length(w) > 1) {
|
|
938
|
+
if (output_filters) { i = gh_short_options(A, i, shortvals, output_filters); continue }
|
|
909
939
|
f = substr(w, 2, 1); rest = substr(w, 3)
|
|
910
940
|
if (f == "o") {
|
|
911
941
|
if (rest == "") { i++; val = A[i] } else val = (substr(rest, 1, 1) == "=" ? substr(rest, 2) : rest)
|
|
@@ -1664,8 +1694,45 @@ function endpoint_path(path, i, pair, value, decoded) {
|
|
|
1664
1694
|
sub(/[?#].*$/, "", decoded); gsub(/\/\/+/, "/", decoded); sub(/\/+$/, "", decoded)
|
|
1665
1695
|
return decoded
|
|
1666
1696
|
}
|
|
1697
|
+
# Ignore string literals and field names, but inspect expressions inside string interpolation.
|
|
1698
|
+
function filter_reads_environment(s, i, c, nextc, quoted, depth, parens, token, previous, level, containers, object_key) {
|
|
1699
|
+
for (i = 1; i <= length(s); i++) {
|
|
1700
|
+
c = substr(s, i, 1); nextc = substr(s, i + 1, 1)
|
|
1701
|
+
if (quoted) {
|
|
1702
|
+
if (c == "\\") {
|
|
1703
|
+
if (nextc == "(") { parens[++depth] = 1; quoted = 0; previous = "" }
|
|
1704
|
+
i++
|
|
1705
|
+
} else if (c == "\"") quoted = 0
|
|
1706
|
+
continue
|
|
1707
|
+
}
|
|
1708
|
+
if (c == "\"") { quoted = 1; previous = "string"; continue }
|
|
1709
|
+
if (c == "#") { while (i <= length(s) && substr(s, i, 1) != "\n") i++; continue }
|
|
1710
|
+
if (depth && c == "(") parens[depth]++
|
|
1711
|
+
if (depth && c == ")" && --parens[depth] == 0) { depth--; quoted = 1; continue }
|
|
1712
|
+
if (c == "[" || c == "{") containers[++level] = c
|
|
1713
|
+
if (c == "]" || c == "}") { delete containers[level]; level-- }
|
|
1714
|
+
if (c ~ /[A-Za-z_]/) {
|
|
1715
|
+
token = c
|
|
1716
|
+
while (substr(s, i + 1, 1) ~ /[A-Za-z0-9_]/) token = token substr(s, ++i, 1)
|
|
1717
|
+
object_key = containers[level] == "{" && (previous == "{" || previous == ",") && substr(s, i + 1) ~ /^[[:space:]]*:[^:]/
|
|
1718
|
+
if ((token == "env" && previous != "." && previous != "$" && !object_key) || (token == "ENV" && previous == "$")) return 1
|
|
1719
|
+
previous = token
|
|
1720
|
+
} else if (c !~ /[[:space:]]/) previous = c
|
|
1721
|
+
}
|
|
1722
|
+
return 0
|
|
1723
|
+
}
|
|
1724
|
+
function check_gh_filter(value) {
|
|
1725
|
+
if (filter_reads_environment(value))
|
|
1726
|
+
report("gh output filter reads the process environment, including credentials", "select response fields without env or $ENV")
|
|
1727
|
+
}
|
|
1728
|
+
function gh_title_option() {
|
|
1729
|
+
return (P[1] ~ /^(pr|issue|release)$/ && P[2] ~ /^(create|edit)$/) ||
|
|
1730
|
+
(P[1] == "pr" && P[2] == "merge") || (P[1] ~ /^(ssh-key|gpg-key)$/ && P[2] == "add")
|
|
1731
|
+
}
|
|
1667
1732
|
function gh(A, s, n, i, w, mutating, k, path, kind) {
|
|
1668
1733
|
kparse(A, s + 1, n, "XHfFqtR")
|
|
1734
|
+
# Only named command pairs use -t for a title or subject rather than an output template.
|
|
1735
|
+
kparse(A, s + 1, n, "XHfFqtR", (gh_title_option() ? 2 : 1))
|
|
1669
1736
|
if (P[1] == "secret") {
|
|
1670
1737
|
if (P[2] != "set" && P[2] != "delete" && P[2] != "remove")
|
|
1671
1738
|
report("gh secret " P[2] " reads the repository secret store", "gh secret set NAME (writes nothing to the output); refer to secrets by name only")
|