@vibe-agent-toolkit/utils 0.1.39 → 0.1.40-rc.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.
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
* argv. **Not** passed through a shell — operators (`|`, `&&`, `$(...)`)
|
|
10
10
|
* become literal argv elements, per the design's §6.1 sharp-edge note.
|
|
11
11
|
*
|
|
12
|
+
* Command sources can be disabled at runtime with `VAT_LINKAUTH_ALLOW_COMMAND=0`
|
|
13
|
+
* (or by passing `allowCommand: false` in deps). Useful in security-sensitive
|
|
14
|
+
* environments where arbitrary command execution is undesirable.
|
|
15
|
+
*
|
|
12
16
|
* Returns `undefined` if every source fails or yields an empty/whitespace
|
|
13
17
|
* value — the caller's `resolveAuthenticatedUrl` translates that to the
|
|
14
18
|
* `unverified` outcome (surfaced as `LINK_AUTH_UNVERIFIED` by the validator).
|
|
@@ -37,11 +41,33 @@ export interface TokenResolutionDeps {
|
|
|
37
41
|
success: boolean;
|
|
38
42
|
stdout: string;
|
|
39
43
|
};
|
|
44
|
+
/**
|
|
45
|
+
* Whether `{ command: ... }` sources are allowed. Defaults to
|
|
46
|
+
* `process.env['VAT_LINKAUTH_ALLOW_COMMAND'] !== '0'`. Set to `false` (or
|
|
47
|
+
* export `VAT_LINKAUTH_ALLOW_COMMAND=0`) to skip all command sources and rely
|
|
48
|
+
* solely on env-var sources — useful in locked-down CI or security reviews.
|
|
49
|
+
*/
|
|
50
|
+
readonly allowCommand: boolean;
|
|
40
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Return a copy of the given env with all `GIT_*` keys removed. Case-insensitive
|
|
54
|
+
* on the key so Windows env vars (which are case-insensitive at the OS level,
|
|
55
|
+
* though `process.env` preserves original case) can't sneak through as e.g.
|
|
56
|
+
* `Git_Dir`.
|
|
57
|
+
*
|
|
58
|
+
* Exported for unit testing and for callers assembling their own `runCommand`
|
|
59
|
+
* who want the exact same scrub `defaultRunCommand` applies.
|
|
60
|
+
*
|
|
61
|
+
* Rationale: `vat resources validate` is often invoked from git pre-commit
|
|
62
|
+
* hooks, which pre-set `GIT_DIR` / `GIT_WORK_TREE` / `GIT_INDEX_FILE`. These
|
|
63
|
+
* poison any nested tool that shells out to git, notably `gh auth token`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function scrubGitEnv(source: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
41
66
|
/**
|
|
42
67
|
* Default `runCommand` implementation — exported so callers that want to
|
|
43
68
|
* memoize per-validate-run can wrap it without duplicating the spawn logic.
|
|
44
|
-
* Forwards to `safeExecResult` (no shell, argv-based)
|
|
69
|
+
* Forwards to `safeExecResult` (no shell, argv-based), with `GIT_*` vars
|
|
70
|
+
* stripped from the child env — see {@link scrubGitEnv}.
|
|
45
71
|
*/
|
|
46
72
|
export declare const defaultRunCommand: TokenResolutionDeps['runCommand'];
|
|
47
73
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-token.d.ts","sourceRoot":"","sources":["../../src/link-auth/resolve-token.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"resolve-token.d.ts","sourceRoot":"","sources":["../../src/link-auth/resolve-token.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,MAAM,MAAM,WAAW,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAA;CAAE,CAAC;AAEtG,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAEjD;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,KAAK;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAEvF;;;;;OAKG;IACH,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;CAChC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAIxE;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,EAAE,mBAAmB,CAAC,YAAY,CAO/D,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,SAAS,WAAW,EAAE,EAC/B,IAAI,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAClC,MAAM,GAAG,SAAS,CAWpB"}
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
* argv. **Not** passed through a shell — operators (`|`, `&&`, `$(...)`)
|
|
10
10
|
* become literal argv elements, per the design's §6.1 sharp-edge note.
|
|
11
11
|
*
|
|
12
|
+
* Command sources can be disabled at runtime with `VAT_LINKAUTH_ALLOW_COMMAND=0`
|
|
13
|
+
* (or by passing `allowCommand: false` in deps). Useful in security-sensitive
|
|
14
|
+
* environments where arbitrary command execution is undesirable.
|
|
15
|
+
*
|
|
12
16
|
* Returns `undefined` if every source fails or yields an empty/whitespace
|
|
13
17
|
* value — the caller's `resolveAuthenticatedUrl` translates that to the
|
|
14
18
|
* `unverified` outcome (surfaced as `LINK_AUTH_UNVERIFIED` by the validator).
|
|
@@ -17,10 +21,27 @@
|
|
|
17
21
|
* `safeExecSync`-backed, `shell: false`).
|
|
18
22
|
*/
|
|
19
23
|
import { safeExecResult } from '../safe-exec.js';
|
|
24
|
+
/**
|
|
25
|
+
* Return a copy of the given env with all `GIT_*` keys removed. Case-insensitive
|
|
26
|
+
* on the key so Windows env vars (which are case-insensitive at the OS level,
|
|
27
|
+
* though `process.env` preserves original case) can't sneak through as e.g.
|
|
28
|
+
* `Git_Dir`.
|
|
29
|
+
*
|
|
30
|
+
* Exported for unit testing and for callers assembling their own `runCommand`
|
|
31
|
+
* who want the exact same scrub `defaultRunCommand` applies.
|
|
32
|
+
*
|
|
33
|
+
* Rationale: `vat resources validate` is often invoked from git pre-commit
|
|
34
|
+
* hooks, which pre-set `GIT_DIR` / `GIT_WORK_TREE` / `GIT_INDEX_FILE`. These
|
|
35
|
+
* poison any nested tool that shells out to git, notably `gh auth token`.
|
|
36
|
+
*/
|
|
37
|
+
export function scrubGitEnv(source) {
|
|
38
|
+
return Object.fromEntries(Object.entries(source).filter(([k]) => !k.toUpperCase().startsWith('GIT_')));
|
|
39
|
+
}
|
|
20
40
|
/**
|
|
21
41
|
* Default `runCommand` implementation — exported so callers that want to
|
|
22
42
|
* memoize per-validate-run can wrap it without duplicating the spawn logic.
|
|
23
|
-
* Forwards to `safeExecResult` (no shell, argv-based)
|
|
43
|
+
* Forwards to `safeExecResult` (no shell, argv-based), with `GIT_*` vars
|
|
44
|
+
* stripped from the child env — see {@link scrubGitEnv}.
|
|
24
45
|
*/
|
|
25
46
|
export const defaultRunCommand = (argv) => {
|
|
26
47
|
if (argv.length === 0)
|
|
@@ -28,7 +49,7 @@ export const defaultRunCommand = (argv) => {
|
|
|
28
49
|
const [bin, ...args] = argv;
|
|
29
50
|
if (bin === undefined)
|
|
30
51
|
return { success: false, stdout: '' };
|
|
31
|
-
const result = safeExecResult(bin, [...args], { encoding: 'utf8' });
|
|
52
|
+
const result = safeExecResult(bin, [...args], { encoding: 'utf8', env: scrubGitEnv(process.env) });
|
|
32
53
|
const stdout = typeof result.stdout === 'string' ? result.stdout : result.stdout.toString('utf8');
|
|
33
54
|
return { success: result.success, stdout };
|
|
34
55
|
};
|
|
@@ -42,7 +63,10 @@ export const defaultRunCommand = (argv) => {
|
|
|
42
63
|
export function resolveToken(sources, deps) {
|
|
43
64
|
const env = deps?.env ?? process.env;
|
|
44
65
|
const runCommand = deps?.runCommand ?? defaultRunCommand;
|
|
66
|
+
const allowCommand = deps?.allowCommand ?? (process.env['VAT_LINKAUTH_ALLOW_COMMAND'] !== '0');
|
|
45
67
|
for (const source of sources) {
|
|
68
|
+
if (!allowCommand && 'command' in source)
|
|
69
|
+
continue;
|
|
46
70
|
const value = tryResolveSource(source, env, runCommand);
|
|
47
71
|
if (value !== undefined && value.length > 0)
|
|
48
72
|
return value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-token.js","sourceRoot":"","sources":["../../src/link-auth/resolve-token.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"resolve-token.js","sourceRoot":"","sources":["../../src/link-auth/resolve-token.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA4BjD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,MAAyB;IACnD,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CACvD,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAsC,CAAC,IAAI,EAAE,EAAE;IAC3E,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAC7D,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAC5B,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAC7D,MAAM,MAAM,GAAG,cAAc,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,QAAQ,EAA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