@simple-git/argv-parser 2.0.1 → 3.0.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.
Files changed (30) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +7 -3
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.mjs +538 -209
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/src/args/parse-argv.types.d.ts +6 -0
  8. package/dist/src/args/parse-argv.types.d.ts.map +1 -1
  9. package/dist/src/config/config-allow-list.d.ts +28 -0
  10. package/dist/src/config/config-allow-list.d.ts.map +1 -0
  11. package/dist/src/config/config.types.d.ts +1 -0
  12. package/dist/src/config/config.types.d.ts.map +1 -1
  13. package/dist/src/config/detect-config-action.d.ts +3 -1
  14. package/dist/src/config/detect-config-action.d.ts.map +1 -1
  15. package/dist/src/env/parse-env.d.ts +13 -1
  16. package/dist/src/env/parse-env.d.ts.map +1 -1
  17. package/dist/src/template/ref-name.d.ts +11 -0
  18. package/dist/src/template/ref-name.d.ts.map +1 -0
  19. package/dist/src/template/remote-url.d.ts +27 -0
  20. package/dist/src/template/remote-url.d.ts.map +1 -0
  21. package/dist/src/template/template-argv.d.ts +25 -0
  22. package/dist/src/template/template-argv.d.ts.map +1 -0
  23. package/dist/src/template/template-values.d.ts +11 -0
  24. package/dist/src/template/template-values.d.ts.map +1 -0
  25. package/dist/src/vulnerabilities/detect-vulnerable-config-writes.d.ts.map +1 -1
  26. package/dist/src/vulnerabilities/vulnerability.types.d.ts +111 -1
  27. package/dist/src/vulnerabilities/vulnerability.types.d.ts.map +1 -1
  28. package/package.json +1 -1
  29. package/dist/src/vulnerabilities/vulnerability-check.d.ts +0 -6
  30. package/dist/src/vulnerabilities/vulnerability-check.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import { isPathSpec as v, toPaths as U } from "@simple-git/args-pathspec";
2
- function* x(e, n) {
3
- const t = n === "global";
1
+ import { isPathSpec as b, toPaths as _ } from "@simple-git/args-pathspec";
2
+ function* L(e, t) {
3
+ const n = t === "global";
4
4
  for (const o of e)
5
- o.isGlobal === t && (yield o);
5
+ o.isGlobal === n && (yield o);
6
6
  }
7
- const P = /* @__PURE__ */ new Set([
7
+ const K = /* @__PURE__ */ new Set([
8
8
  "--add",
9
9
  "--edit",
10
10
  "--remove-section",
@@ -13,7 +13,7 @@ const P = /* @__PURE__ */ new Set([
13
13
  "--unset",
14
14
  "--unset-all",
15
15
  "-e"
16
- ]), S = /* @__PURE__ */ new Set([
16
+ ]), I = /* @__PURE__ */ new Set([
17
17
  "--get",
18
18
  "--get-all",
19
19
  "--get-color",
@@ -22,45 +22,51 @@ const P = /* @__PURE__ */ new Set([
22
22
  "--get-urlmatch",
23
23
  "--list",
24
24
  "-l"
25
- ]), E = /* @__PURE__ */ new Set([
25
+ ]), j = /* @__PURE__ */ new Set([
26
26
  "edit",
27
27
  "remove-section",
28
28
  "rename-section",
29
29
  "set",
30
30
  "unset"
31
- ]), F = /* @__PURE__ */ new Set(["get", "get-color", "get-colorbool", "list"]);
32
- function A(e, n) {
33
- for (const { name: o } of x(e, "task")) {
34
- if (P.has(o))
35
- return w(!0, n);
36
- if (S.has(o))
37
- return w(!1, n);
31
+ ]), D = /* @__PURE__ */ new Set(["get", "get-color", "get-colorbool", "list"]);
32
+ function B(e, t) {
33
+ for (const { name: o } of L(e, "task")) {
34
+ if (K.has(o))
35
+ return w(!0, t, o === "--rename-section");
36
+ if (I.has(o))
37
+ return w(!1, t);
38
38
  }
39
- const t = n.at(0)?.toLowerCase();
40
- return t === void 0 ? null : E.has(t) ? w(!0, n.slice(1)) : F.has(t) ? w(!1, n.slice(1)) : n.length === 1 ? w(!1, n) : w(!0, n);
39
+ const n = t.at(0)?.toLowerCase();
40
+ return n === void 0 ? null : j.has(n) ? w(!0, t.slice(1), n === "rename-section") : D.has(n) ? w(!1, t.slice(1)) : t.length === 1 ? w(!1, t) : w(!0, t);
41
41
  }
42
- function w(e = !1, n = []) {
43
- const t = n.at(0)?.toLowerCase();
44
- return t === void 0 ? null : {
42
+ function w(e = !1, t = [], n = !1) {
43
+ const o = t.at(0)?.toLowerCase();
44
+ return o === void 0 ? null : {
45
45
  isWrite: e,
46
46
  isRead: !e,
47
- key: t,
48
- value: n.at(1)
47
+ key: o,
48
+ value: t.at(1),
49
+ rename: n
49
50
  };
50
51
  }
51
- function O(e, n) {
52
- return n.isWrite && n.value !== void 0 ? { key: n.key, value: n.value, scope: e } : { key: n.key, scope: e };
52
+ function V(e, t) {
53
+ return t.isWrite && t.value !== void 0 ? {
54
+ scope: e,
55
+ key: t.key,
56
+ value: t.value,
57
+ rename: t.rename
58
+ } : { key: t.key, scope: e };
53
59
  }
54
- function G(e) {
55
- const n = e?.indexOf("=") || -1;
56
- return !e || n < 0 ? null : {
57
- key: e.slice(0, n).trim().toLowerCase(),
58
- value: e.slice(n + 1)
60
+ function q(e) {
61
+ const t = e?.indexOf("=") || -1;
62
+ return !e || t < 0 ? null : {
63
+ key: e.slice(0, t).trim().toLowerCase(),
64
+ value: e.slice(t + 1)
59
65
  };
60
66
  }
61
- function M(e) {
62
- for (const { name: n } of x(e, "task"))
63
- switch (n) {
67
+ function z(e) {
68
+ for (const { name: t } of L(e, "task"))
69
+ switch (t) {
64
70
  case "--global":
65
71
  return "global";
66
72
  case "--system":
@@ -75,44 +81,44 @@ function M(e) {
75
81
  }
76
82
  return "local";
77
83
  }
78
- function N({ name: e }) {
84
+ function Y({ name: e }) {
79
85
  if (e === "-c" || e === "--config")
80
86
  return "inline";
81
87
  if (e === "--config-env")
82
88
  return "env";
83
89
  }
84
- function* $(e) {
85
- for (const n of e) {
86
- const t = N(n), o = t && G(n.value);
90
+ function* H(e) {
91
+ for (const t of e) {
92
+ const n = Y(t), o = n && q(t.value);
87
93
  o && (yield {
88
94
  ...o,
89
- scope: t
95
+ scope: n
90
96
  });
91
97
  }
92
98
  }
93
- function D(e, n, t) {
99
+ function J(e, t, n) {
94
100
  const o = {
95
101
  read: [],
96
- write: [...$(n)]
102
+ write: [...H(t)]
97
103
  };
98
- return e === "config" && L(
104
+ return e === "config" && X(
99
105
  o,
100
- M(n),
101
- A(n, t)
106
+ z(t),
107
+ B(t, n)
102
108
  ), o;
103
109
  }
104
- function L(e, n, t) {
105
- if (t === null)
110
+ function X(e, t, n) {
111
+ if (n === null)
106
112
  return;
107
- const o = O(n, t);
108
- t.isWrite ? e.write.push(o) : e.read.push(o);
113
+ const o = V(t, n);
114
+ n.isWrite ? e.write.push(o) : e.read.push(o);
109
115
  }
110
- const C = {
116
+ const R = {
111
117
  short: /* @__PURE__ */ new Map([
112
118
  ["c", !0]
113
119
  // -c <k=v> set config key for this invocation
114
120
  ])
115
- }, I = {
121
+ }, S = {
116
122
  short: new Map([
117
123
  ["C", !0],
118
124
  // -C <path> change working directory
@@ -124,7 +130,7 @@ const C = {
124
130
  // -p paginate
125
131
  ["v", !1],
126
132
  // -v version
127
- ...C.short.entries()
133
+ ...R.short.entries()
128
134
  ]),
129
135
  long: /* @__PURE__ */ new Set([
130
136
  "attr-source",
@@ -136,7 +142,7 @@ const C = {
136
142
  "super-prefix",
137
143
  "work-tree"
138
144
  ])
139
- }, R = {
145
+ }, Q = {
140
146
  clone: {
141
147
  short: /* @__PURE__ */ new Map([
142
148
  ["b", !0],
@@ -227,77 +233,77 @@ const C = {
227
233
  ]),
228
234
  long: /* @__PURE__ */ new Set(["exec", "onto", "strategy", "strategy-option"])
229
235
  }
230
- }, T = { short: /* @__PURE__ */ new Map(), long: /* @__PURE__ */ new Set() };
231
- function B(e) {
232
- const n = R[e ?? ""] ?? T;
236
+ }, Z = { short: /* @__PURE__ */ new Map(), long: /* @__PURE__ */ new Set() };
237
+ function ee(e) {
238
+ const t = Q[e ?? ""] ?? Z;
233
239
  return {
234
- short: new Map([...C.short.entries(), ...n.short.entries()]),
235
- long: n.long
240
+ short: new Map([...R.short.entries(), ...t.short.entries()]),
241
+ long: t.long
236
242
  };
237
243
  }
238
- function b(e, n = I) {
244
+ function F(e, t = S) {
239
245
  if (e.startsWith("--")) {
240
- const t = e.indexOf("=");
241
- if (t > 2)
242
- return [{ name: e.slice(0, t), value: e.slice(t + 1), needsNext: !1 }];
246
+ const n = e.indexOf("=");
247
+ if (n > 2)
248
+ return [{ name: e.slice(0, n), value: e.slice(n + 1), needsNext: !1 }];
243
249
  const o = e.slice(2);
244
- return [{ name: e, needsNext: n.long.has(o) }];
250
+ return [{ name: e, needsNext: t.long.has(o) }];
245
251
  }
246
252
  if (e.length === 2) {
247
- const t = e.charAt(1), o = n.short.get(t);
253
+ const n = e.charAt(1), o = t.short.get(n);
248
254
  return [{ name: e, needsNext: o === !0 }];
249
255
  }
250
- return j(e, n.short);
256
+ return te(e, t.short);
251
257
  }
252
- function j(e, n) {
253
- const t = e.slice(1).split(""), o = [];
254
- for (let a = 0; a < t.length; a++) {
255
- const s = t[a], r = n.get(s);
258
+ function te(e, t) {
259
+ const n = e.slice(1).split(""), o = [];
260
+ for (let a = 0; a < n.length; a++) {
261
+ const s = n[a], r = t.get(s);
256
262
  if (r === void 0)
257
263
  return [{ name: e, needsNext: !1 }];
258
264
  if (r) {
259
- const i = t.slice(a + 1).join("");
260
- if (i && ![...i].every((m) => n.has(m)))
261
- return o.push({ name: `-${s}`, value: i, needsNext: !1 }), o;
265
+ const f = n.slice(a + 1).join("");
266
+ if (f && ![...f].every((v) => t.has(v)))
267
+ return o.push({ name: `-${s}`, value: f, needsNext: !1 }), o;
262
268
  }
263
269
  o.push({ name: `-${s}`, needsNext: r });
264
270
  }
265
271
  return o;
266
272
  }
267
- function W(e, n = []) {
268
- let t = 0;
269
- for (; t < e.length; ) {
270
- const o = String(e[t]);
273
+ function ne(e, t = []) {
274
+ let n = 0;
275
+ for (; n < e.length; ) {
276
+ const o = String(e[n]);
271
277
  if (!o.startsWith("-") || o.length < 2) break;
272
- const a = b(o);
273
- let s = t + 1;
278
+ const a = F(o);
279
+ let s = n + 1;
274
280
  for (const r of a) {
275
- const i = {
281
+ const f = {
276
282
  name: r.name,
277
283
  value: r.value,
278
284
  absorbedNext: !1,
279
285
  isGlobal: !0
280
286
  };
281
- r.needsNext && i.value === void 0 && s < e.length && (i.value = String(e[s]), i.absorbedNext = !0, s++), n.push(i);
287
+ r.needsNext && f.value === void 0 && s < e.length && (f.value = String(e[s]), f.absorbedNext = !0, s++), t.push(f);
282
288
  }
283
- t = s;
289
+ n = s;
284
290
  }
285
- return { flags: n, taskIndex: t };
291
+ return { flags: t, taskIndex: n };
286
292
  }
287
- function V(e, n, t = []) {
288
- const o = B(n), a = [], s = [];
293
+ function oe(e, t, n = []) {
294
+ const o = ee(t), a = [], s = [];
289
295
  let r = 0;
290
296
  for (; r < e.length; ) {
291
- const i = e[r];
292
- if (v(i)) {
293
- s.push(...U(i)), r++;
297
+ const f = e[r];
298
+ if (b(f)) {
299
+ s.push(..._(f)), r++;
294
300
  continue;
295
301
  }
296
- const p = String(i);
302
+ const p = String(f);
297
303
  if (p === "--") {
298
- for (let d = r + 1; d < e.length; d++) {
299
- const g = e[d];
300
- v(g) ? s.push(...U(g)) : s.push(String(g));
304
+ for (let i = r + 1; i < e.length; i++) {
305
+ const d = e[i];
306
+ b(d) ? s.push(..._(d)) : s.push(String(d));
301
307
  }
302
308
  break;
303
309
  }
@@ -305,136 +311,294 @@ function V(e, n, t = []) {
305
311
  a.push(p), r++;
306
312
  continue;
307
313
  }
308
- const m = b(p, o);
309
- let u = r + 1;
310
- for (const d of m) {
311
- const g = {
312
- name: d.name,
313
- value: d.value,
314
+ const v = F(p, o);
315
+ let h = r + 1;
316
+ for (const i of v) {
317
+ const d = {
318
+ name: i.name,
319
+ value: i.value,
314
320
  absorbedNext: !1,
315
321
  isGlobal: !1
316
322
  };
317
- d.needsNext && g.value === void 0 && u < e.length && !v(e[u]) && (g.value = String(e[u]), g.absorbedNext = !0, u++), t.push(g);
323
+ i.needsNext && d.value === void 0 && h < e.length && !b(e[h]) && (d.value = String(e[h]), d.absorbedNext = !0, h++), n.push(d);
318
324
  }
319
- r = u;
325
+ r = h;
320
326
  }
321
- return { flags: t, positionals: a, pathspecs: s };
327
+ return { flags: n, positionals: a, pathspecs: s };
322
328
  }
323
- function* q({
329
+ function* ae({
324
330
  write: e
325
331
  }) {
326
- for (const n of e)
327
- for (const t of K) {
328
- const o = t(n.key);
329
- o && (yield o);
332
+ for (const t of e) {
333
+ if (t.rename) {
334
+ yield {
335
+ category: "allowUnsafeConfigRename",
336
+ level: "default",
337
+ message: `Renaming config section ${t.key} is not permitted without enabling allowUnsafeConfigRename`
338
+ };
339
+ continue;
330
340
  }
341
+ for (const n of fe) {
342
+ const o = n(t.key);
343
+ if (o) {
344
+ yield o;
345
+ break;
346
+ }
347
+ }
348
+ }
331
349
  }
332
- function f(e, n, t = String(e)) {
333
- const o = typeof e == "string" ? new RegExp(`\\s*${e.toLowerCase()}`) : e;
334
- return function(s) {
335
- if (o.test(s))
350
+ function u(e, t, n = String(e), o = "default") {
351
+ const a = typeof e == "string" ? new RegExp(`\\s*${e.toLowerCase()}`) : e;
352
+ return function(r) {
353
+ if (a.test(r))
336
354
  return {
337
- category: n,
338
- message: `Configuring ${t} is not permitted without enabling ${n}`
355
+ category: t,
356
+ level: o,
357
+ message: `Configuring ${n} is not permitted without enabling ${t}`,
358
+ configKey: r
339
359
  };
340
360
  };
341
361
  }
342
- function l(e, n) {
343
- const t = new RegExp(`\\s*${e.toLowerCase().replace(/\./g, "(..+)?.")}`);
344
- return f(t, n, e);
345
- }
346
- const K = [
347
- f("alias", "allowUnsafeAlias"),
348
- f("core.askPass", "allowUnsafeAskPass"),
349
- f("core.editor", "allowUnsafeEditor"),
350
- f("core.fsmonitor", "allowUnsafeFsMonitor"),
351
- f("core.gitProxy", "allowUnsafeGitProxy"),
352
- f("core.hooksPath", "allowUnsafeHooksPath"),
353
- f("core.pager", "allowUnsafePager"),
354
- f("core.sshCommand", "allowUnsafeSshCommand"),
355
- l("credential.helper", "allowUnsafeCredentialHelper"),
356
- l("diff.command", "allowUnsafeDiffExternal"),
357
- f("diff.external", "allowUnsafeDiffExternal"),
358
- l("difftool.cmd", "allowUnsafeDiffExternal"),
359
- l("diff.textconv", "allowUnsafeDiffTextConv"),
360
- l("filter.clean", "allowUnsafeFilter"),
361
- l("filter.process", "allowUnsafeFilter"),
362
- l("filter.smudge", "allowUnsafeFilter"),
363
- l("gpg.program", "allowUnsafeGpgProgram"),
364
- f("include.path", "allowUnsafeInclude"),
365
- l("includeIf", "allowUnsafeInclude"),
366
- f("init.templateDir", "allowUnsafeTemplateDir"),
367
- l("pager.", "allowUnsafePager"),
368
- l("merge.driver", "allowUnsafeMergeDriver"),
369
- l("mergetool.path", "allowUnsafeMergeDriver"),
370
- l("mergetool.cmd", "allowUnsafeMergeDriver"),
371
- l("protocol.allow", "allowUnsafeProtocolOverride"),
372
- l("remote.receivepack", "allowUnsafePack"),
373
- l("remote.uploadpack", "allowUnsafePack"),
374
- f("uploadpack.packObjectsHook", "allowUnsafePack"),
375
- f("sequence.editor", "allowUnsafeEditor"),
376
- l("submodule.update", "allowUnsafeSubmodule"),
377
- l("tar.command", "allowUnsafeCommandBinaries"),
378
- l("trailer.cmd", "allowUnsafeCommandBinaries"),
379
- l("trailer.command", "allowUnsafeCommandBinaries"),
380
- l("url.insteadOf", "allowUnsafeUrlRewrite")
362
+ function c(e, t) {
363
+ const n = new RegExp(`\\s*${e.toLowerCase().replace(/\./g, "(..+)?.")}`);
364
+ return u(n, t, e);
365
+ }
366
+ const se = /^sendemail\.(.+\.)?(sendmailcmd|tocmd|cccmd|headercmd|smtpserver|smtpserveroption|smtpsslcertpath|smtpsslclientcert|smtpsslclientkey|aliasesfile|mailmap\.file)$/, re = /^imap\.(tunnel|host|sslverify)$/, le = /^instaweb\.(httpd|modulepath|gitwebdir)$/, ie = /^(browser|man)\..+\.(path|cmd)$/, ce = /^gpg\.(ssh\.(allowedsignersfile|revocationfile)|mintrustlevel)$/, fe = [
367
+ u(se, "allowUnsafeSendEmailConfig", "sendemail.*"),
368
+ u(re, "allowUnsafeSendEmailConfig", "imap.*"),
369
+ u(le, "allowUnsafeWebServerConfig", "instaweb.*"),
370
+ u(ie, "allowUnsafeBrowser", "browser.* / man.*"),
371
+ u(ce, "allowUnsafeSignatureTrust", "gpg.* signature trust"),
372
+ u("alias", "allowUnsafeAlias"),
373
+ u("core.askPass", "allowUnsafeAskPass"),
374
+ u("core.editor", "allowUnsafeEditor"),
375
+ u("core.fsmonitor", "allowUnsafeFsMonitor"),
376
+ u("core.gitProxy", "allowUnsafeGitProxy"),
377
+ u("core.hooksPath", "allowUnsafeHooksPath"),
378
+ u("core.pager", "allowUnsafePager"),
379
+ u("core.sshCommand", "allowUnsafeSshCommand"),
380
+ c("credential.helper", "allowUnsafeCredentialHelper"),
381
+ c("diff.command", "allowUnsafeDiffExternal"),
382
+ u("diff.external", "allowUnsafeDiffExternal"),
383
+ c("difftool.cmd", "allowUnsafeDiffExternal"),
384
+ c("difftool.path", "allowUnsafeDiffExternal"),
385
+ c("diff.textconv", "allowUnsafeDiffTextConv"),
386
+ c("filter.clean", "allowUnsafeFilter"),
387
+ c("filter.process", "allowUnsafeFilter"),
388
+ c("filter.smudge", "allowUnsafeFilter"),
389
+ c("gpg.program", "allowUnsafeGpgProgram"),
390
+ c("gpg.defaultKeyCommand", "allowUnsafeGpgProgram"),
391
+ u("include.path", "allowUnsafeInclude"),
392
+ c("includeIf", "allowUnsafeInclude"),
393
+ u("init.templateDir", "allowUnsafeTemplateDir"),
394
+ u("interactive.diffFilter", "allowUnsafePager"),
395
+ c("pager.", "allowUnsafePager"),
396
+ c("merge.driver", "allowUnsafeMergeDriver"),
397
+ c("mergetool.path", "allowUnsafeMergeDriver"),
398
+ c("mergetool.cmd", "allowUnsafeMergeDriver"),
399
+ c("protocol.allow", "allowUnsafeProtocolOverride"),
400
+ c("remote.receivepack", "allowUnsafePack"),
401
+ c("remote.uploadpack", "allowUnsafePack"),
402
+ u("uploadpack.packObjectsHook", "allowUnsafePack"),
403
+ u("sequence.editor", "allowUnsafeEditor"),
404
+ c("submodule.update", "allowUnsafeSubmodule"),
405
+ c("tar.command", "allowUnsafeCommandBinaries"),
406
+ c("trailer.cmd", "allowUnsafeCommandBinaries"),
407
+ c("trailer.command", "allowUnsafeCommandBinaries"),
408
+ c("url.insteadOf", "allowUnsafeUrlRewrite"),
409
+ // catch-all configuration using the "foo.command" or "bar.cmd" naming convention, only blocked
410
+ // when the `recommended` checks are enabled
411
+ u(/command$/, "allowUnsafeCommandBinaries", "/command$/", "recommended"),
412
+ u(/\.cmd$/, "allowUnsafeCommandBinaries", "/\\.cmd$/", "recommended")
381
413
  ];
382
- function* H(e, n) {
383
- for (const t of n)
384
- for (const o of X) {
385
- const a = o(e, t);
414
+ function* ue(e, t) {
415
+ for (const n of t)
416
+ for (const o of de) {
417
+ const a = o(e, n);
386
418
  a && (yield a);
387
419
  }
388
420
  }
389
- function c(e, n, t, { name: o = String(n), globalOnly: a = !1, withValue: s = !1 } = {}) {
390
- const r = typeof n == "string" ? new RegExp(`\\s*${n.toLowerCase()}`) : n, i = `Use of ${e ? `${e} with option ` : ""}${o} is not permitted without enabling ${t}`;
391
- return function(m, u) {
392
- if (!(e && m !== e) && !(a && !u.isGlobal) && !(s && u.value === void 0) && r.test(u.name))
421
+ function g(e, t, n, {
422
+ name: o = String(t),
423
+ exceptTask: a,
424
+ globalOnly: s = !1,
425
+ withValue: r = !1
426
+ } = {}) {
427
+ const f = typeof t == "string" ? new RegExp(`\\s*${t.toLowerCase()}`) : t, p = `Use of ${e ? `${e} with option ` : ""}${o} is not permitted without enabling ${n}`;
428
+ return function(h, i) {
429
+ if (!(e && h !== e) && !(a && h === a) && !(s && !i.isGlobal) && !(r && i.value === void 0) && f.test(i.name))
393
430
  return {
394
- category: t,
395
- message: i
431
+ category: n,
432
+ level: "default",
433
+ message: p
396
434
  };
397
435
  };
398
436
  }
399
- const h = { globalOnly: !0, withValue: !0 }, X = [
400
- c(null, /--(upload|receive)-pack/, "allowUnsafePack", {
437
+ const y = { globalOnly: !0, withValue: !0 }, de = [
438
+ g(null, /--(upload|receive)-pack/, "allowUnsafePack", {
401
439
  name: "--upload-pack or --receive-pack"
402
440
  }),
403
- c("clone", /^-\w*u/, "allowUnsafePack"),
404
- c("clone", "--u", "allowUnsafePack"),
405
- c("push", /^--exec$/, "allowUnsafePack", { name: "--exec" }),
441
+ g("clone", /^-\w*u/, "allowUnsafePack"),
442
+ g("clone", "--u", "allowUnsafePack"),
443
+ // `--exec` names the program run on the remote end of `push`, `send-pack`, `fetch-pack`, `archive` and
444
+ // (undocumented) `ls-remote`, `rebase` uses it for a command run after each commit
445
+ g(null, /^--exec$/, "allowUnsafePack", {
446
+ name: "--exec",
447
+ exceptTask: "rebase"
448
+ }),
406
449
  // `git` accepts unambiguous abbreviations of long options, so `--ex` and `--exe` are `--exec`
407
- c("rebase", /^(-x|--ex(ec?)?)$/, "allowUnsafeExec", { name: "-x or --exec" }),
408
- c(null, "--template", "allowUnsafeTemplateDir"),
409
- c(null, "--exec-path", "allowUnsafeExec", h),
450
+ g("rebase", /^(-x|--ex(ec?)?)$/, "allowUnsafeExec", { name: "-x or --exec" }),
451
+ // `git filter-branch` runs the value of each of these through `eval`
452
+ g(
453
+ "filter-branch",
454
+ /^--(setup|(env|tree|index|parent|msg|commit|tag-name)-filter)$/,
455
+ "allowUnsafeExec",
456
+ { name: "--setup or --<type>-filter" }
457
+ ),
458
+ // `git grep` configures a pager with `-O<cmd>` (potentially clustered as `-iO<cmd>`), or through the long-form
459
+ // `--open-files-in-pager`. Without a value both use the configured pager, so are permitted.
460
+ g("grep", /^-\w*O./, "allowUnsafePager", { name: "-O" }),
461
+ g("grep", "--open-files-in-pager", "allowUnsafePager", { withValue: !0 }),
462
+ g(null, "--template", "allowUnsafeTemplateDir"),
463
+ g(null, "--exec-path", "allowUnsafeExec", y),
410
464
  // `git` reads the configuration of whichever repository these name, so the
411
465
  // directory alone is enough to deliver config the argv guards never see
412
- c(null, "--git-dir", "allowUnsafeConfigPaths", h),
413
- c(null, "--work-tree", "allowUnsafeConfigPaths", h),
414
- c(null, /^-C$/, "allowUnsafeConfigPaths", { ...h, name: "-C" })
466
+ g(null, "--git-dir", "allowUnsafeConfigPaths", y),
467
+ g(null, "--work-tree", "allowUnsafeConfigPaths", y),
468
+ g(null, /^-C$/, "allowUnsafeConfigPaths", { ...y, name: "-C" })
415
469
  ];
416
- function k(e, n, t) {
417
- return [...H(e, n), ...q(t)];
470
+ function G(e, t, n) {
471
+ return [...ue(e, t), ...ae(n)];
418
472
  }
419
- function Y(...e) {
420
- const { flags: n, taskIndex: t } = W(e), o = t < e.length ? String(e[t]).toLowerCase() : null, a = o !== null ? e.slice(t + 1) : [], { positionals: s, pathspecs: r } = V(a, o, n), i = D(o, n, s);
473
+ function Ae(...e) {
474
+ const { flags: t, taskIndex: n } = ne(e), o = n < e.length ? String(e[n]).toLowerCase() : null, a = o !== null ? e.slice(n + 1) : [], { positionals: s, pathspecs: r } = oe(a, o, t), f = J(o, t, s);
421
475
  return {
422
476
  task: o,
423
- flags: n.map(J),
477
+ flags: t.map(ge),
424
478
  paths: r,
425
- config: i,
426
- vulnerabilities: z(k(o, n, i))
479
+ config: f,
480
+ vulnerabilities: me(G(o, t, f))
427
481
  };
428
482
  }
429
- function z(e) {
483
+ function me(e) {
430
484
  return Object.defineProperty(e, "vulnerabilities", {
431
485
  value: e
432
486
  });
433
487
  }
434
- function J({ value: e, name: n }) {
435
- return e !== void 0 ? { name: n, value: e } : { name: n };
488
+ function ge({ value: e, name: t }) {
489
+ return e !== void 0 ? { name: t, value: e } : { name: t };
436
490
  }
437
- const y = {
491
+ const pe = Object.freeze([
492
+ // identity
493
+ "user.name",
494
+ "user.email",
495
+ "user.useconfigonly",
496
+ "author.name",
497
+ "author.email",
498
+ "committer.name",
499
+ "committer.email",
500
+ // line endings, file system and display behaviour
501
+ "core.abbrev",
502
+ "core.autocrlf",
503
+ "core.bigfilethreshold",
504
+ "core.commentchar",
505
+ "core.commentstring",
506
+ "core.compression",
507
+ "core.eol",
508
+ "core.filemode",
509
+ "core.ignorecase",
510
+ "core.logallrefupdates",
511
+ "core.longpaths",
512
+ "core.precomposeunicode",
513
+ "core.preloadindex",
514
+ "core.quotepath",
515
+ "core.safecrlf",
516
+ "core.untrackedcache",
517
+ "core.whitespace",
518
+ "advice.*",
519
+ "color.*",
520
+ "column.ui",
521
+ "i18n.commitencoding",
522
+ "i18n.logoutputencoding",
523
+ "init.defaultbranch",
524
+ // branch / merge / rebase / pull / push defaults
525
+ "branch.autosetupmerge",
526
+ "branch.autosetuprebase",
527
+ "branch.sort",
528
+ "checkout.defaultremote",
529
+ "clone.defaultremotename",
530
+ "fetch.prune",
531
+ "fetch.prunetags",
532
+ "merge.conflictstyle",
533
+ "merge.ff",
534
+ "merge.renamelimit",
535
+ "pull.ff",
536
+ "pull.rebase",
537
+ "push.autosetupremote",
538
+ "push.default",
539
+ "push.followtags",
540
+ "rebase.autosquash",
541
+ "rebase.autostash",
542
+ "rerere.enabled",
543
+ "tag.sort",
544
+ "versionsort.suffix",
545
+ // output formatting of diff / log / status / grep
546
+ "diff.algorithm",
547
+ "diff.colormoved",
548
+ "diff.context",
549
+ "diff.interhunkcontext",
550
+ "diff.mnemonicprefix",
551
+ "diff.noprefix",
552
+ "diff.relative",
553
+ "diff.renamelimit",
554
+ "diff.renames",
555
+ "grep.extendedregexp",
556
+ "grep.linenumber",
557
+ "grep.patterntype",
558
+ "log.abbrevcommit",
559
+ "log.date",
560
+ "log.decorate",
561
+ "log.follow",
562
+ "status.branch",
563
+ "status.renames",
564
+ "status.short",
565
+ "status.showuntrackedfiles",
566
+ // performance and transfer tuning
567
+ "feature.manyfiles",
568
+ "gc.auto",
569
+ "gc.autodetach",
570
+ "http.lowspeedlimit",
571
+ "http.lowspeedtime",
572
+ "http.postbuffer",
573
+ "http.version",
574
+ "index.version",
575
+ "pack.threads",
576
+ "pack.windowmemory",
577
+ "protocol.version",
578
+ // extra request headers, commonly used for CI authentication tokens
579
+ "http.extraheader",
580
+ "http.*.extraheader",
581
+ // integrity checks - these only ever make git stricter
582
+ "fetch.fsckobjects",
583
+ "receive.fsckobjects",
584
+ "transfer.fsckobjects"
585
+ ]);
586
+ function he(e) {
587
+ const t = /* @__PURE__ */ new Set(), n = [];
588
+ for (const o of e) {
589
+ const a = String(o).trim().toLowerCase();
590
+ a && (a.includes("*") ? n.push(
591
+ new RegExp(
592
+ `^${a.split("*").map((s) => s.replace(/[.+?^${}()|[\]\\]/g, "\\$&")).join(".*")}$`
593
+ )
594
+ ) : t.add(a));
595
+ }
596
+ return (o) => {
597
+ const a = o.trim().toLowerCase();
598
+ return t.has(a) || n.some((s) => s.test(a));
599
+ };
600
+ }
601
+ const Le = he(pe), N = {
438
602
  editor: "allowUnsafeEditor",
439
603
  git_askpass: "allowUnsafeAskPass",
440
604
  git_config_global: "allowUnsafeConfigPaths",
@@ -455,55 +619,220 @@ const y = {
455
619
  prefix: "allowUnsafeConfigPaths",
456
620
  ssh_askpass: "allowUnsafeAskPass",
457
621
  visual: "allowUnsafeEditor"
622
+ }, T = {
623
+ home: "allowUnsafeConfigPaths",
624
+ xdg_config_home: "allowUnsafeConfigPaths"
458
625
  };
459
- function* Q(e) {
460
- const n = parseInt(e.git_config_count ?? "0", 10);
461
- for (let t = 0; t < n; t++) {
462
- const o = e[`git_config_key_${t}`], a = e[`git_config_value_${t}`];
626
+ function W(e) {
627
+ return Object.hasOwn(T, e);
628
+ }
629
+ function* we(e) {
630
+ const t = parseInt(e.git_config_count ?? "0", 10);
631
+ for (let n = 0; n < t; n++) {
632
+ const o = e[`git_config_key_${n}`], a = e[`git_config_value_${n}`];
463
633
  o !== void 0 && (yield { key: o.toLowerCase().trim(), value: a, scope: "env" });
464
634
  }
465
635
  }
466
- function* Z(e) {
636
+ function* ve(e, t) {
467
637
  for (const n of Object.keys(e))
468
- if (_(n)) {
469
- const t = y[n];
638
+ if (W(n) && e[n] !== t[n]) {
639
+ const o = T[n];
470
640
  yield {
471
- category: t,
472
- message: `Use of "${n.toUpperCase()}" is not permitted without enabling ${t}`
641
+ category: o,
642
+ level: "recommended",
643
+ message: `Use of "${n.toUpperCase()}" with a value other than the inherited one is not permitted without enabling ${o}`,
644
+ envKey: n
473
645
  };
474
646
  }
475
647
  }
476
- function _(e) {
477
- return Object.hasOwn(y, e);
648
+ function* be(e) {
649
+ for (const t of Object.keys(e))
650
+ if (M(t)) {
651
+ const n = N[t];
652
+ yield {
653
+ category: n,
654
+ level: "default",
655
+ message: `Use of "${t.toUpperCase()}" is not permitted without enabling ${n}`,
656
+ envKey: t
657
+ };
658
+ }
478
659
  }
479
- function ee(e) {
480
- const n = {};
481
- for (const [t, o] of Object.entries(e)) {
482
- const a = t.toLowerCase().trim();
483
- (_(a) || a.startsWith("git")) && (n[a] = String(o));
660
+ function M(e) {
661
+ return Object.hasOwn(N, e);
662
+ }
663
+ function Ue(e) {
664
+ const t = String(e).toLowerCase().trim();
665
+ return t.startsWith("git_") || M(t);
666
+ }
667
+ function $(e) {
668
+ const t = {};
669
+ for (const [n, o] of Object.entries(e)) {
670
+ const a = n.toLowerCase().trim();
671
+ (Ue(a) || W(a)) && (t[a] = String(o));
484
672
  }
485
- return n;
673
+ return t;
486
674
  }
487
- function ne(e) {
488
- const n = ee(e), t = {
675
+ function Re(e, t = {}) {
676
+ const n = $(e), o = {
489
677
  read: [],
490
- write: [...Q(n)]
491
- }, o = [
492
- ...Z(n),
493
- ...k(null, [], t)
678
+ write: [...we(n)]
679
+ }, a = [
680
+ ...be(n),
681
+ ...ve(n, $(t)),
682
+ ...G(null, [], o)
494
683
  ];
495
684
  return {
496
- config: t,
497
- vulnerabilities: o
685
+ config: o,
686
+ vulnerabilities: a
687
+ };
688
+ }
689
+ class k {
690
+ constructor(t, n) {
691
+ this.value = t, this.validate = n;
692
+ }
693
+ }
694
+ function Fe(e) {
695
+ return new k(String(e), (t) => {
696
+ if (!t || t === "@" || t.includes("..") || t.includes("@{") || t.includes("//") || /[\s~^:?*[\\]/.test(t) || t.endsWith("/") || t.endsWith(".") || t.split("/").some((n) => n.startsWith(".") || n.endsWith(".lock")))
697
+ return "not a valid ref name";
698
+ });
699
+ }
700
+ const ye = [
701
+ "https",
702
+ "http",
703
+ "ssh",
704
+ "git+ssh",
705
+ "ssh+git",
706
+ "git",
707
+ "file",
708
+ "scp",
709
+ "local"
710
+ ], xe = new Set(ye), Ce = /^([a-z][a-z0-9+.-]*):\/\//i, Se = /^(?:([^@/]+)@)?([^/:]+):(?!\/\/)/;
711
+ function Ge(e, { protocols: t } = {}) {
712
+ const n = t ? new Set(t) : xe;
713
+ return new k(String(e), (o) => {
714
+ const a = Ce.exec(o)?.[1]?.toLowerCase();
715
+ if (a !== void 0) {
716
+ if (!n.has(a))
717
+ return `protocol "${a}" is not permitted`;
718
+ let r;
719
+ try {
720
+ r = new URL(o);
721
+ } catch {
722
+ return "not a valid url";
723
+ }
724
+ return r.hostname.startsWith("-") || decodeURIComponent(r.username).startsWith("-") ? 'host and user names must not start with "-"' : void 0;
725
+ }
726
+ const s = Se.exec(o);
727
+ return s && !/^[a-z]:[\\/]/i.test(o) ? n.has("scp") ? s[1]?.startsWith("-") || s[2].startsWith("-") ? 'host and user names must not start with "-"' : void 0 : "scp-like urls are not permitted" : n.has("local") ? void 0 : "local paths are not permitted";
728
+ });
729
+ }
730
+ class ke extends Error {
731
+ }
732
+ const Ee = /[\u0000-\u001f\u007f]/, _e = /^[a-z][a-z0-9+.-]*::/i, P = /* @__PURE__ */ new Set(["-c", "--config", "--config-env"]), O = /* @__PURE__ */ new Set([
733
+ ...[...S.short].filter(([, e]) => e).map(([e]) => `-${e}`),
734
+ ...[...S.long].map((e) => `--${e}`)
735
+ ]);
736
+ function m(e) {
737
+ throw new ke(e);
738
+ }
739
+ function $e(e) {
740
+ return Array.isArray(e) && Array.isArray(e.raw) && Object.isFrozen(e);
741
+ }
742
+ function U(e) {
743
+ return JSON.stringify(String(e));
744
+ }
745
+ function A(e) {
746
+ let t;
747
+ if (e instanceof k) {
748
+ t = e.value;
749
+ const n = e.validate(t);
750
+ n && m(`interpolated value ${U(t)} is rejected: ${n}`);
751
+ } else typeof e == "string" ? t = e : typeof e == "number" && Number.isFinite(e) ? t = String(e) : m(
752
+ `interpolated values must be strings, finite numbers or arrays of them, received ${typeof e}`
753
+ );
754
+ return Ee.test(t) && m(`interpolated value ${U(t)} contains control characters`), _e.test(t) && m(`interpolated value ${U(t)} would select a git remote helper transport`), t;
755
+ }
756
+ function Pe(e, t) {
757
+ const n = [];
758
+ let o = [];
759
+ const a = () => {
760
+ o.length && (n.push(o), o = []);
498
761
  };
762
+ return e.forEach((s, r) => {
763
+ for (const f of s.split(/(\s+)/))
764
+ /^\s+$/.test(f) ? a() : f && o.push({ text: f });
765
+ r < t.length && o.push({ text: "", value: t[r] });
766
+ }), a(), n;
499
767
  }
500
- function oe(e, n) {
501
- return [...Y(...e).vulnerabilities, ...ne(n).vulnerabilities];
768
+ function Ne(e, t) {
769
+ $e(e) || m("must be used as a tagged template literal");
770
+ const n = [];
771
+ let o, a = !1, s;
772
+ for (const r of Pe(e, t)) {
773
+ if (r.every((l) => !("value" in l))) {
774
+ const l = r.map((x) => x.text).join("");
775
+ n.push(l), s = l, a || (a = o !== void 0 && l === "--"), o === void 0 && !l.startsWith("-") && !O.has(n.at(-2) ?? "") && (o = l);
776
+ continue;
777
+ }
778
+ const p = !("value" in r[0]);
779
+ s !== void 0 && P.has(s) && !p && m(
780
+ 'configuration keys must be written literally, use "-c some.key=${value}" rather than "-c ${value}"'
781
+ );
782
+ const h = p && (r[0].text.startsWith("-") || s !== void 0 && O.has(s));
783
+ if (o === void 0 && !h && m(
784
+ 'the git sub-command must be written literally, interpolated values before it can only be used as option values, for example "-c user.name=${name}"'
785
+ ), r.length === 1) {
786
+ const { value: l } = r[0];
787
+ if (b(l))
788
+ n.push(l);
789
+ else
790
+ for (const x of Array.isArray(l) ? l : [l]) {
791
+ const C = A(x);
792
+ C.startsWith("-") && !a && m(
793
+ `interpolated value ${U(C)} would be read as an option, values that may start with "-" must follow "--" or be wrapped with pathspec()`
794
+ ), n.push(C);
795
+ }
796
+ s = void 0;
797
+ continue;
798
+ }
799
+ let i = "", d = -1;
800
+ for (const l of r)
801
+ "value" in l ? ((Array.isArray(l.value) || b(l.value)) && m("arrays and pathspecs must be interpolated as a standalone argument"), d < 0 && (d = i.length), i += A(l.value)) : i += l.text;
802
+ if (d === 0 && i.startsWith("-") && !a && m(`interpolated value ${U(i)} would be read as an option`), d > 0 && i.startsWith("-") && !a) {
803
+ const l = i.indexOf("=");
804
+ (l < 0 || l >= d) && m(
805
+ 'interpolated values in options must follow "=", for example "--message=${value}"'
806
+ );
807
+ }
808
+ if (s !== void 0 && P.has(s)) {
809
+ const l = i.indexOf("=");
810
+ (l < 0 || l >= d) && m(
811
+ 'configuration keys must be written literally, use "-c some.key=${value}" rather than "-c ${value}"'
812
+ );
813
+ }
814
+ const E = /^(?:--config(?:-env)?=|-c(?=.))/.exec(i)?.[0];
815
+ if (E && !a) {
816
+ const l = i.indexOf("=", E.length);
817
+ (l < 0 || l >= d) && m('configuration keys must be written literally, use "--config=some.key=${value}"');
818
+ }
819
+ n.push(i), s = void 0;
820
+ }
821
+ return o === void 0 && m("no git sub-command supplied"), n;
502
822
  }
503
823
  export {
504
- _ as isGitEnvKey,
505
- Y as parseArgv,
506
- ne as parseEnv,
507
- oe as vulnerabilityCheck
824
+ ke as GitTemplateError,
825
+ pe as SAFE_CONFIG_KEYS,
826
+ k as TemplateValue,
827
+ he as configKeyMatcher,
828
+ M as isGitEnvKey,
829
+ Ue as isGuardedEnvKey,
830
+ Le as isSafeConfigKey,
831
+ $e as isTemplateStringsArray,
832
+ Ae as parseArgv,
833
+ Re as parseEnv,
834
+ Fe as refName,
835
+ Ge as remoteUrl,
836
+ Ne as templateArgv
508
837
  };
509
838
  //# sourceMappingURL=index.mjs.map