passport-bridge 0.46.0 → 0.47.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.
- package/dist/cliGitCredential.d.ts +2 -0
- package/dist/cliGitCredential.js +15 -7
- package/dist/cliGuardHealth.d.ts +5 -0
- package/dist/cliGuardHealth.js +6 -1
- package/dist/cliHook.d.ts +3 -13
- package/dist/cliHook.js +68 -43
- package/dist/cliHookClients.d.ts +3 -0
- package/dist/cliHookClients.js +4 -0
- package/dist/cliHookDecide.d.ts +11 -3
- package/dist/cliHookDecide.js +100 -9
- package/dist/cliHookDeliver.js +5 -2
- package/dist/cliHookInput.d.ts +2 -0
- package/dist/cliHookInput.js +10 -0
- package/dist/cliHookInstall.d.ts +6 -1
- package/dist/cliHookInstall.js +36 -9
- package/dist/cliHookStatus.d.ts +13 -0
- package/dist/cliHookStatus.js +54 -5
- package/dist/cliSetupLock.d.ts +1 -1
- package/dist/cliSetupLock.js +4 -3
- package/dist/cliSigningKeys.d.ts +10 -0
- package/dist/cliSigningKeys.js +10 -0
- package/dist/cliStatus.d.ts +5 -0
- package/dist/cliStatus.js +15 -5
- package/dist/controlPlane.generated.d.ts +12 -27
- package/dist/controlPlane.generated.js +11 -2
- package/dist/controlPlaneCli.js +5 -2
- package/dist/controlPlaneGuard.js +9 -5
- package/dist/controlPlaneModel.generated.js +3 -0
- package/dist/controlPlaneOffline.d.ts +67 -0
- package/dist/controlPlaneOffline.js +213 -0
- package/dist/controlPlanePeople.generated.d.ts +9 -0
- package/dist/controlPlaneRailwayGuard.d.ts +7 -0
- package/dist/controlPlaneRailwayGuard.js +15 -2
- package/dist/controlPlaneRoutes.generated.d.ts +63 -0
- package/dist/controlPlaneRoutes.generated.js +111 -0
- package/dist/controlPlaneSupabase.d.ts +7 -0
- package/dist/controlPlaneSupabase.js +16 -3
- package/dist/cpCli.d.ts +20 -0
- package/dist/cpCli.js +102 -1
- package/dist/cpRefusal.d.ts +8 -0
- package/dist/cpRefusal.js +13 -0
- package/dist/gitCredentialRetire.d.ts +25 -0
- package/dist/gitCredentialRetire.js +143 -0
- package/dist/hookAdapters.d.ts +44 -0
- package/dist/hookAdapters.js +106 -0
- package/dist/lockedHooks.d.ts +13 -11
- package/dist/lockedHooks.js +19 -16
- package/dist/managedHooks.d.ts +2 -0
- package/dist/managedHooks.js +24 -3
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/testHookEnv.d.ts +2 -0
- package/dist/testHookEnv.js +26 -0
- package/dist/testSigning.d.ts +5 -0
- package/dist/testSigning.js +19 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/cpCli.js
CHANGED
|
@@ -7,10 +7,12 @@
|
|
|
7
7
|
* Reading never throws: a missing, corrupt, oversized or foreign-owned copy is treated as absent (nothing is asked
|
|
8
8
|
* but commands that can't be undone on this computer). Refreshing never rejects: any failure keeps the previous copy.
|
|
9
9
|
*/
|
|
10
|
+
import { createPublicKey, verify } from "node:crypto";
|
|
10
11
|
import { closeSync, constants, lstatSync, mkdirSync, openSync, rmSync, statSync, utimesSync } from "node:fs";
|
|
11
12
|
import { join } from "node:path";
|
|
12
13
|
import { readBoundedUtf8File } from "./boundedFile.js";
|
|
13
14
|
import { readBoundedJson } from "./boundedResponse.js";
|
|
15
|
+
import { CLI_SIGNING_KEYS } from "./cliSigningKeys.js";
|
|
14
16
|
import { credentialDir, enforceOwner, ensurePrivateDirectory, writePrivateAtomic } from "./credentialStorage.js";
|
|
15
17
|
import { assertProfileName, getProfile } from "./credentials.js";
|
|
16
18
|
import { disarmFastPath } from "./fastPathFlag.js";
|
|
@@ -21,10 +23,80 @@ export const CP_CLI_STALE_MS = 60 * 60 * 1000;
|
|
|
21
23
|
/** The hooks try at most this often, so an offline laptop pays nothing. */
|
|
22
24
|
export const CP_CLI_RETRY_MS = 10 * 60 * 1000;
|
|
23
25
|
const CACHE_DIRECTORY = "cp-cli";
|
|
24
|
-
|
|
26
|
+
/** Room for every platform's Block-covered action keys (`blocks`). */
|
|
27
|
+
const MAX_BYTES = 64 * 1024;
|
|
28
|
+
const MAX_BLOCKED = 512;
|
|
29
|
+
const ACTION_KEY = /^[a-z][a-z0-9_.:-]{0,119}$/;
|
|
25
30
|
const MAX_VENDORS = 64;
|
|
26
31
|
const VENDOR = /^[a-z0-9][a-z0-9_-]{0,31}$/;
|
|
27
32
|
const PLATFORMS = ["github", "railway", "supabase"];
|
|
33
|
+
/** The exact bytes `blocks` are signed over: a checked copy of shared/cpCli.ts `blocksSigningInput`. */
|
|
34
|
+
export function blocksSigningInput(ws, at, blocks) {
|
|
35
|
+
const platforms = Object.keys(blocks).sort();
|
|
36
|
+
return JSON.stringify([
|
|
37
|
+
"passport-cli-blocks/v1",
|
|
38
|
+
ws,
|
|
39
|
+
at,
|
|
40
|
+
platforms.map((key) => [key, [...(blocks[key] ?? [])].sort()])
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
/** Whether Passport signed these `blocks` with a key this CLI ships. Never throws. */
|
|
44
|
+
export function signedByPassport(blocks, signed, keys = CLI_SIGNING_KEYS) {
|
|
45
|
+
const spki = keys[signed.kid];
|
|
46
|
+
if (!spki)
|
|
47
|
+
return false;
|
|
48
|
+
try {
|
|
49
|
+
const key = createPublicKey({ key: Buffer.from(spki, "base64"), format: "der", type: "spki" });
|
|
50
|
+
const data = Buffer.from(blocksSigningInput(signed.ws, signed.at, blocks), "utf8");
|
|
51
|
+
return verify(null, data, key, Buffer.from(signed.sig, "base64url"));
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function seenPath(profile) {
|
|
58
|
+
assertProfileName(profile);
|
|
59
|
+
return join(directory(), `.${profile}.blocks-seen`);
|
|
60
|
+
}
|
|
61
|
+
/** The newest signed time of rules this computer has seen for a profile (0 when none). Never throws. */
|
|
62
|
+
export function seenBlocksAt(profile) {
|
|
63
|
+
try {
|
|
64
|
+
const path = seenPath(profile);
|
|
65
|
+
enforceOwner(lstatSync(path), "control-plane rules state");
|
|
66
|
+
const at = JSON.parse(readBoundedUtf8File(path, 256)).at;
|
|
67
|
+
return typeof at === "number" && Number.isFinite(at) && at > 0 ? at : 0;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Remember the newest signed rules seen, so a copy from before can't be swapped back in. Never throws. */
|
|
74
|
+
export function noteSeenBlocks(profile, at) {
|
|
75
|
+
try {
|
|
76
|
+
if (at <= seenBlocksAt(profile))
|
|
77
|
+
return;
|
|
78
|
+
ensureCacheDirectory();
|
|
79
|
+
writePrivateAtomic(seenPath(profile), ".blocks-seen", `${JSON.stringify({ at })}\n`, "control-plane rules state");
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// Best effort: the signature and the 7 days still apply.
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function parseSignature(value) {
|
|
86
|
+
const body = plainObject(value);
|
|
87
|
+
if (!body)
|
|
88
|
+
return undefined;
|
|
89
|
+
const { ws, at, kid, sig } = body;
|
|
90
|
+
if (typeof ws !== "string" || !/^[A-Za-z0-9_-]{1,64}$/.test(ws))
|
|
91
|
+
return undefined;
|
|
92
|
+
if (typeof at !== "number" || !Number.isFinite(at) || at < 0)
|
|
93
|
+
return undefined;
|
|
94
|
+
if (typeof kid !== "string" || !/^[0-9a-f]{16}$/.test(kid))
|
|
95
|
+
return undefined;
|
|
96
|
+
if (typeof sig !== "string" || !/^[A-Za-z0-9_-]{40,200}$/.test(sig))
|
|
97
|
+
return undefined;
|
|
98
|
+
return { ws, at, kid, sig };
|
|
99
|
+
}
|
|
28
100
|
function plainObject(value) {
|
|
29
101
|
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
30
102
|
}
|
|
@@ -44,6 +116,23 @@ export function parseCpCli(value) {
|
|
|
44
116
|
if (!out.vendors.includes(vendor))
|
|
45
117
|
out.vendors.push(vendor);
|
|
46
118
|
}
|
|
119
|
+
const blocks = plainObject(body.blocks);
|
|
120
|
+
if (blocks) {
|
|
121
|
+
out.blocks = {};
|
|
122
|
+
for (const platform of PLATFORMS) {
|
|
123
|
+
const keys = blocks[platform];
|
|
124
|
+
if (keys === undefined)
|
|
125
|
+
continue;
|
|
126
|
+
if (!Array.isArray(keys) || keys.length > MAX_BLOCKED)
|
|
127
|
+
return null;
|
|
128
|
+
if (!keys.every((key) => typeof key === "string" && ACTION_KEY.test(key)))
|
|
129
|
+
return null;
|
|
130
|
+
out.blocks[platform] = [...new Set(keys)];
|
|
131
|
+
}
|
|
132
|
+
const signature = parseSignature(body.blocksSignature);
|
|
133
|
+
if (signature)
|
|
134
|
+
out.blocksSignature = signature;
|
|
135
|
+
}
|
|
47
136
|
return out;
|
|
48
137
|
}
|
|
49
138
|
function directory() {
|
|
@@ -169,7 +258,19 @@ export async function refreshCpCli(profile, signal, deps = {}) {
|
|
|
169
258
|
saveLocalNotices(profile, parseNotices(plainObject(body)?.notices));
|
|
170
259
|
if (!cli || signal.aborted)
|
|
171
260
|
return "failed";
|
|
261
|
+
// The last good signed rules stay until a newer signed copy replaces them: a server that couldn't read its rules
|
|
262
|
+
// (or has no signing key) never overwrites them with nothing. Their own signed time still ages them out.
|
|
263
|
+
if (!cli.blocks || !cli.blocksSignature) {
|
|
264
|
+
const previous = readCpCli(profile);
|
|
265
|
+
if (previous?.blocks && previous.blocksSignature) {
|
|
266
|
+
cli.blocks = previous.blocks;
|
|
267
|
+
cli.blocksSignature = previous.blocksSignature;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
172
270
|
writeCpCli(profile, cli, (deps.now ?? Date.now)());
|
|
271
|
+
// A newer signed copy than any seen: an older one swapped back in later reads as missing.
|
|
272
|
+
if (cli.blocks && cli.blocksSignature && signedByPassport(cli.blocks, cli.blocksSignature))
|
|
273
|
+
noteSeenBlocks(profile, cli.blocksSignature.at);
|
|
173
274
|
return "updated";
|
|
174
275
|
}
|
|
175
276
|
catch {
|
package/dist/cpRefusal.d.ts
CHANGED
|
@@ -13,3 +13,11 @@ export declare function refusalOf(body: {
|
|
|
13
13
|
kind: "block";
|
|
14
14
|
message: string;
|
|
15
15
|
} | null;
|
|
16
|
+
/** Statuses that are no answer from Passport (signed out, gone, rate-limited): unreachable, never an allow
|
|
17
|
+
* (`docs/design/v22/visibility.md`, B4), with 5xx, timeouts and a 200 that isn't Passport's JSON. */
|
|
18
|
+
export declare const NO_ANSWER_STATUSES: ReadonlySet<number>;
|
|
19
|
+
/** A no-answer status's body: a refusal Passport wrote (a stopped agent's 403) blocks; anything else is no answer. */
|
|
20
|
+
export declare function noAnswer<T>(response: Response, unreachable: T): Promise<T | {
|
|
21
|
+
kind: "block";
|
|
22
|
+
message: string;
|
|
23
|
+
}>;
|
package/dist/cpRefusal.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readBoundedJson } from "./boundedResponse.js";
|
|
1
2
|
/**
|
|
2
3
|
* The control plane's refusal, read the same way by every guard client (GitHub, Railway, Supabase and vendor CLIs):
|
|
3
4
|
* any `allow: false` refuses, whatever its words: a block ("Blocked by Passport: …"), a stopped agent ("Stopped by
|
|
@@ -12,3 +13,15 @@ export function refusalOf(body) {
|
|
|
12
13
|
const message = typeof body.message === "string" && body.message.trim() ? body.message : REFUSED_WITHOUT_REASON;
|
|
13
14
|
return { kind: "block", message: message.slice(0, 400) };
|
|
14
15
|
}
|
|
16
|
+
/** Statuses that are no answer from Passport (signed out, gone, rate-limited): unreachable, never an allow
|
|
17
|
+
* (`docs/design/v22/visibility.md`, B4), with 5xx, timeouts and a 200 that isn't Passport's JSON. */
|
|
18
|
+
export const NO_ANSWER_STATUSES = new Set([401, 403, 404, 429]);
|
|
19
|
+
/** A no-answer status's body: a refusal Passport wrote (a stopped agent's 403) blocks; anything else is no answer. */
|
|
20
|
+
export async function noAnswer(response, unreachable) {
|
|
21
|
+
try {
|
|
22
|
+
return refusalOf(await readBoundedJson(response)) ?? unreachable;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return unreachable;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Runtime } from "./cliSupport.js";
|
|
2
|
+
import { type GitCredentialState, type RunGit } from "./gitCredentialSetup.js";
|
|
3
|
+
/** Set on the nested `git credential fill`, so a Passport entry that couldn't be removed never recurses. */
|
|
4
|
+
export declare const RETIRED_FILL_GUARD = "PASSPORT_GIT_CREDENTIAL_RETIRED";
|
|
5
|
+
export declare const RETIRED_NOTICE = "passport: git-credential is retired, so Passport took itself out of your global git config; git uses your own sign-in.";
|
|
6
|
+
export declare const RETIRE_FAILED_NOTICE = "passport: git-credential is retired, but your global git config couldn't be updated; git uses your own sign-in, and Passport tries again next time.";
|
|
7
|
+
/**
|
|
8
|
+
* Takes Passport's own entries out of the global git config and nothing else.
|
|
9
|
+
* In order, so a failure part-way is retried on the next call (Passport's
|
|
10
|
+
* helper, removed last, keeps bringing git back here):
|
|
11
|
+
* 1. what setup moved out of the section goes back (it lives only in the record);
|
|
12
|
+
* 2. the pushInsteadOf rewrites the record lists, each by its exact value;
|
|
13
|
+
* 3. useHttpPath, unless the record shows the section had it before;
|
|
14
|
+
* 4. the empty `helper =` reset: with a record, when the recorded helpers had no
|
|
15
|
+
* reset; without one, when every reset sits right before a Passport line (as
|
|
16
|
+
* setup writes them). This reset is what left git with no answer;
|
|
17
|
+
* 5. Passport's helper value(s) last.
|
|
18
|
+
* Each removal is one `--fixed-value --unset-all` of an exact value, so a
|
|
19
|
+
* concurrent writer is never undone. A failed write prints one line and stops;
|
|
20
|
+
* git is still answered through the fallback.
|
|
21
|
+
*/
|
|
22
|
+
export declare function retireGitCredential(runtime: Pick<Runtime, "env" | "stderr">, state: GitCredentialState | null, run?: RunGit): boolean;
|
|
23
|
+
/** The credential git's remaining helpers give for this request, never prompting: the lines git needs from
|
|
24
|
+
* a helper (username, password, expiry), or "" when none answers in time. */
|
|
25
|
+
export declare function fillFromOwnHelpers(input: string, env: Runtime["env"], cwd?: string, timeoutMs?: number): Promise<string>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `passport git-credential` is retired (off in v1: Passport issues no git
|
|
3
|
+
* tokens). A config left from an older setup still points git at it, and the
|
|
4
|
+
* empty `helper =` reset that setup added drops the helpers git had before, so
|
|
5
|
+
* git would get an empty answer and stop at a sign-in prompt. When git asks,
|
|
6
|
+
* the CLI unsets only its own values from the global config (one stderr line),
|
|
7
|
+
* then answers from the person's own helpers so this git command works too.
|
|
8
|
+
*/
|
|
9
|
+
import { spawn } from "node:child_process";
|
|
10
|
+
import { rmSync } from "node:fs";
|
|
11
|
+
import { PASSPORT_CREDENTIAL_KEY, defaultRunGit, isPassportHelper, statePath } from "./gitCredentialSetup.js";
|
|
12
|
+
const USE_HTTP_PATH_KEY = "credential.https://github.com/.useHttpPath";
|
|
13
|
+
/** Set on the nested `git credential fill`, so a Passport entry that couldn't be removed never recurses. */
|
|
14
|
+
export const RETIRED_FILL_GUARD = "PASSPORT_GIT_CREDENTIAL_RETIRED";
|
|
15
|
+
const MAX_ANSWER_BYTES = 64 * 1024;
|
|
16
|
+
const FILL_TIMEOUT_MS = 15_000;
|
|
17
|
+
export const RETIRED_NOTICE = "passport: git-credential is retired, so Passport took itself out of your global git config; git uses your own sign-in.";
|
|
18
|
+
export const RETIRE_FAILED_NOTICE = "passport: git-credential is retired, but your global git config couldn't be updated; git uses your own sign-in, and Passport tries again next time.";
|
|
19
|
+
function globalValues(run, env, key) {
|
|
20
|
+
const got = run(["config", "--global", "--get-all", key], env);
|
|
21
|
+
return got.ok ? got.stdout.replace(/\n$/, "").split("\n") : null;
|
|
22
|
+
}
|
|
23
|
+
/** The values setup's record says the section held for `key` before Passport wrote it. */
|
|
24
|
+
function recorded(state, key) {
|
|
25
|
+
const found = Object.entries(state.restore ?? {}).find(([existing]) => existing.toLowerCase() === key.toLowerCase());
|
|
26
|
+
return found?.[1] ?? [];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Takes Passport's own entries out of the global git config and nothing else.
|
|
30
|
+
* In order, so a failure part-way is retried on the next call (Passport's
|
|
31
|
+
* helper, removed last, keeps bringing git back here):
|
|
32
|
+
* 1. what setup moved out of the section goes back (it lives only in the record);
|
|
33
|
+
* 2. the pushInsteadOf rewrites the record lists, each by its exact value;
|
|
34
|
+
* 3. useHttpPath, unless the record shows the section had it before;
|
|
35
|
+
* 4. the empty `helper =` reset: with a record, when the recorded helpers had no
|
|
36
|
+
* reset; without one, when every reset sits right before a Passport line (as
|
|
37
|
+
* setup writes them). This reset is what left git with no answer;
|
|
38
|
+
* 5. Passport's helper value(s) last.
|
|
39
|
+
* Each removal is one `--fixed-value --unset-all` of an exact value, so a
|
|
40
|
+
* concurrent writer is never undone. A failed write prints one line and stops;
|
|
41
|
+
* git is still answered through the fallback.
|
|
42
|
+
*/
|
|
43
|
+
export function retireGitCredential(runtime, state, run = defaultRunGit) {
|
|
44
|
+
const env = runtime.env;
|
|
45
|
+
const helpers = globalValues(run, env, PASSPORT_CREDENTIAL_KEY) ?? [];
|
|
46
|
+
const ours = [...new Set(helpers.filter(isPassportHelper))];
|
|
47
|
+
if (!ours.length)
|
|
48
|
+
return false;
|
|
49
|
+
const unset = (key, value) => run(["config", "--global", "--fixed-value", "--unset-all", key, value], env).ok;
|
|
50
|
+
const failed = () => (runtime.stderr.write(`${RETIRE_FAILED_NOTICE}\n`), false);
|
|
51
|
+
for (const [key, values] of Object.entries(state?.restore ?? {})) {
|
|
52
|
+
const present = globalValues(run, env, key) ?? [];
|
|
53
|
+
for (const value of values) {
|
|
54
|
+
if (!present.includes(value) && !run(["config", "--global", "--add", key, value], env).ok)
|
|
55
|
+
return failed();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const { key, value } of state?.pushInsteadOf ?? []) {
|
|
59
|
+
if (globalValues(run, env, key)?.includes(value) && !unset(key, value))
|
|
60
|
+
return failed();
|
|
61
|
+
}
|
|
62
|
+
const pathOurs = state ? !recorded(state, USE_HTTP_PATH_KEY).includes("true") : true;
|
|
63
|
+
if (pathOurs && globalValues(run, env, USE_HTTP_PATH_KEY)?.includes("true") && !unset(USE_HTTP_PATH_KEY, "true")) {
|
|
64
|
+
return failed();
|
|
65
|
+
}
|
|
66
|
+
const resets = helpers.filter((value) => value === "").length;
|
|
67
|
+
const resetsBeforeOurs = helpers.filter((value, index) => value === "" && isPassportHelper(helpers[index + 1] ?? ""));
|
|
68
|
+
const resetOurs = state
|
|
69
|
+
? !recorded(state, PASSPORT_CREDENTIAL_KEY).includes("")
|
|
70
|
+
: resets > 0 && resetsBeforeOurs.length === resets;
|
|
71
|
+
if (resetOurs && resets > 0 && !unset(PASSPORT_CREDENTIAL_KEY, ""))
|
|
72
|
+
return failed();
|
|
73
|
+
if (!ours.every((value) => unset(PASSPORT_CREDENTIAL_KEY, value)))
|
|
74
|
+
return failed();
|
|
75
|
+
try {
|
|
76
|
+
rmSync(statePath(), { force: true });
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
/* the record only matters to setup */
|
|
80
|
+
}
|
|
81
|
+
runtime.stderr.write(`${RETIRED_NOTICE}\n`);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
/** The credential git's remaining helpers give for this request, never prompting: the lines git needs from
|
|
85
|
+
* a helper (username, password, expiry), or "" when none answers in time. */
|
|
86
|
+
export function fillFromOwnHelpers(input, env, cwd = process.cwd(), timeoutMs = FILL_TIMEOUT_MS) {
|
|
87
|
+
const vars = env;
|
|
88
|
+
// git always hands a helper its HOME; without one, git would read the OS account's real config instead.
|
|
89
|
+
if (vars[RETIRED_FILL_GUARD] || !vars.HOME)
|
|
90
|
+
return Promise.resolve("");
|
|
91
|
+
const request = input
|
|
92
|
+
.split("\n")
|
|
93
|
+
.filter((line) => /^(?:protocol|host|username|path)=/.test(line))
|
|
94
|
+
.join("\n");
|
|
95
|
+
if (!/^host=/m.test(request))
|
|
96
|
+
return Promise.resolve("");
|
|
97
|
+
return new Promise((resolve) => {
|
|
98
|
+
const run = { settled: false };
|
|
99
|
+
const finish = (answer) => {
|
|
100
|
+
if (run.settled)
|
|
101
|
+
return;
|
|
102
|
+
run.settled = true;
|
|
103
|
+
clearTimeout(run.timer);
|
|
104
|
+
resolve(answer);
|
|
105
|
+
};
|
|
106
|
+
const child = spawn("git", ["-c", "credential.interactive=false", "credential", "fill"], {
|
|
107
|
+
cwd,
|
|
108
|
+
detached: true,
|
|
109
|
+
env: {
|
|
110
|
+
...env,
|
|
111
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
112
|
+
GIT_ASKPASS: "",
|
|
113
|
+
SSH_ASKPASS: "",
|
|
114
|
+
GCM_INTERACTIVE: "never",
|
|
115
|
+
[RETIRED_FILL_GUARD]: "1"
|
|
116
|
+
},
|
|
117
|
+
stdio: ["pipe", "pipe", "ignore"]
|
|
118
|
+
});
|
|
119
|
+
// A helper's own child can hold stdout open: the timer answers git anyway and ends the whole group.
|
|
120
|
+
run.timer = setTimeout(() => {
|
|
121
|
+
try {
|
|
122
|
+
if (child.pid)
|
|
123
|
+
process.kill(-child.pid, "SIGKILL");
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
/* already gone */
|
|
127
|
+
}
|
|
128
|
+
finish("");
|
|
129
|
+
}, timeoutMs);
|
|
130
|
+
let out = "";
|
|
131
|
+
child.stdout.on("data", (chunk) => {
|
|
132
|
+
if (out.length < MAX_ANSWER_BYTES)
|
|
133
|
+
out += chunk.toString("utf8");
|
|
134
|
+
});
|
|
135
|
+
child.on("error", () => finish(""));
|
|
136
|
+
child.on("close", (code) => {
|
|
137
|
+
const lines = out.split("\n").filter((line) => /^(?:username|password|password_expiry_utc)=/.test(line));
|
|
138
|
+
finish(code === 0 && lines.some((line) => line.startsWith("password=")) ? `${lines.join("\n")}\n` : "");
|
|
139
|
+
});
|
|
140
|
+
child.stdin.on("error", () => undefined);
|
|
141
|
+
child.stdin.end(`${request}\n\n`);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One adapter per hook payload dialect (`docs/design/v22/visibility.md`, B1). Each agent sends its own shape, and a
|
|
3
|
+
* hook that reads the wrong shape silently fails open, so every shape is parsed on purpose and anything else is
|
|
4
|
+
* unparseable, which the guard refuses (exit 2), never allows:
|
|
5
|
+
*
|
|
6
|
+
* - Claude-style (Claude Code; Codex adds `turn_id` and may send the command as argv): `hook_event_name`
|
|
7
|
+
* `PreToolUse` | `PostToolUse` | `PostToolUseFailure`, `tool_name`, `tool_input.command`, `tool_use_id`.
|
|
8
|
+
* - Cursor's own shell events: `beforeShellExecution` | `afterShellExecution` with a flat `command`.
|
|
9
|
+
* - Cursor running a hook it imported from Claude Code settings: Claude-style with `cursor_version`, or Cursor's
|
|
10
|
+
* camel-case `preToolUse` | `postToolUse`.
|
|
11
|
+
*
|
|
12
|
+
* Session events (start, end, a prompt), and event names this version doesn't know, are parseable and not shell
|
|
13
|
+
* commands; an unknown name that reads as a pre-tool event is unparseable. Pure.
|
|
14
|
+
*/
|
|
15
|
+
import { type HookInput } from "./cliHookInput.js";
|
|
16
|
+
import type { GuardClient } from "./cliHookGuard.js";
|
|
17
|
+
/** One shell command, whichever agent format it arrived in. */
|
|
18
|
+
export type ShellEvent = {
|
|
19
|
+
phase: "pre" | "post";
|
|
20
|
+
command: string;
|
|
21
|
+
/** Cursor's own beforeShellExecution / afterShellExecution. */
|
|
22
|
+
cursorNative: boolean;
|
|
23
|
+
/** Cursor running a hook it imported from Claude Code settings. */
|
|
24
|
+
cursorImported: boolean;
|
|
25
|
+
};
|
|
26
|
+
export type Unparseable = "empty" | "not-json" | "not-object" | "no-event" | "no-tool" | "no-command" | "unknown-event";
|
|
27
|
+
export type Parsed =
|
|
28
|
+
/** `event` null: parseable, not a shell command (another tool, a session event). */
|
|
29
|
+
{
|
|
30
|
+
ok: true;
|
|
31
|
+
input: HookInput;
|
|
32
|
+
event: ShellEvent | null;
|
|
33
|
+
} | {
|
|
34
|
+
ok: false;
|
|
35
|
+
why: Unparseable;
|
|
36
|
+
};
|
|
37
|
+
/** The agent's label in Passport's own words, for a refusal. */
|
|
38
|
+
export declare const AGENT_LABEL: Readonly<Record<GuardClient, string>>;
|
|
39
|
+
/** Normalise one parsed payload into its shell command and when it runs; null for anything that isn't one. */
|
|
40
|
+
export declare function shellEvent(input: HookInput): ShellEvent | null;
|
|
41
|
+
/** Parse what the agent sent on stdin. `raw` null: nothing arrived in the budget (or more than the hook reads). */
|
|
42
|
+
export declare function parsePayload(raw: string | null): Parsed;
|
|
43
|
+
/** What the agent reads when the guard can't read its payload: the command didn't run. */
|
|
44
|
+
export declare function unreadableMessage(client: GuardClient | undefined): string;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One adapter per hook payload dialect (`docs/design/v22/visibility.md`, B1). Each agent sends its own shape, and a
|
|
3
|
+
* hook that reads the wrong shape silently fails open, so every shape is parsed on purpose and anything else is
|
|
4
|
+
* unparseable, which the guard refuses (exit 2), never allows:
|
|
5
|
+
*
|
|
6
|
+
* - Claude-style (Claude Code; Codex adds `turn_id` and may send the command as argv): `hook_event_name`
|
|
7
|
+
* `PreToolUse` | `PostToolUse` | `PostToolUseFailure`, `tool_name`, `tool_input.command`, `tool_use_id`.
|
|
8
|
+
* - Cursor's own shell events: `beforeShellExecution` | `afterShellExecution` with a flat `command`.
|
|
9
|
+
* - Cursor running a hook it imported from Claude Code settings: Claude-style with `cursor_version`, or Cursor's
|
|
10
|
+
* camel-case `preToolUse` | `postToolUse`.
|
|
11
|
+
*
|
|
12
|
+
* Session events (start, end, a prompt), and event names this version doesn't know, are parseable and not shell
|
|
13
|
+
* commands; an unknown name that reads as a pre-tool event is unparseable. Pure.
|
|
14
|
+
*/
|
|
15
|
+
import { commandText, record } from "./cliHookInput.js";
|
|
16
|
+
const SHELL_TOOLS = new Set(["Bash", "bash", "shell", "Shell"]);
|
|
17
|
+
const CURSOR_NATIVE = {
|
|
18
|
+
beforeShellExecution: "pre",
|
|
19
|
+
afterShellExecution: "post"
|
|
20
|
+
};
|
|
21
|
+
const CLAUDE_STYLE = {
|
|
22
|
+
PreToolUse: "pre",
|
|
23
|
+
PostToolUse: "post",
|
|
24
|
+
PostToolUseFailure: "post",
|
|
25
|
+
// Cursor's own names for the same events, which its imported hooks may receive.
|
|
26
|
+
preToolUse: "pre",
|
|
27
|
+
postToolUse: "post"
|
|
28
|
+
};
|
|
29
|
+
const SESSION_EVENTS = new Set([
|
|
30
|
+
"SessionStart",
|
|
31
|
+
"SessionEnd",
|
|
32
|
+
"UserPromptSubmit",
|
|
33
|
+
"Stop",
|
|
34
|
+
"SubagentStop",
|
|
35
|
+
"Notification",
|
|
36
|
+
"PreCompact",
|
|
37
|
+
"sessionStart",
|
|
38
|
+
"sessionEnd",
|
|
39
|
+
"beforeSubmitPrompt",
|
|
40
|
+
"stop"
|
|
41
|
+
]);
|
|
42
|
+
/** A name that reads as a pre-tool event ("PreToolCall", "beforeMCPExecution", "pre_tool_use"). */
|
|
43
|
+
const PRE_TOOL_NAME = /^(?:pre[\s_-]?tool|before)/i;
|
|
44
|
+
/** The agent's label in Passport's own words, for a refusal. */
|
|
45
|
+
export const AGENT_LABEL = {
|
|
46
|
+
"claude-code": "Claude Code",
|
|
47
|
+
codex: "Codex",
|
|
48
|
+
cursor: "Cursor"
|
|
49
|
+
};
|
|
50
|
+
/** Normalise one parsed payload into its shell command and when it runs; null for anything that isn't one. */
|
|
51
|
+
export function shellEvent(input) {
|
|
52
|
+
const name = typeof input.hook_event_name === "string" ? input.hook_event_name : "";
|
|
53
|
+
const native = CURSOR_NATIVE[name];
|
|
54
|
+
if (native) {
|
|
55
|
+
if (typeof input.command !== "string")
|
|
56
|
+
return null;
|
|
57
|
+
return { phase: native, command: input.command, cursorNative: true, cursorImported: false };
|
|
58
|
+
}
|
|
59
|
+
const phase = CLAUDE_STYLE[name];
|
|
60
|
+
if (!phase || typeof input.tool_name !== "string" || !SHELL_TOOLS.has(input.tool_name))
|
|
61
|
+
return null;
|
|
62
|
+
const command = commandText(record(input.tool_input).command);
|
|
63
|
+
if (command === null)
|
|
64
|
+
return null;
|
|
65
|
+
const imported = typeof input.cursor_version === "string" || name === "preToolUse" || name === "postToolUse";
|
|
66
|
+
return { phase, command, cursorNative: false, cursorImported: imported };
|
|
67
|
+
}
|
|
68
|
+
/** Parse what the agent sent on stdin. `raw` null: nothing arrived in the budget (or more than the hook reads). */
|
|
69
|
+
export function parsePayload(raw) {
|
|
70
|
+
if (raw === null || !raw.trim())
|
|
71
|
+
return { ok: false, why: "empty" };
|
|
72
|
+
let parsed;
|
|
73
|
+
try {
|
|
74
|
+
parsed = JSON.parse(raw);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return { ok: false, why: "not-json" };
|
|
78
|
+
}
|
|
79
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
80
|
+
return { ok: false, why: "not-object" };
|
|
81
|
+
const input = parsed;
|
|
82
|
+
const name = input.hook_event_name;
|
|
83
|
+
if (typeof name !== "string" || !name)
|
|
84
|
+
return { ok: false, why: "no-event" };
|
|
85
|
+
if (CURSOR_NATIVE[name]) {
|
|
86
|
+
return typeof input.command === "string"
|
|
87
|
+
? { ok: true, input, event: shellEvent(input) }
|
|
88
|
+
: { ok: false, why: "no-command" };
|
|
89
|
+
}
|
|
90
|
+
if (CLAUDE_STYLE[name]) {
|
|
91
|
+
if (typeof input.tool_name !== "string" || !input.tool_name)
|
|
92
|
+
return { ok: false, why: "no-tool" };
|
|
93
|
+
if (!SHELL_TOOLS.has(input.tool_name))
|
|
94
|
+
return { ok: true, input, event: null };
|
|
95
|
+
const event = shellEvent(input);
|
|
96
|
+
return event ? { ok: true, input, event } : { ok: false, why: "no-command" };
|
|
97
|
+
}
|
|
98
|
+
if (SESSION_EVENTS.has(name))
|
|
99
|
+
return { ok: true, input, event: null };
|
|
100
|
+
// An event this version doesn't know is ignored, unless it reads as a pre-tool event the guard should have parsed.
|
|
101
|
+
return PRE_TOOL_NAME.test(name) ? { ok: false, why: "unknown-event" } : { ok: true, input, event: null };
|
|
102
|
+
}
|
|
103
|
+
/** What the agent reads when the guard can't read its payload: the command didn't run. */
|
|
104
|
+
export function unreadableMessage(client) {
|
|
105
|
+
return `Passport couldn't read this command from ${client ? AGENT_LABEL[client] : "the agent"}, so it didn't run.`;
|
|
106
|
+
}
|
package/dist/lockedHooks.d.ts
CHANGED
|
@@ -13,13 +13,14 @@
|
|
|
13
13
|
* Vendor references (verified 2026-10-09):
|
|
14
14
|
* - Claude Code: managed settings can hold `hooks`, which a person's
|
|
15
15
|
* `disableAllHooks` can't turn off; drop-ins go in `managed-settings.d/`;
|
|
16
|
-
*
|
|
16
|
+
* a hook's `onFailure: "block"` makes it fail closed (always, 2026-11-17);
|
|
17
|
+
* `allowManagedHooksOnly` (always set, 2026-11-18) turns every other hook off;
|
|
17
18
|
* with claude.ai server-managed settings too, `managedSourcesBehavior: "merge"`
|
|
18
19
|
* applies both. code.claude.com/docs/en/settings, code.claude.com/docs/en/hooks
|
|
19
20
|
* - Codex: hooks in requirements.toml are trusted by policy and must run from
|
|
20
|
-
* `managed_dir`; `allow_managed_hooks_only`
|
|
21
|
+
* `managed_dir`; `allow_managed_hooks_only` (always set, 2026-11-18) turns every other hook off.
|
|
21
22
|
* learn.chatgpt.com/docs/enterprise/managed-configuration
|
|
22
|
-
* - Cursor: a system hooks.json; `failClosed` blocks when the hook can't run.
|
|
23
|
+
* - Cursor: a system hooks.json; `failClosed` (always set, 2026-11-17) blocks when the hook can't run.
|
|
23
24
|
* A team marketplace plugin set to Required can't be removed.
|
|
24
25
|
* cursor.com/docs/agent/hooks, cursor.com/docs/plugins
|
|
25
26
|
*/
|
|
@@ -29,9 +30,9 @@ export declare const LOCK_AGENTS: readonly LockAgent[];
|
|
|
29
30
|
/** Words shared by the web and the CLI. */
|
|
30
31
|
export declare const LOCK_COPY: {
|
|
31
32
|
readonly label: "Lock it";
|
|
32
|
-
readonly hint: "Managed settings keep the guard on; people can't turn it off.";
|
|
33
|
+
readonly hint: "Managed settings keep the guard on and turn other hooks off; people can't turn it off.";
|
|
33
34
|
readonly strictLabel: "Strict";
|
|
34
|
-
readonly strictHint: "
|
|
35
|
+
readonly strictHint: "A person without the guard set up can't run commands.";
|
|
35
36
|
readonly claudeMergeNote: "Also using claude.ai server-managed settings? Add \"managedSourcesBehavior\": \"merge\" so both apply.";
|
|
36
37
|
readonly locked: "Locked";
|
|
37
38
|
readonly needsAdmin: "Locking needs administrator rights. Run it with sudo, or deploy these through MDM:";
|
|
@@ -59,23 +60,23 @@ type ClaudeHook = {
|
|
|
59
60
|
onFailure?: "block";
|
|
60
61
|
};
|
|
61
62
|
export type ClaudeLockedSettings = {
|
|
62
|
-
allowManagedHooksOnly
|
|
63
|
+
allowManagedHooksOnly: true;
|
|
63
64
|
hooks: Record<"PreToolUse" | "PostToolUse" | "PostToolUseFailure", {
|
|
64
65
|
matcher: "Bash";
|
|
65
66
|
hooks: ClaudeHook[];
|
|
66
67
|
}[]>;
|
|
67
68
|
};
|
|
68
69
|
/** The keys Passport adds to Claude Code's managed settings. */
|
|
69
|
-
export declare function claudeLockedSettings({ platform
|
|
70
|
+
export declare function claudeLockedSettings({ platform }: {
|
|
70
71
|
platform: LockPlatform;
|
|
71
72
|
strict: boolean;
|
|
72
73
|
}): ClaudeLockedSettings;
|
|
73
|
-
/**
|
|
74
|
+
/** The managed-only line (every lock, 2026-11-18); TOML wants it before any table. */
|
|
74
75
|
export declare const CODEX_STRICT_LINE = "allow_managed_hooks_only = true";
|
|
75
76
|
/** Codex's `[hooks]` tables: the shim's folder and the two hooks run from it. */
|
|
76
77
|
export declare function codexHooksTables(platform?: "darwin" | "linux"): string[];
|
|
77
78
|
/** Passport's lines for Codex's requirements.toml. */
|
|
78
|
-
export declare function codexLockedRequirements({
|
|
79
|
+
export declare function codexLockedRequirements({ platform }: {
|
|
79
80
|
strict: boolean;
|
|
80
81
|
platform?: "darwin" | "linux";
|
|
81
82
|
}): string;
|
|
@@ -91,8 +92,9 @@ export type CursorSystemHooks = {
|
|
|
91
92
|
afterShellExecution: CursorHook[];
|
|
92
93
|
};
|
|
93
94
|
};
|
|
94
|
-
/** Cursor's system hooks.json with Passport's two entries
|
|
95
|
-
|
|
95
|
+
/** Cursor's system hooks.json with Passport's two entries; the guard fails closed, strict or not (Cursor has no
|
|
96
|
+
* managed-only switch, so `strict` changes nothing here). */
|
|
97
|
+
export declare function cursorSystemHooks({ platform }: {
|
|
96
98
|
platform: LockPlatform;
|
|
97
99
|
strict: boolean;
|
|
98
100
|
}): CursorSystemHooks;
|
package/dist/lockedHooks.js
CHANGED
|
@@ -13,13 +13,14 @@
|
|
|
13
13
|
* Vendor references (verified 2026-10-09):
|
|
14
14
|
* - Claude Code: managed settings can hold `hooks`, which a person's
|
|
15
15
|
* `disableAllHooks` can't turn off; drop-ins go in `managed-settings.d/`;
|
|
16
|
-
*
|
|
16
|
+
* a hook's `onFailure: "block"` makes it fail closed (always, 2026-11-17);
|
|
17
|
+
* `allowManagedHooksOnly` (always set, 2026-11-18) turns every other hook off;
|
|
17
18
|
* with claude.ai server-managed settings too, `managedSourcesBehavior: "merge"`
|
|
18
19
|
* applies both. code.claude.com/docs/en/settings, code.claude.com/docs/en/hooks
|
|
19
20
|
* - Codex: hooks in requirements.toml are trusted by policy and must run from
|
|
20
|
-
* `managed_dir`; `allow_managed_hooks_only`
|
|
21
|
+
* `managed_dir`; `allow_managed_hooks_only` (always set, 2026-11-18) turns every other hook off.
|
|
21
22
|
* learn.chatgpt.com/docs/enterprise/managed-configuration
|
|
22
|
-
* - Cursor: a system hooks.json; `failClosed` blocks when the hook can't run.
|
|
23
|
+
* - Cursor: a system hooks.json; `failClosed` (always set, 2026-11-17) blocks when the hook can't run.
|
|
23
24
|
* A team marketplace plugin set to Required can't be removed.
|
|
24
25
|
* cursor.com/docs/agent/hooks, cursor.com/docs/plugins
|
|
25
26
|
*/
|
|
@@ -27,9 +28,9 @@ export const LOCK_AGENTS = ["claude-code", "codex", "cursor"];
|
|
|
27
28
|
/** Words shared by the web and the CLI. */
|
|
28
29
|
export const LOCK_COPY = {
|
|
29
30
|
label: "Lock it",
|
|
30
|
-
hint: "Managed settings keep the guard on; people can't turn it off.",
|
|
31
|
+
hint: "Managed settings keep the guard on and turn other hooks off; people can't turn it off.",
|
|
31
32
|
strictLabel: "Strict",
|
|
32
|
-
strictHint: "
|
|
33
|
+
strictHint: "A person without the guard set up can't run commands.",
|
|
33
34
|
claudeMergeNote: 'Also using claude.ai server-managed settings? Add "managedSourcesBehavior": "merge" so both apply.',
|
|
34
35
|
locked: "Locked",
|
|
35
36
|
needsAdmin: "Locking needs administrator rights. Run it with sudo, or deploy these through MDM:",
|
|
@@ -112,15 +113,16 @@ export function shimScriptWindows(strict) {
|
|
|
112
113
|
].join("\r\n");
|
|
113
114
|
}
|
|
114
115
|
/** The keys Passport adds to Claude Code's managed settings. */
|
|
115
|
-
export function claudeLockedSettings({ platform
|
|
116
|
+
export function claudeLockedSettings({ platform }) {
|
|
116
117
|
const hook = (guard) => ({
|
|
117
118
|
type: "command",
|
|
118
119
|
command: shimCommand(platform, "claude-code", guard),
|
|
119
120
|
timeout: 5,
|
|
120
|
-
...(guard
|
|
121
|
+
...(guard ? { onFailure: "block" } : {})
|
|
121
122
|
});
|
|
122
123
|
return {
|
|
123
|
-
|
|
124
|
+
// Locked means only managed hooks run (2026-11-18); `strict` changes only the launcher (`shimScript`).
|
|
125
|
+
allowManagedHooksOnly: true,
|
|
124
126
|
hooks: {
|
|
125
127
|
PreToolUse: [{ matcher: "Bash", hooks: [hook(true)] }],
|
|
126
128
|
PostToolUse: [{ matcher: "Bash", hooks: [hook(false)] }],
|
|
@@ -128,7 +130,7 @@ export function claudeLockedSettings({ platform, strict }) {
|
|
|
128
130
|
}
|
|
129
131
|
};
|
|
130
132
|
}
|
|
131
|
-
/**
|
|
133
|
+
/** The managed-only line (every lock, 2026-11-18); TOML wants it before any table. */
|
|
132
134
|
export const CODEX_STRICT_LINE = "allow_managed_hooks_only = true";
|
|
133
135
|
function codexHook(event, platform, guard) {
|
|
134
136
|
return [
|
|
@@ -154,9 +156,11 @@ export function codexHooksTables(platform = "darwin") {
|
|
|
154
156
|
];
|
|
155
157
|
}
|
|
156
158
|
/** Passport's lines for Codex's requirements.toml. */
|
|
157
|
-
export function codexLockedRequirements({
|
|
159
|
+
export function codexLockedRequirements({ platform = "darwin" }) {
|
|
158
160
|
return [
|
|
159
|
-
|
|
161
|
+
// Locked means only managed hooks run (2026-11-18).
|
|
162
|
+
CODEX_STRICT_LINE,
|
|
163
|
+
"",
|
|
160
164
|
"[features]",
|
|
161
165
|
"hooks = true",
|
|
162
166
|
"",
|
|
@@ -164,14 +168,13 @@ export function codexLockedRequirements({ strict, platform = "darwin" }) {
|
|
|
164
168
|
""
|
|
165
169
|
].join("\n");
|
|
166
170
|
}
|
|
167
|
-
/** Cursor's system hooks.json with Passport's two entries
|
|
168
|
-
|
|
171
|
+
/** Cursor's system hooks.json with Passport's two entries; the guard fails closed, strict or not (Cursor has no
|
|
172
|
+
* managed-only switch, so `strict` changes nothing here). */
|
|
173
|
+
export function cursorSystemHooks({ platform }) {
|
|
169
174
|
return {
|
|
170
175
|
version: 1,
|
|
171
176
|
hooks: {
|
|
172
|
-
beforeShellExecution: [
|
|
173
|
-
{ command: shimCommand(platform, "cursor", true), timeout: 5, ...(strict ? { failClosed: true } : {}) }
|
|
174
|
-
],
|
|
177
|
+
beforeShellExecution: [{ command: shimCommand(platform, "cursor", true), timeout: 5, failClosed: true }],
|
|
175
178
|
afterShellExecution: [{ command: shimCommand(platform, "cursor", false), timeout: 5 }]
|
|
176
179
|
}
|
|
177
180
|
};
|