type-git 0.3.0-alpha.0 → 0.3.0-alpha.1
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.
- package/dist/adapters/bun/index.cjs +10 -4
- package/dist/adapters/bun/index.cjs.map +1 -1
- package/dist/adapters/bun/index.d.cts +1 -1
- package/dist/adapters/bun/index.d.ts +1 -1
- package/dist/adapters/bun/index.js +10 -4
- package/dist/adapters/bun/index.js.map +1 -1
- package/dist/adapters/deno/index.cjs +10 -4
- package/dist/adapters/deno/index.cjs.map +1 -1
- package/dist/adapters/deno/index.d.cts +1 -1
- package/dist/adapters/deno/index.d.ts +1 -1
- package/dist/adapters/deno/index.js +10 -4
- package/dist/adapters/deno/index.js.map +1 -1
- package/dist/adapters/node/index.cjs +124 -9
- package/dist/adapters/node/index.cjs.map +1 -1
- package/dist/adapters/node/index.d.cts +16 -2
- package/dist/adapters/node/index.d.ts +16 -2
- package/dist/adapters/node/index.js +124 -9
- package/dist/adapters/node/index.js.map +1 -1
- package/dist/{adapters-BEKkCViX.d.cts → adapters-Bpuvmw9y.d.cts} +68 -1
- package/dist/{adapters-BEKkCViX.d.ts → adapters-Bpuvmw9y.d.ts} +68 -1
- package/dist/index.cjs +130 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +127 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment variable inheritance control (environment variable traversal prevention)
|
|
3
|
+
*
|
|
4
|
+
* By default, type-git does NOT pass the entire parent process environment to the
|
|
5
|
+
* spawned Git subprocess. Leaking the full environment into Git (and from there into
|
|
6
|
+
* credential helpers, hooks, and LFS transfer agents) is an environment variable
|
|
7
|
+
* traversal risk: secrets such as cloud credentials or API tokens that live in the
|
|
8
|
+
* parent process can be exfiltrated by untrusted Git configuration or remote-controlled
|
|
9
|
+
* helpers.
|
|
10
|
+
*
|
|
11
|
+
* Instead, only a curated allowlist of variables that Git genuinely needs to operate is
|
|
12
|
+
* inherited. Callers can widen or replace this behavior via the `inheritEnv` option.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Controls how the parent process environment is inherited by spawned Git commands.
|
|
16
|
+
*
|
|
17
|
+
* - `undefined` (default): inherit only {@link DEFAULT_ENV_ALLOWLIST} — the variables
|
|
18
|
+
* Git needs to function. Sensitive variables are not passed through.
|
|
19
|
+
* - `true`: inherit the entire parent environment (legacy behavior, opt-in).
|
|
20
|
+
* - `false`: inherit nothing. The child only receives explicitly provided variables and
|
|
21
|
+
* values computed by the library (e.g. `HOME`, `PATH` prefixes). Note that this may
|
|
22
|
+
* break Git if `PATH` is not otherwise supplied.
|
|
23
|
+
* - `string[]`: inherit {@link DEFAULT_ENV_ALLOWLIST} plus the named variables. Use this
|
|
24
|
+
* to explicitly opt specific variables (e.g. an SSH command or a token) back in.
|
|
25
|
+
*/
|
|
26
|
+
type EnvInheritance = boolean | string[];
|
|
27
|
+
/**
|
|
28
|
+
* Curated allowlist of environment variables inherited by default.
|
|
29
|
+
*
|
|
30
|
+
* These are variables Git (and the tools it shells out to, such as ssh and credential
|
|
31
|
+
* helpers) commonly needs to operate. The list intentionally excludes arbitrary
|
|
32
|
+
* application secrets so they are not silently forwarded to Git subprocesses.
|
|
33
|
+
*
|
|
34
|
+
* Variable names are matched case-insensitively on Windows.
|
|
35
|
+
*/
|
|
36
|
+
declare const DEFAULT_ENV_ALLOWLIST: readonly string[];
|
|
37
|
+
/**
|
|
38
|
+
* Resolve the set of environment variables to inherit from the parent process.
|
|
39
|
+
*
|
|
40
|
+
* @param parentEnv - The parent process environment (e.g. `process.env`).
|
|
41
|
+
* @param inheritEnv - Inheritance policy. See {@link EnvInheritance}.
|
|
42
|
+
* @param platform - The runtime platform (e.g. `process.platform`). When `'win32'`,
|
|
43
|
+
* variable names are matched case-insensitively.
|
|
44
|
+
* @returns A record containing only the inherited variables (undefined values removed).
|
|
45
|
+
*/
|
|
46
|
+
declare function resolveInheritedEnv(parentEnv: Record<string, string | undefined>, inheritEnv?: EnvInheritance, platform?: string): Record<string, string>;
|
|
47
|
+
|
|
1
48
|
/**
|
|
2
49
|
* Core type definitions for the type-safe Git wrapper library
|
|
3
50
|
*
|
|
@@ -9,6 +56,7 @@
|
|
|
9
56
|
* - Output contracts for typed parsing
|
|
10
57
|
* - Branded types for type safety
|
|
11
58
|
*/
|
|
59
|
+
|
|
12
60
|
/**
|
|
13
61
|
* Brand symbol for NonEmptyString
|
|
14
62
|
* @internal
|
|
@@ -331,6 +379,15 @@ type GitOpenOptions = {
|
|
|
331
379
|
credentialHelper?: string;
|
|
332
380
|
/** Additional environment variables */
|
|
333
381
|
env?: Record<string, string>;
|
|
382
|
+
/**
|
|
383
|
+
* Controls how the parent process environment is inherited by spawned Git commands.
|
|
384
|
+
*
|
|
385
|
+
* By default, only a curated allowlist of variables that Git needs to operate is
|
|
386
|
+
* inherited (environment variable traversal prevention). Set to `true` to inherit the
|
|
387
|
+
* full parent environment, or provide an array of variable names to opt additional
|
|
388
|
+
* variables back in.
|
|
389
|
+
*/
|
|
390
|
+
inheritEnv?: EnvInheritance;
|
|
334
391
|
/** Directories to prepend to PATH */
|
|
335
392
|
pathPrefix?: string[];
|
|
336
393
|
/** Credential configuration (§6.4) */
|
|
@@ -518,6 +575,16 @@ type SpawnOptions = {
|
|
|
518
575
|
argv: string[];
|
|
519
576
|
/** Additional environment variables */
|
|
520
577
|
env?: Record<string, string>;
|
|
578
|
+
/**
|
|
579
|
+
* Whether to merge the parent process environment underneath `env`.
|
|
580
|
+
*
|
|
581
|
+
* - `true` (default when omitted): the parent environment is merged underneath `env`,
|
|
582
|
+
* so the child inherits the full parent environment with `env` overrides on top.
|
|
583
|
+
* - `false`: the child receives only the variables in `env` (and nothing from the
|
|
584
|
+
* parent process). This prevents implicit environment variable traversal — used by
|
|
585
|
+
* {@link CliRunner}, which resolves the inherited variables itself.
|
|
586
|
+
*/
|
|
587
|
+
inheritEnv?: boolean;
|
|
521
588
|
/** Working directory */
|
|
522
589
|
cwd?: string;
|
|
523
590
|
/** AbortSignal for cancellation */
|
|
@@ -728,4 +795,4 @@ interface RuntimeAdapters {
|
|
|
728
795
|
*/
|
|
729
796
|
type AdapterFactory = () => RuntimeAdapters;
|
|
730
797
|
|
|
731
|
-
export { type AuditConfig as A, type Capabilities as C, type ExecAdapter as E, type FsAdapter as F, type GitErrorCategory as G, type LfsMode as L, type NonEmptyString as N, type OutputContract as O, type RuntimeAdapters as R, type SpawnOptions as S, type TailOptions as T, type StreamHandler as a, type SpawnResult as b, type SpawnHandle as c, type TailHandle as d, type ExecOpts as e, type RawResult as f, type GitProgress as g, type GitOpenOptions as h, type
|
|
798
|
+
export { type AuditConfig as A, type TraceEvent as B, type Capabilities as C, DEFAULT_ENV_ALLOWLIST as D, type ExecAdapter as E, type FsAdapter as F, type GitErrorCategory as G, type LfsMode as L, type NonEmptyString as N, type OutputContract as O, type RuntimeAdapters as R, type SpawnOptions as S, type TailOptions as T, type StreamHandler as a, type SpawnResult as b, type SpawnHandle as c, type TailHandle as d, type ExecOpts as e, type RawResult as f, type GitProgress as g, type GitOpenOptions as h, type EnvInheritance as i, type ExecutionContext as j, GitError as k, type AdapterFactory as l, isNonEmpty as m, nonEmpty as n, type LfsProgress as o, type GitErrorKind as p, GitArgumentError as q, resolveInheritedEnv as r, type Runtime as s, type CommandSpec as t, type CredentialRequest as u, type Credential as v, type CredentialConfig as w, type AuditEventStart as x, type AuditEventEnd as y, type AuditEvent as z };
|
|
@@ -1,3 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment variable inheritance control (environment variable traversal prevention)
|
|
3
|
+
*
|
|
4
|
+
* By default, type-git does NOT pass the entire parent process environment to the
|
|
5
|
+
* spawned Git subprocess. Leaking the full environment into Git (and from there into
|
|
6
|
+
* credential helpers, hooks, and LFS transfer agents) is an environment variable
|
|
7
|
+
* traversal risk: secrets such as cloud credentials or API tokens that live in the
|
|
8
|
+
* parent process can be exfiltrated by untrusted Git configuration or remote-controlled
|
|
9
|
+
* helpers.
|
|
10
|
+
*
|
|
11
|
+
* Instead, only a curated allowlist of variables that Git genuinely needs to operate is
|
|
12
|
+
* inherited. Callers can widen or replace this behavior via the `inheritEnv` option.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Controls how the parent process environment is inherited by spawned Git commands.
|
|
16
|
+
*
|
|
17
|
+
* - `undefined` (default): inherit only {@link DEFAULT_ENV_ALLOWLIST} — the variables
|
|
18
|
+
* Git needs to function. Sensitive variables are not passed through.
|
|
19
|
+
* - `true`: inherit the entire parent environment (legacy behavior, opt-in).
|
|
20
|
+
* - `false`: inherit nothing. The child only receives explicitly provided variables and
|
|
21
|
+
* values computed by the library (e.g. `HOME`, `PATH` prefixes). Note that this may
|
|
22
|
+
* break Git if `PATH` is not otherwise supplied.
|
|
23
|
+
* - `string[]`: inherit {@link DEFAULT_ENV_ALLOWLIST} plus the named variables. Use this
|
|
24
|
+
* to explicitly opt specific variables (e.g. an SSH command or a token) back in.
|
|
25
|
+
*/
|
|
26
|
+
type EnvInheritance = boolean | string[];
|
|
27
|
+
/**
|
|
28
|
+
* Curated allowlist of environment variables inherited by default.
|
|
29
|
+
*
|
|
30
|
+
* These are variables Git (and the tools it shells out to, such as ssh and credential
|
|
31
|
+
* helpers) commonly needs to operate. The list intentionally excludes arbitrary
|
|
32
|
+
* application secrets so they are not silently forwarded to Git subprocesses.
|
|
33
|
+
*
|
|
34
|
+
* Variable names are matched case-insensitively on Windows.
|
|
35
|
+
*/
|
|
36
|
+
declare const DEFAULT_ENV_ALLOWLIST: readonly string[];
|
|
37
|
+
/**
|
|
38
|
+
* Resolve the set of environment variables to inherit from the parent process.
|
|
39
|
+
*
|
|
40
|
+
* @param parentEnv - The parent process environment (e.g. `process.env`).
|
|
41
|
+
* @param inheritEnv - Inheritance policy. See {@link EnvInheritance}.
|
|
42
|
+
* @param platform - The runtime platform (e.g. `process.platform`). When `'win32'`,
|
|
43
|
+
* variable names are matched case-insensitively.
|
|
44
|
+
* @returns A record containing only the inherited variables (undefined values removed).
|
|
45
|
+
*/
|
|
46
|
+
declare function resolveInheritedEnv(parentEnv: Record<string, string | undefined>, inheritEnv?: EnvInheritance, platform?: string): Record<string, string>;
|
|
47
|
+
|
|
1
48
|
/**
|
|
2
49
|
* Core type definitions for the type-safe Git wrapper library
|
|
3
50
|
*
|
|
@@ -9,6 +56,7 @@
|
|
|
9
56
|
* - Output contracts for typed parsing
|
|
10
57
|
* - Branded types for type safety
|
|
11
58
|
*/
|
|
59
|
+
|
|
12
60
|
/**
|
|
13
61
|
* Brand symbol for NonEmptyString
|
|
14
62
|
* @internal
|
|
@@ -331,6 +379,15 @@ type GitOpenOptions = {
|
|
|
331
379
|
credentialHelper?: string;
|
|
332
380
|
/** Additional environment variables */
|
|
333
381
|
env?: Record<string, string>;
|
|
382
|
+
/**
|
|
383
|
+
* Controls how the parent process environment is inherited by spawned Git commands.
|
|
384
|
+
*
|
|
385
|
+
* By default, only a curated allowlist of variables that Git needs to operate is
|
|
386
|
+
* inherited (environment variable traversal prevention). Set to `true` to inherit the
|
|
387
|
+
* full parent environment, or provide an array of variable names to opt additional
|
|
388
|
+
* variables back in.
|
|
389
|
+
*/
|
|
390
|
+
inheritEnv?: EnvInheritance;
|
|
334
391
|
/** Directories to prepend to PATH */
|
|
335
392
|
pathPrefix?: string[];
|
|
336
393
|
/** Credential configuration (§6.4) */
|
|
@@ -518,6 +575,16 @@ type SpawnOptions = {
|
|
|
518
575
|
argv: string[];
|
|
519
576
|
/** Additional environment variables */
|
|
520
577
|
env?: Record<string, string>;
|
|
578
|
+
/**
|
|
579
|
+
* Whether to merge the parent process environment underneath `env`.
|
|
580
|
+
*
|
|
581
|
+
* - `true` (default when omitted): the parent environment is merged underneath `env`,
|
|
582
|
+
* so the child inherits the full parent environment with `env` overrides on top.
|
|
583
|
+
* - `false`: the child receives only the variables in `env` (and nothing from the
|
|
584
|
+
* parent process). This prevents implicit environment variable traversal — used by
|
|
585
|
+
* {@link CliRunner}, which resolves the inherited variables itself.
|
|
586
|
+
*/
|
|
587
|
+
inheritEnv?: boolean;
|
|
521
588
|
/** Working directory */
|
|
522
589
|
cwd?: string;
|
|
523
590
|
/** AbortSignal for cancellation */
|
|
@@ -728,4 +795,4 @@ interface RuntimeAdapters {
|
|
|
728
795
|
*/
|
|
729
796
|
type AdapterFactory = () => RuntimeAdapters;
|
|
730
797
|
|
|
731
|
-
export { type AuditConfig as A, type Capabilities as C, type ExecAdapter as E, type FsAdapter as F, type GitErrorCategory as G, type LfsMode as L, type NonEmptyString as N, type OutputContract as O, type RuntimeAdapters as R, type SpawnOptions as S, type TailOptions as T, type StreamHandler as a, type SpawnResult as b, type SpawnHandle as c, type TailHandle as d, type ExecOpts as e, type RawResult as f, type GitProgress as g, type GitOpenOptions as h, type
|
|
798
|
+
export { type AuditConfig as A, type TraceEvent as B, type Capabilities as C, DEFAULT_ENV_ALLOWLIST as D, type ExecAdapter as E, type FsAdapter as F, type GitErrorCategory as G, type LfsMode as L, type NonEmptyString as N, type OutputContract as O, type RuntimeAdapters as R, type SpawnOptions as S, type TailOptions as T, type StreamHandler as a, type SpawnResult as b, type SpawnHandle as c, type TailHandle as d, type ExecOpts as e, type RawResult as f, type GitProgress as g, type GitOpenOptions as h, type EnvInheritance as i, type ExecutionContext as j, GitError as k, type AdapterFactory as l, isNonEmpty as m, nonEmpty as n, type LfsProgress as o, type GitErrorKind as p, GitArgumentError as q, resolveInheritedEnv as r, type Runtime as s, type CommandSpec as t, type CredentialRequest as u, type Credential as v, type CredentialConfig as w, type AuditEventStart as x, type AuditEventEnd as y, type AuditEvent as z };
|
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
CliRunner: () => CliRunner,
|
|
34
|
+
DEFAULT_ENV_ALLOWLIST: () => DEFAULT_ENV_ALLOWLIST,
|
|
34
35
|
GIT_LOG_FORMAT: () => GIT_LOG_FORMAT,
|
|
35
36
|
GitArgumentError: () => GitArgumentError,
|
|
36
37
|
GitError: () => GitError,
|
|
@@ -55,7 +56,8 @@ __export(src_exports, {
|
|
|
55
56
|
parseLsTree: () => parseLsTree,
|
|
56
57
|
parsePorcelainV2: () => parsePorcelainV2,
|
|
57
58
|
parseRecords: () => parseRecords,
|
|
58
|
-
parseWorktreeList: () => parseWorktreeList
|
|
59
|
+
parseWorktreeList: () => parseWorktreeList,
|
|
60
|
+
resolveInheritedEnv: () => resolveInheritedEnv
|
|
59
61
|
});
|
|
60
62
|
module.exports = __toCommonJS(src_exports);
|
|
61
63
|
|
|
@@ -563,6 +565,99 @@ function detectErrorCategory(stderr) {
|
|
|
563
565
|
|
|
564
566
|
// src/runner/cli-runner.ts
|
|
565
567
|
var import_node_process = __toESM(require("process"), 1);
|
|
568
|
+
|
|
569
|
+
// src/core/env.ts
|
|
570
|
+
var DEFAULT_ENV_ALLOWLIST = [
|
|
571
|
+
// Executable resolution
|
|
572
|
+
"PATH",
|
|
573
|
+
"PATHEXT",
|
|
574
|
+
// User home / identity
|
|
575
|
+
"HOME",
|
|
576
|
+
"USER",
|
|
577
|
+
"LOGNAME",
|
|
578
|
+
// Locale and time
|
|
579
|
+
"LANG",
|
|
580
|
+
"LANGUAGE",
|
|
581
|
+
"LC_ALL",
|
|
582
|
+
"LC_CTYPE",
|
|
583
|
+
"LC_MESSAGES",
|
|
584
|
+
"LC_NUMERIC",
|
|
585
|
+
"LC_TIME",
|
|
586
|
+
"LC_COLLATE",
|
|
587
|
+
"LC_MONETARY",
|
|
588
|
+
"TZ",
|
|
589
|
+
// Temporary directories
|
|
590
|
+
"TMPDIR",
|
|
591
|
+
"TMP",
|
|
592
|
+
"TEMP",
|
|
593
|
+
// Terminal
|
|
594
|
+
"TERM",
|
|
595
|
+
"COLORTERM",
|
|
596
|
+
// SSH agent (required for Git-over-SSH authentication)
|
|
597
|
+
"SSH_AUTH_SOCK",
|
|
598
|
+
"SSH_AGENT_PID",
|
|
599
|
+
// HTTP(S) proxy configuration (required for Git network operations behind a proxy)
|
|
600
|
+
"HTTP_PROXY",
|
|
601
|
+
"HTTPS_PROXY",
|
|
602
|
+
"http_proxy",
|
|
603
|
+
"https_proxy",
|
|
604
|
+
"ALL_PROXY",
|
|
605
|
+
"all_proxy",
|
|
606
|
+
"NO_PROXY",
|
|
607
|
+
"no_proxy",
|
|
608
|
+
// Windows essentials
|
|
609
|
+
"USERPROFILE",
|
|
610
|
+
"HOMEDRIVE",
|
|
611
|
+
"HOMEPATH",
|
|
612
|
+
"APPDATA",
|
|
613
|
+
"LOCALAPPDATA",
|
|
614
|
+
"PROGRAMDATA",
|
|
615
|
+
"ALLUSERSPROFILE",
|
|
616
|
+
"PROGRAMFILES",
|
|
617
|
+
"PROGRAMFILES(X86)",
|
|
618
|
+
"PROGRAMW6432",
|
|
619
|
+
"PUBLIC",
|
|
620
|
+
"SYSTEMROOT",
|
|
621
|
+
"SYSTEMDRIVE",
|
|
622
|
+
"WINDIR",
|
|
623
|
+
"COMSPEC",
|
|
624
|
+
"COMPUTERNAME",
|
|
625
|
+
"USERDOMAIN",
|
|
626
|
+
"NUMBER_OF_PROCESSORS",
|
|
627
|
+
"PROCESSOR_ARCHITECTURE"
|
|
628
|
+
];
|
|
629
|
+
function resolveInheritedEnv(parentEnv, inheritEnv, platform = "") {
|
|
630
|
+
if (inheritEnv === true) {
|
|
631
|
+
const all = {};
|
|
632
|
+
for (const [key, value] of Object.entries(parentEnv)) {
|
|
633
|
+
if (value !== void 0) {
|
|
634
|
+
all[key] = value;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
return all;
|
|
638
|
+
}
|
|
639
|
+
const allow = new Set(inheritEnv === false ? [] : DEFAULT_ENV_ALLOWLIST);
|
|
640
|
+
if (Array.isArray(inheritEnv)) {
|
|
641
|
+
for (const name of inheritEnv) {
|
|
642
|
+
allow.add(name);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
const isWindows = platform === "win32";
|
|
646
|
+
const allowLower = isWindows ? new Set([...allow].map((name) => name.toLowerCase())) : null;
|
|
647
|
+
const result = {};
|
|
648
|
+
for (const [key, value] of Object.entries(parentEnv)) {
|
|
649
|
+
if (value === void 0) {
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
const allowed = allowLower ? allowLower.has(key.toLowerCase()) : allow.has(key);
|
|
653
|
+
if (allowed) {
|
|
654
|
+
result[key] = value;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
return result;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// src/runner/cli-runner.ts
|
|
566
661
|
var FATAL_ERROR_PATTERN = /fatal:\s*(.+)/i;
|
|
567
662
|
var ERROR_PATTERN = /error:\s*(.+)/i;
|
|
568
663
|
var LINE_SEPARATOR_PATTERN = /\r|\n/;
|
|
@@ -616,6 +711,7 @@ var CliRunner = class _CliRunner {
|
|
|
616
711
|
exec;
|
|
617
712
|
gitBinary;
|
|
618
713
|
baseEnv;
|
|
714
|
+
inheritEnv;
|
|
619
715
|
pathPrefix;
|
|
620
716
|
home;
|
|
621
717
|
credential;
|
|
@@ -624,6 +720,7 @@ var CliRunner = class _CliRunner {
|
|
|
624
720
|
this.exec = adapters.exec;
|
|
625
721
|
this.gitBinary = options?.gitBinary ?? "git";
|
|
626
722
|
this.baseEnv = options?.env ?? {};
|
|
723
|
+
this.inheritEnv = options?.inheritEnv;
|
|
627
724
|
this.pathPrefix = options?.pathPrefix ?? [];
|
|
628
725
|
this.home = options?.home;
|
|
629
726
|
this.credential = options?.credential;
|
|
@@ -637,6 +734,7 @@ var CliRunner = class _CliRunner {
|
|
|
637
734
|
withOptions(options) {
|
|
638
735
|
const mergedEnv = { ...this.baseEnv, ...options.env };
|
|
639
736
|
const mergedPathPrefix = [...this.pathPrefix, ...options.pathPrefix ?? []];
|
|
737
|
+
const inheritEnv = options.inheritEnv ?? this.inheritEnv;
|
|
640
738
|
const home = options.home ?? this.home;
|
|
641
739
|
const credential = options.credential ?? this.credential;
|
|
642
740
|
const audit = options.audit ?? this.audit;
|
|
@@ -654,6 +752,7 @@ var CliRunner = class _CliRunner {
|
|
|
654
752
|
{
|
|
655
753
|
gitBinary: options.gitBinary ?? this.gitBinary,
|
|
656
754
|
env: mergedEnv,
|
|
755
|
+
inheritEnv,
|
|
657
756
|
pathPrefix: mergedPathPrefix,
|
|
658
757
|
home,
|
|
659
758
|
credential,
|
|
@@ -685,10 +784,16 @@ var CliRunner = class _CliRunner {
|
|
|
685
784
|
/**
|
|
686
785
|
* Build the effective environment for command execution
|
|
687
786
|
*
|
|
688
|
-
*
|
|
787
|
+
* Seeds the environment from the inherited (allowlisted) parent variables, then layers
|
|
788
|
+
* the configured `env`, home directory, and PATH prefix overrides on top. The parent
|
|
789
|
+
* process environment is never forwarded wholesale unless `inheritEnv: true` is set
|
|
790
|
+
* (environment variable traversal prevention).
|
|
689
791
|
*/
|
|
690
792
|
buildEnv() {
|
|
691
|
-
const env = {
|
|
793
|
+
const env = {
|
|
794
|
+
...resolveInheritedEnv(import_node_process.default.env, this.inheritEnv, import_node_process.default.platform),
|
|
795
|
+
...this.baseEnv
|
|
796
|
+
};
|
|
692
797
|
if (this.home) {
|
|
693
798
|
env.HOME = this.home;
|
|
694
799
|
env.USERPROFILE = this.home;
|
|
@@ -701,9 +806,11 @@ var CliRunner = class _CliRunner {
|
|
|
701
806
|
}
|
|
702
807
|
}
|
|
703
808
|
if (allPathPrefixes.length > 0) {
|
|
704
|
-
const
|
|
705
|
-
const
|
|
706
|
-
|
|
809
|
+
const isWindows = import_node_process.default.platform === "win32";
|
|
810
|
+
const separator = isWindows ? ";" : ":";
|
|
811
|
+
const pathKey = isWindows ? Object.keys(env).find((key) => key.toLowerCase() === "path") ?? "PATH" : "PATH";
|
|
812
|
+
const currentPath = env[pathKey] ?? "";
|
|
813
|
+
env[pathKey] = [...allPathPrefixes, currentPath].join(separator);
|
|
707
814
|
}
|
|
708
815
|
if (this.audit?.onTrace) {
|
|
709
816
|
if (env.GIT_TRACE === void 0) {
|
|
@@ -754,6 +861,9 @@ var CliRunner = class _CliRunner {
|
|
|
754
861
|
{
|
|
755
862
|
argv,
|
|
756
863
|
env,
|
|
864
|
+
// The env above is already fully resolved (including any inherited variables),
|
|
865
|
+
// so the adapter must not merge the parent environment on top of it.
|
|
866
|
+
inheritEnv: false,
|
|
757
867
|
cwd: context.type === "worktree" ? context.workdir : void 0,
|
|
758
868
|
signal
|
|
759
869
|
},
|
|
@@ -5528,6 +5638,7 @@ function toCliRunnerOptions(opts) {
|
|
|
5528
5638
|
}
|
|
5529
5639
|
return {
|
|
5530
5640
|
env: opts.env,
|
|
5641
|
+
inheritEnv: opts.inheritEnv,
|
|
5531
5642
|
pathPrefix: opts.pathPrefix,
|
|
5532
5643
|
home: opts.home,
|
|
5533
5644
|
credential: opts.credential ? {
|
|
@@ -5971,6 +6082,12 @@ async function createGit(options) {
|
|
|
5971
6082
|
|
|
5972
6083
|
// src/adapters/node/exec.ts
|
|
5973
6084
|
var import_node_child_process = require("child_process");
|
|
6085
|
+
function resolveChildEnv(env, inheritEnv) {
|
|
6086
|
+
if (inheritEnv === false) {
|
|
6087
|
+
return env ?? {};
|
|
6088
|
+
}
|
|
6089
|
+
return env ? { ...process.env, ...env } : process.env;
|
|
6090
|
+
}
|
|
5974
6091
|
async function* streamToAsyncIterable(stream) {
|
|
5975
6092
|
let buffer = "";
|
|
5976
6093
|
for await (const chunk of stream) {
|
|
@@ -5997,7 +6114,7 @@ var NodeExecAdapter = class {
|
|
|
5997
6114
|
};
|
|
5998
6115
|
}
|
|
5999
6116
|
spawn(options, handlers) {
|
|
6000
|
-
const { argv, env, cwd, signal } = options;
|
|
6117
|
+
const { argv, env, inheritEnv, cwd, signal } = options;
|
|
6001
6118
|
const command = argv[0];
|
|
6002
6119
|
if (command === void 0) {
|
|
6003
6120
|
throw new Error("argv must not be empty");
|
|
@@ -6006,7 +6123,7 @@ var NodeExecAdapter = class {
|
|
|
6006
6123
|
return new Promise((resolve, reject) => {
|
|
6007
6124
|
const child = (0, import_node_child_process.spawn)(command, args, {
|
|
6008
6125
|
cwd,
|
|
6009
|
-
env: env
|
|
6126
|
+
env: resolveChildEnv(env, inheritEnv),
|
|
6010
6127
|
stdio: ["ignore", "pipe", "pipe"]
|
|
6011
6128
|
});
|
|
6012
6129
|
let stdout = "";
|
|
@@ -6054,7 +6171,7 @@ var NodeExecAdapter = class {
|
|
|
6054
6171
|
});
|
|
6055
6172
|
}
|
|
6056
6173
|
spawnStreaming(options) {
|
|
6057
|
-
const { argv, env, cwd, signal } = options;
|
|
6174
|
+
const { argv, env, inheritEnv, cwd, signal } = options;
|
|
6058
6175
|
const command = argv[0];
|
|
6059
6176
|
if (command === void 0) {
|
|
6060
6177
|
throw new Error("argv must not be empty");
|
|
@@ -6062,7 +6179,7 @@ var NodeExecAdapter = class {
|
|
|
6062
6179
|
const args = argv.slice(1);
|
|
6063
6180
|
const child = (0, import_node_child_process.spawn)(command, args, {
|
|
6064
6181
|
cwd,
|
|
6065
|
-
env: env
|
|
6182
|
+
env: resolveChildEnv(env, inheritEnv),
|
|
6066
6183
|
stdio: ["ignore", "pipe", "pipe"]
|
|
6067
6184
|
});
|
|
6068
6185
|
let aborted = false;
|
|
@@ -6460,6 +6577,7 @@ var TypeGit = class _TypeGit {
|
|
|
6460
6577
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6461
6578
|
0 && (module.exports = {
|
|
6462
6579
|
CliRunner,
|
|
6580
|
+
DEFAULT_ENV_ALLOWLIST,
|
|
6463
6581
|
GIT_LOG_FORMAT,
|
|
6464
6582
|
GitArgumentError,
|
|
6465
6583
|
GitError,
|
|
@@ -6484,6 +6602,7 @@ var TypeGit = class _TypeGit {
|
|
|
6484
6602
|
parseLsTree,
|
|
6485
6603
|
parsePorcelainV2,
|
|
6486
6604
|
parseRecords,
|
|
6487
|
-
parseWorktreeList
|
|
6605
|
+
parseWorktreeList,
|
|
6606
|
+
resolveInheritedEnv
|
|
6488
6607
|
});
|
|
6489
6608
|
//# sourceMappingURL=index.cjs.map
|