passport-bridge 0.7.0 → 0.7.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/README.md +80 -48
- package/dist/boundedFile.js +46 -0
- package/dist/boundedMcpFetch.js +98 -0
- package/dist/boundedResponse.js +56 -0
- package/dist/bridge.js +426 -99
- package/dist/bridgeConfig.js +19 -0
- package/dist/bridgeShutdown.js +30 -0
- package/dist/cli.js +193 -37
- package/dist/cliArgs.js +2 -0
- package/dist/cliClient.js +24 -46
- package/dist/cliDeadline.js +27 -0
- package/dist/cliLogin.js +103 -0
- package/dist/cliOffline.js +53 -0
- package/dist/cliOutput.js +106 -0
- package/dist/cliPagination.js +55 -0
- package/dist/cliResult.js +87 -0
- package/dist/cliSession.js +163 -0
- package/dist/cliSupport.js +191 -0
- package/dist/completion.js +22 -9
- package/dist/credentials.js +584 -83
- package/dist/discover.js +60 -34
- package/dist/doctor.js +56 -13
- package/dist/legacyCliSecurity.js +26 -0
- package/dist/passport.js +87 -469
- package/dist/privateStableFile.js +170 -0
- package/dist/recoveryCleanup.js +17 -0
- package/dist/recoveryIdentity.js +80 -0
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +1740 -0
- package/package.json +21 -7
- package/dist/discover.test.js +0 -51
package/dist/discover.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import { existsSync
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
3
|
import { homedir, hostname, platform } from "node:os";
|
|
4
|
-
import {
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { readOrCreatePrivateStableFile } from "./privateStableFile.js";
|
|
6
|
+
import { readBoundedUtf8File } from "./boundedFile.js";
|
|
5
7
|
/**
|
|
6
8
|
* A managed scanner is the enforcement boundary Passport can verify today.
|
|
7
9
|
* `require_passport` fails every active direct connection unless an admin has
|
|
@@ -15,10 +17,10 @@ export function evaluateDiscoveryCompliance(report) {
|
|
|
15
17
|
const denied = active.filter((asset) => asset.decision?.state === "denied").length;
|
|
16
18
|
const enforcement = String(report.policy?.enforcement ?? "observe");
|
|
17
19
|
const noncompliant = report.policy?.fleetMode === "managed" &&
|
|
18
|
-
((enforcement === "require_passport" && routeRequired > 0) ||
|
|
19
|
-
(enforcement === "block" && denied > 0));
|
|
20
|
+
((enforcement === "require_passport" && routeRequired > 0) || (enforcement === "block" && denied > 0));
|
|
20
21
|
return { compliant: !noncompliant, routeRequired, denied };
|
|
21
22
|
}
|
|
23
|
+
const LOCAL_MCP_CONFIG_MAX_BYTES = 2 * 1024 * 1024;
|
|
22
24
|
function appConfigRoot(env) {
|
|
23
25
|
if (platform() === "darwin")
|
|
24
26
|
return join(homedir(), "Library", "Application Support");
|
|
@@ -36,7 +38,10 @@ function jsonSpecs(env) {
|
|
|
36
38
|
];
|
|
37
39
|
}
|
|
38
40
|
function safeName(raw) {
|
|
39
|
-
const value = raw
|
|
41
|
+
const value = raw
|
|
42
|
+
.replace(/[\u0000-\u001f\u007f]/g, "")
|
|
43
|
+
.trim()
|
|
44
|
+
.slice(0, 80);
|
|
40
45
|
if (!value ||
|
|
41
46
|
value.startsWith("/") ||
|
|
42
47
|
value.includes("\\") ||
|
|
@@ -49,7 +54,20 @@ function safeName(raw) {
|
|
|
49
54
|
}
|
|
50
55
|
function executableClass(command) {
|
|
51
56
|
const leaf = command.trim().split(/[\\/]/).pop()?.split(/\s+/)[0]?.toLowerCase() ?? "";
|
|
52
|
-
const allow = new Set([
|
|
57
|
+
const allow = new Set([
|
|
58
|
+
"npx",
|
|
59
|
+
"npm",
|
|
60
|
+
"node",
|
|
61
|
+
"uvx",
|
|
62
|
+
"uv",
|
|
63
|
+
"python",
|
|
64
|
+
"python3",
|
|
65
|
+
"docker",
|
|
66
|
+
"deno",
|
|
67
|
+
"bun",
|
|
68
|
+
"passport",
|
|
69
|
+
"passport-bridge"
|
|
70
|
+
]);
|
|
53
71
|
return allow.has(leaf) ? leaf : "executable hidden";
|
|
54
72
|
}
|
|
55
73
|
export function inspectDiscoveryEntry(client, rawName, raw, passportOrigin) {
|
|
@@ -91,7 +109,9 @@ export function inspectDiscoveryEntry(client, rawName, raw, passportOrigin) {
|
|
|
91
109
|
}
|
|
92
110
|
if (command) {
|
|
93
111
|
const commandClass = executableClass(command);
|
|
94
|
-
const args = Array.isArray(entry.args)
|
|
112
|
+
const args = Array.isArray(entry.args)
|
|
113
|
+
? entry.args.filter((value) => typeof value === "string")
|
|
114
|
+
: [];
|
|
95
115
|
const governed = commandClass === "passport" ||
|
|
96
116
|
commandClass === "passport-bridge" ||
|
|
97
117
|
args.some((value) => /(?:^|[\\/])passport-bridge(?:\.exe)?$/i.test(value));
|
|
@@ -119,7 +139,7 @@ function readJsonSource(spec, passportOrigin) {
|
|
|
119
139
|
if (!existsSync(spec.path))
|
|
120
140
|
return { client: spec.client, status: "missing", servers: [] };
|
|
121
141
|
try {
|
|
122
|
-
const parsed = JSON.parse(
|
|
142
|
+
const parsed = JSON.parse(readBoundedUtf8File(spec.path, LOCAL_MCP_CONFIG_MAX_BYTES));
|
|
123
143
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
124
144
|
return { client: spec.client, status: "invalid", servers: [] };
|
|
125
145
|
}
|
|
@@ -141,15 +161,18 @@ function readJsonSource(spec, passportOrigin) {
|
|
|
141
161
|
const code = error.code;
|
|
142
162
|
return {
|
|
143
163
|
client: spec.client,
|
|
144
|
-
status: code === "EACCES" || code === "EPERM"
|
|
164
|
+
status: code === "EACCES" || code === "EPERM"
|
|
165
|
+
? "permission_denied"
|
|
166
|
+
: error instanceof SyntaxError
|
|
167
|
+
? "invalid"
|
|
168
|
+
: "unreadable",
|
|
145
169
|
servers: []
|
|
146
170
|
};
|
|
147
171
|
}
|
|
148
172
|
}
|
|
149
173
|
function unquoteToml(value) {
|
|
150
174
|
const trimmed = value.trim();
|
|
151
|
-
if ((trimmed.startsWith('"') && trimmed.endsWith('"')) ||
|
|
152
|
-
(trimmed.startsWith("'") && trimmed.endsWith("'"))) {
|
|
175
|
+
if ((trimmed.startsWith('"') && trimmed.endsWith('"')) || (trimmed.startsWith("'") && trimmed.endsWith("'"))) {
|
|
153
176
|
return trimmed.slice(1, -1);
|
|
154
177
|
}
|
|
155
178
|
return trimmed;
|
|
@@ -159,7 +182,7 @@ function readCodex(passportOrigin) {
|
|
|
159
182
|
if (!existsSync(path))
|
|
160
183
|
return { client: "codex", status: "missing", servers: [] };
|
|
161
184
|
try {
|
|
162
|
-
const text =
|
|
185
|
+
const text = readBoundedUtf8File(path, LOCAL_MCP_CONFIG_MAX_BYTES);
|
|
163
186
|
const entries = new Map();
|
|
164
187
|
let current = "";
|
|
165
188
|
for (const line of text.split(/\r?\n/)) {
|
|
@@ -180,7 +203,9 @@ function readCodex(passportOrigin) {
|
|
|
180
203
|
return {
|
|
181
204
|
client: "codex",
|
|
182
205
|
status: "ready",
|
|
183
|
-
servers: [...entries.entries()]
|
|
206
|
+
servers: [...entries.entries()]
|
|
207
|
+
.slice(0, 100)
|
|
208
|
+
.map(([name, entry]) => inspectDiscoveryEntry("codex", name, entry, passportOrigin))
|
|
184
209
|
};
|
|
185
210
|
}
|
|
186
211
|
catch (error) {
|
|
@@ -198,33 +223,34 @@ function installationFile(env) {
|
|
|
198
223
|
: env.XDG_STATE_HOME || join(homedir(), ".local", "state");
|
|
199
224
|
return join(base, "passport", "fleet-installation.json");
|
|
200
225
|
}
|
|
201
|
-
function
|
|
226
|
+
export function fleetInstallationId(env = process.env) {
|
|
202
227
|
const path = installationFile(env);
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
228
|
+
return readOrCreatePrivateStableFile({
|
|
229
|
+
target: path,
|
|
230
|
+
label: "fleet installation identity",
|
|
231
|
+
temporaryPrefix: ".fleet-installation",
|
|
232
|
+
maxBytes: 4096,
|
|
233
|
+
create: () => `${JSON.stringify({ id: `fleet-${randomUUID()}` })}\n`,
|
|
234
|
+
parse(contents) {
|
|
235
|
+
try {
|
|
236
|
+
const saved = JSON.parse(contents);
|
|
237
|
+
return typeof saved.id === "string" && /^[A-Za-z0-9._:-]{1,128}$/.test(saved.id) ? saved.id : undefined;
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
});
|
|
217
244
|
}
|
|
218
245
|
export function scanLocalMcpConfigs(passportOrigin, env = process.env) {
|
|
219
|
-
const sources = [
|
|
220
|
-
...jsonSpecs(env).map((spec) => readJsonSource(spec, passportOrigin)),
|
|
221
|
-
readCodex(passportOrigin)
|
|
222
|
-
];
|
|
246
|
+
const sources = [...jsonSpecs(env).map((spec) => readJsonSource(spec, passportOrigin)), readCodex(passportOrigin)];
|
|
223
247
|
return {
|
|
224
248
|
scanId: `dscan_${randomUUID()}`,
|
|
225
249
|
scannedAt: Date.now(),
|
|
226
|
-
installationId:
|
|
227
|
-
installationLabel: hostname()
|
|
250
|
+
installationId: fleetInstallationId(env),
|
|
251
|
+
installationLabel: hostname()
|
|
252
|
+
.replace(/[\u0000-\u001f\u007f]/g, "")
|
|
253
|
+
.slice(0, 80) || "Managed computer",
|
|
228
254
|
sources
|
|
229
255
|
};
|
|
230
256
|
}
|
package/dist/doctor.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { lstatSync
|
|
1
|
+
import { lstatSync } from "node:fs";
|
|
2
|
+
import { readBoundedUtf8File } from "./boundedFile.js";
|
|
2
3
|
import { CliGateway, CLI_PROTOCOL_TOOLS, MIN_CLI_SERVER_VERSION } from "./cliClient.js";
|
|
3
4
|
import { assertProfileName, credsPath } from "./credentials.js";
|
|
5
|
+
const DOCTOR_CREDENTIAL_MAX_BYTES = 1024 * 1024;
|
|
4
6
|
function check(checks, id, status, summary, action) {
|
|
5
7
|
checks.push({ id, status, summary, ...(action ? { action } : {}) });
|
|
6
8
|
}
|
|
@@ -12,7 +14,11 @@ function inspectStore(checks, agentMode) {
|
|
|
12
14
|
}
|
|
13
15
|
catch (error) {
|
|
14
16
|
const missing = error.code === "ENOENT";
|
|
15
|
-
check(checks, "credential_store", agentMode && missing ? "skip" : "fail", missing
|
|
17
|
+
check(checks, "credential_store", agentMode && missing ? "skip" : "fail", missing
|
|
18
|
+
? agentMode
|
|
19
|
+
? "No local credential store is needed in agent-key mode."
|
|
20
|
+
: "No local credential store exists."
|
|
21
|
+
: "The credential store could not be inspected.", missing && !agentMode ? "Run `passport login --cloud <origin> --workspace <id>`." : undefined);
|
|
16
22
|
return { profiles: empty, count: 0 };
|
|
17
23
|
}
|
|
18
24
|
if (stat.isSymbolicLink() || !stat.isFile()) {
|
|
@@ -27,11 +33,13 @@ function inspectStore(checks, agentMode) {
|
|
|
27
33
|
check(checks, "credential_permissions", "fail", "The credential file is owned by another account.", "Move credentials into a file owned by this account.");
|
|
28
34
|
}
|
|
29
35
|
else {
|
|
30
|
-
check(checks, "credential_permissions", "pass", process.platform === "win32"
|
|
36
|
+
check(checks, "credential_permissions", "pass", process.platform === "win32"
|
|
37
|
+
? "Credential file is a regular file (Windows ACLs apply)."
|
|
38
|
+
: "Credential file is owner-only (0600).");
|
|
31
39
|
}
|
|
32
40
|
let parsed;
|
|
33
41
|
try {
|
|
34
|
-
parsed = JSON.parse(
|
|
42
|
+
parsed = JSON.parse(readBoundedUtf8File(credsPath(), DOCTOR_CREDENTIAL_MAX_BYTES));
|
|
35
43
|
}
|
|
36
44
|
catch {
|
|
37
45
|
check(checks, "credential_store", "fail", "The credential store is not valid JSON.", "Move the damaged file aside, then run `passport login` again.");
|
|
@@ -56,7 +64,10 @@ function inspectStore(checks, agentMode) {
|
|
|
56
64
|
continue;
|
|
57
65
|
}
|
|
58
66
|
const record = raw;
|
|
59
|
-
if (typeof record.refreshToken !== "string" ||
|
|
67
|
+
if (typeof record.refreshToken !== "string" ||
|
|
68
|
+
!record.refreshToken ||
|
|
69
|
+
typeof record.endpoint !== "string" ||
|
|
70
|
+
!record.endpoint) {
|
|
60
71
|
invalid.push(name);
|
|
61
72
|
continue;
|
|
62
73
|
}
|
|
@@ -74,10 +85,20 @@ function inspectStore(checks, agentMode) {
|
|
|
74
85
|
function errorText(error, redact) {
|
|
75
86
|
return redact(error instanceof Error ? error.message : String(error)) || "Unknown failure.";
|
|
76
87
|
}
|
|
88
|
+
export function nodeRuntimeSupported(version) {
|
|
89
|
+
const match = version.match(/^(\d+)\.(\d+)\.(\d+)/);
|
|
90
|
+
if (!match)
|
|
91
|
+
return false;
|
|
92
|
+
const [major, minor, patch] = match.slice(1).map(Number);
|
|
93
|
+
return major > 22 || (major === 22 && (minor > 23 || (minor === 23 && patch >= 2)));
|
|
94
|
+
}
|
|
95
|
+
function inspectRuntime(checks) {
|
|
96
|
+
const supported = nodeRuntimeSupported(process.versions.node);
|
|
97
|
+
check(checks, "runtime", supported ? "pass" : "fail", `Node.js ${process.versions.node}${supported ? " satisfies" : " does not satisfy"} the >=22.23.2 requirement.`, supported ? undefined : "Install Node.js 22.23.2 or newer.");
|
|
98
|
+
}
|
|
77
99
|
export async function runDoctor(options) {
|
|
78
100
|
const checks = [];
|
|
79
|
-
|
|
80
|
-
check(checks, "runtime", nodeMajor >= 20 ? "pass" : "fail", `Node.js ${process.versions.node}${nodeMajor >= 20 ? " satisfies" : " does not satisfy"} the >=20 requirement.`, nodeMajor >= 20 ? undefined : "Install Node.js 20 or newer.");
|
|
101
|
+
inspectRuntime(checks);
|
|
81
102
|
const hasAgentKey = Boolean(options.env.PASSPORT_AGENT_KEY);
|
|
82
103
|
const hasAgentEndpoint = Boolean(options.env.PASSPORT_ENDPOINT);
|
|
83
104
|
const agentMode = hasAgentKey && hasAgentEndpoint;
|
|
@@ -106,7 +127,11 @@ export async function runDoctor(options) {
|
|
|
106
127
|
const names = Object.keys(store.profiles).sort();
|
|
107
128
|
const candidate = options.profile ?? options.env.PASSPORT_PROFILE ?? (names.length === 1 ? names[0] : undefined);
|
|
108
129
|
if (!candidate) {
|
|
109
|
-
check(checks, "auth_config", "fail", names.length > 1
|
|
130
|
+
check(checks, "auth_config", "fail", names.length > 1
|
|
131
|
+
? `No profile was selected from ${names.length} stored profiles.`
|
|
132
|
+
: "No usable profile is configured.", names.length > 1
|
|
133
|
+
? "Run `passport doctor --profile <name>`."
|
|
134
|
+
: "Run `passport login --cloud <origin> --workspace <id>`.");
|
|
110
135
|
}
|
|
111
136
|
else {
|
|
112
137
|
try {
|
|
@@ -139,17 +164,29 @@ export async function runDoctor(options) {
|
|
|
139
164
|
const health = await fetch(new URL("/healthz", endpointOrigin), {
|
|
140
165
|
signal: AbortSignal.any([options.signal, AbortSignal.timeout(options.timeoutMs)])
|
|
141
166
|
});
|
|
142
|
-
|
|
167
|
+
const healthy = health.ok;
|
|
168
|
+
const status = health.status;
|
|
169
|
+
await health.body?.cancel().catch(() => undefined);
|
|
170
|
+
check(checks, "server_reachability", healthy ? "pass" : "fail", healthy
|
|
171
|
+
? `Passport health endpoint responded at ${endpointOrigin}.`
|
|
172
|
+
: `Passport health endpoint returned HTTP ${status}.`, healthy ? undefined : "Verify the deployment and reverse-proxy health route.");
|
|
143
173
|
}
|
|
144
174
|
catch (error) {
|
|
145
175
|
check(checks, "server_reachability", "fail", `Could not reach the Passport health endpoint: ${errorText(error, options.redactError)}`, "Check DNS, TLS, proxy routing, and network access.");
|
|
146
176
|
}
|
|
147
177
|
let gateway;
|
|
148
178
|
try {
|
|
149
|
-
gateway = await CliGateway.connect({
|
|
179
|
+
gateway = await CliGateway.connect({
|
|
180
|
+
auth,
|
|
181
|
+
caller: options.caller,
|
|
182
|
+
timeoutMs: options.timeoutMs,
|
|
183
|
+
signal: options.signal
|
|
184
|
+
});
|
|
150
185
|
}
|
|
151
186
|
catch (error) {
|
|
152
|
-
check(checks, "authentication", "fail", `Authenticated MCP handshake failed: ${errorText(error, options.redactError)}`, auth.kind === "profile"
|
|
187
|
+
check(checks, "authentication", "fail", `Authenticated MCP handshake failed: ${errorText(error, options.redactError)}`, auth.kind === "profile"
|
|
188
|
+
? "Run `passport login` to refresh this profile, then retry."
|
|
189
|
+
: "Verify PASSPORT_AGENT_KEY and its workspace access.");
|
|
153
190
|
check(checks, "server_protocol", "skip", "CLI protocol checks could not run because the authenticated handshake failed.");
|
|
154
191
|
}
|
|
155
192
|
if (gateway) {
|
|
@@ -158,8 +195,14 @@ export async function runDoctor(options) {
|
|
|
158
195
|
const protocol = await gateway.protocolDiagnostics();
|
|
159
196
|
const safeServer = protocol.server
|
|
160
197
|
? {
|
|
161
|
-
name: options
|
|
162
|
-
|
|
198
|
+
name: options
|
|
199
|
+
.redactError(protocol.server.name)
|
|
200
|
+
.replace(/[\r\n\t]/g, " ")
|
|
201
|
+
.slice(0, 80),
|
|
202
|
+
version: options
|
|
203
|
+
.redactError(protocol.server.version)
|
|
204
|
+
.replace(/[\r\n\t]/g, " ")
|
|
205
|
+
.slice(0, 40)
|
|
163
206
|
}
|
|
164
207
|
: undefined;
|
|
165
208
|
server = safeServer;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { cloudOrigin, endpoint, sameOriginWebUrl } from "./cliSupport.js";
|
|
2
|
+
/** Kept well below the profile lock's 30-second stale lease. */
|
|
3
|
+
export const LEGACY_REQUEST_TIMEOUT_MS = 10_000;
|
|
4
|
+
export function legacyCloudOrigin(raw) {
|
|
5
|
+
return cloudOrigin(raw);
|
|
6
|
+
}
|
|
7
|
+
export function legacyProfileEndpoint(raw) {
|
|
8
|
+
return endpoint(raw);
|
|
9
|
+
}
|
|
10
|
+
export function legacyCredentialEndpoint(raw, cloud) {
|
|
11
|
+
return sameOriginWebUrl(raw, cloud, "a credential endpoint");
|
|
12
|
+
}
|
|
13
|
+
export function legacyVerifyUrl(raw, cloud) {
|
|
14
|
+
return sameOriginWebUrl(raw, cloud, "a sign-in URL");
|
|
15
|
+
}
|
|
16
|
+
/** Every legacy network operation is finite and refuses redirects. In
|
|
17
|
+
* particular, a 307/308 can never replay a refresh token, session bearer, or
|
|
18
|
+
* device code to an origin selected by a response. */
|
|
19
|
+
export function legacyFetch(input, init = {}, fetcher = fetch, timeout = LEGACY_REQUEST_TIMEOUT_MS) {
|
|
20
|
+
const signals = [AbortSignal.timeout(timeout), ...(init.signal ? [init.signal] : [])];
|
|
21
|
+
return fetcher(input, {
|
|
22
|
+
...init,
|
|
23
|
+
redirect: "error",
|
|
24
|
+
signal: signals.length === 1 ? signals[0] : AbortSignal.any(signals)
|
|
25
|
+
});
|
|
26
|
+
}
|