type-git 0.3.0-alpha.0 → 0.3.0-alpha.2

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.
@@ -1,3 +1,89 @@
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
+ * Fine-grained adjustment of the default allowlist.
16
+ *
17
+ * Starts from {@link DEFAULT_ENV_ALLOWLIST}, adds the names in `add`, then removes the
18
+ * names in `remove`. `remove` takes precedence, so `{ add: ['X'], remove: ['X'] }`
19
+ * excludes `X`. This is the way to drop a single default entry (for example
20
+ * `{ remove: ['SSH_AUTH_SOCK', 'SSH_AGENT_PID'] }` for an HTTPS-only application) while
21
+ * keeping the rest of the curated defaults.
22
+ */
23
+ type EnvAllowlistAdjustment = {
24
+ /** Variable names to add to the default allowlist. */
25
+ add?: string[];
26
+ /** Variable names to remove from the (default + add) allowlist. */
27
+ remove?: string[];
28
+ };
29
+ /**
30
+ * Predicate deciding, per variable, whether it is inherited from the parent environment.
31
+ * Receives each parent environment variable name and returns `true` to inherit it. This
32
+ * gives full control and bypasses the default allowlist entirely — reference
33
+ * {@link DEFAULT_ENV_ALLOWLIST} explicitly if you want to build on top of it.
34
+ *
35
+ * Note: on Windows the name is passed through as-is, so handle case-insensitivity yourself
36
+ * (e.g. compare against `name.toUpperCase()`).
37
+ */
38
+ type EnvInheritancePredicate = (name: string) => boolean;
39
+ /**
40
+ * Controls how the parent process environment is inherited by spawned Git commands.
41
+ *
42
+ * - `undefined` (default): inherit only {@link DEFAULT_ENV_ALLOWLIST} — the variables
43
+ * Git needs to function. Sensitive variables are not passed through.
44
+ * - `true`: inherit the entire parent environment (legacy behavior, opt-in).
45
+ * - `false`: inherit nothing. The child only receives explicitly provided variables and
46
+ * values computed by the library (e.g. `HOME`, `PATH` prefixes). Note that this may
47
+ * break Git if `PATH` is not otherwise supplied.
48
+ * - `string[]`: inherit {@link DEFAULT_ENV_ALLOWLIST} plus the named variables. Use this
49
+ * to explicitly opt specific variables (e.g. an SSH command or a token) back in.
50
+ * - `{ add?, remove? }`: inherit {@link DEFAULT_ENV_ALLOWLIST}, plus `add`, minus `remove`.
51
+ * Use this to drop a single default entry without rebuilding the whole allowlist.
52
+ * - `(name) => boolean`: a predicate that decides each variable individually, bypassing the
53
+ * default allowlist entirely.
54
+ */
55
+ type EnvInheritance = boolean | string[] | EnvAllowlistAdjustment | EnvInheritancePredicate;
56
+ /**
57
+ * Curated allowlist of environment variables inherited by default.
58
+ *
59
+ * These are variables Git (and the tools it shells out to, such as ssh and credential
60
+ * helpers) commonly needs to operate. The list intentionally excludes arbitrary
61
+ * application secrets so they are not silently forwarded to Git subprocesses.
62
+ *
63
+ * Security notes:
64
+ * - The SSH agent vars (`SSH_AUTH_SOCK`, `SSH_AGENT_PID`) and SSH/TLS transport config
65
+ * (`GIT_SSH_COMMAND`, `GIT_SSL_CAINFO`, …) are inherited by default so Git-over-SSH and
66
+ * fetch/push keep working out of the box. For an HTTPS-only application that does not
67
+ * want to expose the SSH agent, drop it with
68
+ * `inheritEnv: { remove: ['SSH_AUTH_SOCK', 'SSH_AGENT_PID'] }`.
69
+ * - The most credential-prone helpers (`GIT_ASKPASS`, `SSH_ASKPASS`, `GIT_PROXY_COMMAND`)
70
+ * are intentionally NOT in the default allowlist; opt them back in explicitly
71
+ * (`inheritEnv: ['GIT_ASKPASS']`) only when you trust the value.
72
+ *
73
+ * Variable names are matched case-insensitively on Windows.
74
+ */
75
+ declare const DEFAULT_ENV_ALLOWLIST: readonly string[];
76
+ /**
77
+ * Resolve the set of environment variables to inherit from the parent process.
78
+ *
79
+ * @param parentEnv - The parent process environment (e.g. `process.env`).
80
+ * @param inheritEnv - Inheritance policy. See {@link EnvInheritance}.
81
+ * @param platform - The runtime platform (e.g. `process.platform`). When `'win32'`,
82
+ * variable names are matched case-insensitively.
83
+ * @returns A record containing only the inherited variables (undefined values removed).
84
+ */
85
+ declare function resolveInheritedEnv(parentEnv: Record<string, string | undefined>, inheritEnv?: EnvInheritance, platform?: string): Record<string, string>;
86
+
1
87
  /**
2
88
  * Core type definitions for the type-safe Git wrapper library
3
89
  *
@@ -9,6 +95,7 @@
9
95
  * - Output contracts for typed parsing
10
96
  * - Branded types for type safety
11
97
  */
98
+
12
99
  /**
13
100
  * Brand symbol for NonEmptyString
14
101
  * @internal
@@ -248,12 +335,20 @@ type Capabilities = {
248
335
  lfsVersion?: string;
249
336
  };
250
337
  /**
251
- * LFS mode configuration
338
+ * LFS mode configuration.
339
+ *
340
+ * - `'enabled'` (default): LFS behaves normally.
341
+ * - `'disabled'`: the `repo.lfs.*` / `repo.lfsExtra.*` helpers become no-ops.
342
+ * - object form: working-tree-populating operations (`checkout`, `switch`,
343
+ * `reset`, `merge`, `pull`, `rebase`, `restore`) run with
344
+ * `GIT_LFS_SKIP_SMUDGE=1` so Git leaves LFS pointer files in place instead of
345
+ * downloading their contents. The objects can be materialized later via the
346
+ * explicit `repo.lfs.pull()` / `repo.lfs.checkout()` helpers.
252
347
  */
253
348
  type LfsMode = 'enabled' | 'disabled' | {
254
- /** Skip smudge filter (don't download LFS files on checkout) */
349
+ /** Skip smudge filter (don't download LFS files on checkout). */
255
350
  skipSmudge?: boolean;
256
- /** Skip download (keep pointer files) */
351
+ /** Skip download, keeping pointer files (also implies skip-smudge). */
257
352
  skipDownload?: boolean;
258
353
  };
259
354
  /**
@@ -331,6 +426,18 @@ type GitOpenOptions = {
331
426
  credentialHelper?: string;
332
427
  /** Additional environment variables */
333
428
  env?: Record<string, string>;
429
+ /**
430
+ * Controls how the parent process environment is inherited by spawned Git commands.
431
+ *
432
+ * By default, only a curated allowlist of variables that Git needs to operate is
433
+ * inherited (environment variable traversal prevention). See {@link EnvInheritance} for
434
+ * all supported forms:
435
+ * - `true` — inherit the full parent environment.
436
+ * - `string[]` — inherit the default allowlist plus the named variables.
437
+ * - `{ add?, remove? }` — adjust the default allowlist (e.g. drop `SSH_AUTH_SOCK`).
438
+ * - `(name) => boolean` — decide each variable individually.
439
+ */
440
+ inheritEnv?: EnvInheritance;
334
441
  /** Directories to prepend to PATH */
335
442
  pathPrefix?: string[];
336
443
  /** Credential configuration (§6.4) */
@@ -518,6 +625,16 @@ type SpawnOptions = {
518
625
  argv: string[];
519
626
  /** Additional environment variables */
520
627
  env?: Record<string, string>;
628
+ /**
629
+ * Whether to merge the parent process environment underneath `env`.
630
+ *
631
+ * - `true` (default when omitted): the parent environment is merged underneath `env`,
632
+ * so the child inherits the full parent environment with `env` overrides on top.
633
+ * - `false`: the child receives only the variables in `env` (and nothing from the
634
+ * parent process). This prevents implicit environment variable traversal — used by
635
+ * {@link CliRunner}, which resolves the inherited variables itself.
636
+ */
637
+ inheritEnv?: boolean;
521
638
  /** Working directory */
522
639
  cwd?: string;
523
640
  /** AbortSignal for cancellation */
@@ -728,4 +845,4 @@ interface RuntimeAdapters {
728
845
  */
729
846
  type AdapterFactory = () => RuntimeAdapters;
730
847
 
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 ExecutionContext as i, GitError as j, type AdapterFactory as k, isNonEmpty as l, type LfsProgress as m, nonEmpty as n, type GitErrorKind as o, GitArgumentError as p, type Runtime as q, type CommandSpec as r, type CredentialRequest as s, type Credential as t, type CredentialConfig as u, type AuditEventStart as v, type AuditEventEnd as w, type AuditEvent as x, type TraceEvent as y };
848
+ export { type AuditConfig as A, type AuditEventEnd as B, type Capabilities as C, DEFAULT_ENV_ALLOWLIST as D, type ExecAdapter as E, type FsAdapter as F, type GitErrorCategory as G, type AuditEvent as H, type TraceEvent as I, 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, type EnvAllowlistAdjustment as m, type EnvInheritancePredicate as n, nonEmpty as o, isNonEmpty as p, type LfsProgress as q, resolveInheritedEnv as r, type GitErrorKind as s, GitArgumentError as t, type Runtime as u, type CommandSpec as v, type CredentialRequest as w, type Credential as x, type CredentialConfig as y, type AuditEventStart as z };
@@ -1,3 +1,89 @@
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
+ * Fine-grained adjustment of the default allowlist.
16
+ *
17
+ * Starts from {@link DEFAULT_ENV_ALLOWLIST}, adds the names in `add`, then removes the
18
+ * names in `remove`. `remove` takes precedence, so `{ add: ['X'], remove: ['X'] }`
19
+ * excludes `X`. This is the way to drop a single default entry (for example
20
+ * `{ remove: ['SSH_AUTH_SOCK', 'SSH_AGENT_PID'] }` for an HTTPS-only application) while
21
+ * keeping the rest of the curated defaults.
22
+ */
23
+ type EnvAllowlistAdjustment = {
24
+ /** Variable names to add to the default allowlist. */
25
+ add?: string[];
26
+ /** Variable names to remove from the (default + add) allowlist. */
27
+ remove?: string[];
28
+ };
29
+ /**
30
+ * Predicate deciding, per variable, whether it is inherited from the parent environment.
31
+ * Receives each parent environment variable name and returns `true` to inherit it. This
32
+ * gives full control and bypasses the default allowlist entirely — reference
33
+ * {@link DEFAULT_ENV_ALLOWLIST} explicitly if you want to build on top of it.
34
+ *
35
+ * Note: on Windows the name is passed through as-is, so handle case-insensitivity yourself
36
+ * (e.g. compare against `name.toUpperCase()`).
37
+ */
38
+ type EnvInheritancePredicate = (name: string) => boolean;
39
+ /**
40
+ * Controls how the parent process environment is inherited by spawned Git commands.
41
+ *
42
+ * - `undefined` (default): inherit only {@link DEFAULT_ENV_ALLOWLIST} — the variables
43
+ * Git needs to function. Sensitive variables are not passed through.
44
+ * - `true`: inherit the entire parent environment (legacy behavior, opt-in).
45
+ * - `false`: inherit nothing. The child only receives explicitly provided variables and
46
+ * values computed by the library (e.g. `HOME`, `PATH` prefixes). Note that this may
47
+ * break Git if `PATH` is not otherwise supplied.
48
+ * - `string[]`: inherit {@link DEFAULT_ENV_ALLOWLIST} plus the named variables. Use this
49
+ * to explicitly opt specific variables (e.g. an SSH command or a token) back in.
50
+ * - `{ add?, remove? }`: inherit {@link DEFAULT_ENV_ALLOWLIST}, plus `add`, minus `remove`.
51
+ * Use this to drop a single default entry without rebuilding the whole allowlist.
52
+ * - `(name) => boolean`: a predicate that decides each variable individually, bypassing the
53
+ * default allowlist entirely.
54
+ */
55
+ type EnvInheritance = boolean | string[] | EnvAllowlistAdjustment | EnvInheritancePredicate;
56
+ /**
57
+ * Curated allowlist of environment variables inherited by default.
58
+ *
59
+ * These are variables Git (and the tools it shells out to, such as ssh and credential
60
+ * helpers) commonly needs to operate. The list intentionally excludes arbitrary
61
+ * application secrets so they are not silently forwarded to Git subprocesses.
62
+ *
63
+ * Security notes:
64
+ * - The SSH agent vars (`SSH_AUTH_SOCK`, `SSH_AGENT_PID`) and SSH/TLS transport config
65
+ * (`GIT_SSH_COMMAND`, `GIT_SSL_CAINFO`, …) are inherited by default so Git-over-SSH and
66
+ * fetch/push keep working out of the box. For an HTTPS-only application that does not
67
+ * want to expose the SSH agent, drop it with
68
+ * `inheritEnv: { remove: ['SSH_AUTH_SOCK', 'SSH_AGENT_PID'] }`.
69
+ * - The most credential-prone helpers (`GIT_ASKPASS`, `SSH_ASKPASS`, `GIT_PROXY_COMMAND`)
70
+ * are intentionally NOT in the default allowlist; opt them back in explicitly
71
+ * (`inheritEnv: ['GIT_ASKPASS']`) only when you trust the value.
72
+ *
73
+ * Variable names are matched case-insensitively on Windows.
74
+ */
75
+ declare const DEFAULT_ENV_ALLOWLIST: readonly string[];
76
+ /**
77
+ * Resolve the set of environment variables to inherit from the parent process.
78
+ *
79
+ * @param parentEnv - The parent process environment (e.g. `process.env`).
80
+ * @param inheritEnv - Inheritance policy. See {@link EnvInheritance}.
81
+ * @param platform - The runtime platform (e.g. `process.platform`). When `'win32'`,
82
+ * variable names are matched case-insensitively.
83
+ * @returns A record containing only the inherited variables (undefined values removed).
84
+ */
85
+ declare function resolveInheritedEnv(parentEnv: Record<string, string | undefined>, inheritEnv?: EnvInheritance, platform?: string): Record<string, string>;
86
+
1
87
  /**
2
88
  * Core type definitions for the type-safe Git wrapper library
3
89
  *
@@ -9,6 +95,7 @@
9
95
  * - Output contracts for typed parsing
10
96
  * - Branded types for type safety
11
97
  */
98
+
12
99
  /**
13
100
  * Brand symbol for NonEmptyString
14
101
  * @internal
@@ -248,12 +335,20 @@ type Capabilities = {
248
335
  lfsVersion?: string;
249
336
  };
250
337
  /**
251
- * LFS mode configuration
338
+ * LFS mode configuration.
339
+ *
340
+ * - `'enabled'` (default): LFS behaves normally.
341
+ * - `'disabled'`: the `repo.lfs.*` / `repo.lfsExtra.*` helpers become no-ops.
342
+ * - object form: working-tree-populating operations (`checkout`, `switch`,
343
+ * `reset`, `merge`, `pull`, `rebase`, `restore`) run with
344
+ * `GIT_LFS_SKIP_SMUDGE=1` so Git leaves LFS pointer files in place instead of
345
+ * downloading their contents. The objects can be materialized later via the
346
+ * explicit `repo.lfs.pull()` / `repo.lfs.checkout()` helpers.
252
347
  */
253
348
  type LfsMode = 'enabled' | 'disabled' | {
254
- /** Skip smudge filter (don't download LFS files on checkout) */
349
+ /** Skip smudge filter (don't download LFS files on checkout). */
255
350
  skipSmudge?: boolean;
256
- /** Skip download (keep pointer files) */
351
+ /** Skip download, keeping pointer files (also implies skip-smudge). */
257
352
  skipDownload?: boolean;
258
353
  };
259
354
  /**
@@ -331,6 +426,18 @@ type GitOpenOptions = {
331
426
  credentialHelper?: string;
332
427
  /** Additional environment variables */
333
428
  env?: Record<string, string>;
429
+ /**
430
+ * Controls how the parent process environment is inherited by spawned Git commands.
431
+ *
432
+ * By default, only a curated allowlist of variables that Git needs to operate is
433
+ * inherited (environment variable traversal prevention). See {@link EnvInheritance} for
434
+ * all supported forms:
435
+ * - `true` — inherit the full parent environment.
436
+ * - `string[]` — inherit the default allowlist plus the named variables.
437
+ * - `{ add?, remove? }` — adjust the default allowlist (e.g. drop `SSH_AUTH_SOCK`).
438
+ * - `(name) => boolean` — decide each variable individually.
439
+ */
440
+ inheritEnv?: EnvInheritance;
334
441
  /** Directories to prepend to PATH */
335
442
  pathPrefix?: string[];
336
443
  /** Credential configuration (§6.4) */
@@ -518,6 +625,16 @@ type SpawnOptions = {
518
625
  argv: string[];
519
626
  /** Additional environment variables */
520
627
  env?: Record<string, string>;
628
+ /**
629
+ * Whether to merge the parent process environment underneath `env`.
630
+ *
631
+ * - `true` (default when omitted): the parent environment is merged underneath `env`,
632
+ * so the child inherits the full parent environment with `env` overrides on top.
633
+ * - `false`: the child receives only the variables in `env` (and nothing from the
634
+ * parent process). This prevents implicit environment variable traversal — used by
635
+ * {@link CliRunner}, which resolves the inherited variables itself.
636
+ */
637
+ inheritEnv?: boolean;
521
638
  /** Working directory */
522
639
  cwd?: string;
523
640
  /** AbortSignal for cancellation */
@@ -728,4 +845,4 @@ interface RuntimeAdapters {
728
845
  */
729
846
  type AdapterFactory = () => RuntimeAdapters;
730
847
 
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 ExecutionContext as i, GitError as j, type AdapterFactory as k, isNonEmpty as l, type LfsProgress as m, nonEmpty as n, type GitErrorKind as o, GitArgumentError as p, type Runtime as q, type CommandSpec as r, type CredentialRequest as s, type Credential as t, type CredentialConfig as u, type AuditEventStart as v, type AuditEventEnd as w, type AuditEvent as x, type TraceEvent as y };
848
+ export { type AuditConfig as A, type AuditEventEnd as B, type Capabilities as C, DEFAULT_ENV_ALLOWLIST as D, type ExecAdapter as E, type FsAdapter as F, type GitErrorCategory as G, type AuditEvent as H, type TraceEvent as I, 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, type EnvAllowlistAdjustment as m, type EnvInheritancePredicate as n, nonEmpty as o, isNonEmpty as p, type LfsProgress as q, resolveInheritedEnv as r, type GitErrorKind as s, GitArgumentError as t, type Runtime as u, type CommandSpec as v, type CredentialRequest as w, type Credential as x, type CredentialConfig as y, type AuditEventStart as z };