passport-bridge 0.6.1 → 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 +87 -46
- 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 +196 -37
- package/dist/cliArgs.js +4 -0
- package/dist/cliClient.js +36 -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 +23 -9
- package/dist/credentials.js +585 -81
- package/dist/discover.js +260 -0
- package/dist/doctor.js +56 -13
- package/dist/legacyCliSecurity.js +26 -0
- package/dist/passport.js +122 -453
- 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 +23 -9
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Both binaries use the Passport gateway. Member-authenticated CLI calls share too
|
|
|
10
10
|
npm install --global passport-bridge
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Node.js
|
|
13
|
+
Node.js 22.23.2 or newer is required.
|
|
14
14
|
|
|
15
15
|
## Passport CLI
|
|
16
16
|
|
|
@@ -30,30 +30,39 @@ Remote Passport servers must use HTTPS. Plain HTTP is accepted only for local
|
|
|
30
30
|
development on `localhost`, `127.0.0.0/8`, or `::1`. Self-hosted deployments
|
|
31
31
|
should terminate HTTPS before using interactive profiles or agent keys.
|
|
32
32
|
|
|
33
|
-
Passport CLI 0.
|
|
33
|
+
Passport CLI 0.7.1 requires gateway MCP serverInfo `passport` version 0.5.0 or
|
|
34
34
|
newer and the exact four-tool governed CLI protocol. Older servers fail clearly
|
|
35
35
|
before the CLI makes a tool call.
|
|
36
36
|
|
|
37
37
|
### Commands
|
|
38
38
|
|
|
39
|
-
| Command
|
|
40
|
-
|
|
|
41
|
-
| `login`
|
|
42
|
-
| `logout`
|
|
43
|
-
| `status`
|
|
44
|
-
| `doctor`
|
|
45
|
-
| `search [query]`
|
|
46
|
-
| `describe <tool>`
|
|
47
|
-
| `run <tool> [json]`
|
|
48
|
-
| `connect [app...]`
|
|
49
|
-
| `resources [uri]`
|
|
50
|
-
| `prompts [name]`
|
|
51
|
-
| `
|
|
52
|
-
| `
|
|
53
|
-
| `
|
|
39
|
+
| Command | Purpose |
|
|
40
|
+
| -------------------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
41
|
+
| `login` | Complete device sign-in and save a rotating CLI credential. |
|
|
42
|
+
| `logout` | Revoke the credential and remove its local profile. |
|
|
43
|
+
| `status` | Show the workspace, member, client, and visible MCP connection states. |
|
|
44
|
+
| `doctor` | Check runtime, credential-store safety, configuration, reachability, authentication, and CLI protocol compatibility. |
|
|
45
|
+
| `search [query]` | Search permitted tool definitions. An empty query lists the complete catalog. |
|
|
46
|
+
| `describe <tool>` | Print one exact definition and its full parameter schema. |
|
|
47
|
+
| `run <tool> [json]` | Run a tool through Passport governance. |
|
|
48
|
+
| `connect [app...]` | Show secure member connection links and optionally wait for completion. |
|
|
49
|
+
| `resources [uri]` | List or read MCP resources. |
|
|
50
|
+
| `prompts [name]` | List or get MCP prompts. |
|
|
51
|
+
| `discover` | Scan supported global MCP configuration and submit a privacy-minimized fleet report. |
|
|
52
|
+
| `session` | Process NDJSON commands through one authenticated MCP session. |
|
|
53
|
+
| `completion <shell>` | Generate completion for Bash, Zsh, or Fish without a profile or network. |
|
|
54
|
+
| `help [command]` | Show general or command-specific help. |
|
|
55
|
+
| `version` | Show the package version and locally resolvable profile context. |
|
|
54
56
|
|
|
55
57
|
Every command accepts `--profile <name>`, `--json`, `--timeout <seconds>`, `--quiet`, and `--caller <id>` where applicable.
|
|
56
58
|
|
|
59
|
+
`passport discover` is the cross-platform, headless Passport Discover scanner.
|
|
60
|
+
It uploads no paths, commands or arguments, environment values, headers,
|
|
61
|
+
credentials, endpoint paths or query strings, prompts, files, tool payloads,
|
|
62
|
+
or traffic. Managed-policy violations return exit `5`, so endpoint management
|
|
63
|
+
can use it as a compliance gate without Passport silently editing client
|
|
64
|
+
configuration.
|
|
65
|
+
|
|
57
66
|
### Diagnostics
|
|
58
67
|
|
|
59
68
|
Run diagnostics before opening a support ticket or promoting a CLI release:
|
|
@@ -110,6 +119,34 @@ passport run github_search_issues --set query=SSO --set-json limit=10
|
|
|
110
119
|
|
|
111
120
|
These forms are mutually exclusive. `--set` produces strings and `--set-json` accepts any valid JSON value.
|
|
112
121
|
|
|
122
|
+
### Persistent agent sessions
|
|
123
|
+
|
|
124
|
+
Agents performing several operations can avoid repeated process startup, token
|
|
125
|
+
exchange, MCP initialization, and protocol checks by keeping one CLI process
|
|
126
|
+
open:
|
|
127
|
+
|
|
128
|
+
```sh
|
|
129
|
+
printf '%s\n' \
|
|
130
|
+
'{"id":"find","argv":["search","open issues"]}' \
|
|
131
|
+
'{"id":"call","argv":["run","github_search_issues","{\"query\":\"SSO\"}"]}' \
|
|
132
|
+
| passport session --profile cli@ws_example
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`passport session` reads one `{"id"?:string|number,"argv":string[]}` request
|
|
136
|
+
per line and emits one JSON response per non-empty line. Requests run
|
|
137
|
+
sequentially. Each response contains `ok`, `exitCode`, and either `result` or
|
|
138
|
+
the standard CLI error fields; `id` is echoed for every valid request. A request failure
|
|
139
|
+
does not close the session. EOF or SIGINT/SIGTERM closes the MCP transport
|
|
140
|
+
cleanly.
|
|
141
|
+
|
|
142
|
+
Session input is limited to 1 MiB per line and 128 arguments. Set global
|
|
143
|
+
`--profile`, `--caller`, and `--timeout` options on `passport session`, not in
|
|
144
|
+
individual request `argv` values. Supported request commands are `status`,
|
|
145
|
+
`search`, `describe`, `run`, `connect`, `resources`, `prompts`, and `discover`.
|
|
146
|
+
The mode does not weaken authorization: every operation still executes through
|
|
147
|
+
the governed gateway, and cached access tokens retain the normal expiry and
|
|
148
|
+
401-refresh behavior.
|
|
149
|
+
|
|
113
150
|
### Approvals and connections
|
|
114
151
|
|
|
115
152
|
An approval-required call exits immediately with code 4 and its approval ID. `--wait <seconds>` retries only after a definite structured `approval_pending` response:
|
|
@@ -145,39 +182,41 @@ Human mode writes text content to stdout. Binary or other non-text content requi
|
|
|
145
182
|
|
|
146
183
|
With `--json`, stdout contains exactly one JSON value and no progress text. Hints and warnings use stderr. The success value for each command is:
|
|
147
184
|
|
|
148
|
-
| Command
|
|
149
|
-
|
|
|
150
|
-
| `login`
|
|
151
|
-
| `logout`
|
|
152
|
-
| `status`
|
|
153
|
-
| `doctor`
|
|
154
|
-
| `search`
|
|
155
|
-
| `describe`
|
|
156
|
-
| `run`
|
|
157
|
-
| `connect`
|
|
158
|
-
| `resources`
|
|
159
|
-
| `prompts`
|
|
160
|
-
| `
|
|
161
|
-
| `
|
|
162
|
-
| `
|
|
185
|
+
| Command | JSON value |
|
|
186
|
+
| ------------ | --------------------------------------------------------------------------------------------------------- |
|
|
187
|
+
| `login` | `{profile, endpoint, client, surface}` |
|
|
188
|
+
| `logout` | `{profile, removed, revoked}` |
|
|
189
|
+
| `status` | `{workspace, member, endpoint, auth, profile?, client, mcps}` |
|
|
190
|
+
| `doctor` | `{version,ok,auth,profile?,profileCount,endpointOrigin?,server?,checks}` (also emitted when checks fail). |
|
|
191
|
+
| `search` | The gateway search payload, including `results` or `catalog` and `note`. |
|
|
192
|
+
| `describe` | One tool definition. |
|
|
193
|
+
| `run` | The complete governed MCP tool result, preserving every content block and upstream `structuredContent`. |
|
|
194
|
+
| `connect` | The gateway connection payload, including `connections` and optional `connectAllUrl`. |
|
|
195
|
+
| `resources` | The MCP list or read result. |
|
|
196
|
+
| `prompts` | The MCP list or get result. |
|
|
197
|
+
| `discover` | `{snapshot,report,compliant}`. The snapshot contains privacy-minimized metadata only. |
|
|
198
|
+
| `session` | NDJSON envelopes: `{id?,ok,exitCode,result?}` or `{id?,ok:false,error,cause,exitCode,...}`. |
|
|
199
|
+
| `completion` | `{shell,script}`. Human mode emits the raw completion script. |
|
|
200
|
+
| `help` | `{command, help}` |
|
|
201
|
+
| `version` | `{version, endpoint?, profile?}` |
|
|
163
202
|
|
|
164
203
|
JSON errors have a stable shape:
|
|
165
204
|
|
|
166
205
|
```json
|
|
167
|
-
{"error":"...","cause":"blocked","exitCode":5,"app":"github"}
|
|
206
|
+
{ "error": "...", "cause": "blocked", "exitCode": 5, "app": "github" }
|
|
168
207
|
```
|
|
169
208
|
|
|
170
209
|
`approvalId` and `app` are included when supplied by the gateway.
|
|
171
210
|
|
|
172
|
-
| Exit | Meaning
|
|
173
|
-
| ---: |
|
|
174
|
-
|
|
|
175
|
-
|
|
|
176
|
-
|
|
|
177
|
-
|
|
|
178
|
-
|
|
|
179
|
-
|
|
|
180
|
-
|
|
|
211
|
+
| Exit | Meaning |
|
|
212
|
+
| ---: | ------------------------------------------------------ |
|
|
213
|
+
| 0 | Success |
|
|
214
|
+
| 1 | Network, timeout, server, or unsupported-content error |
|
|
215
|
+
| 2 | Missing, expired, or revoked authentication |
|
|
216
|
+
| 3 | The MCP needs member sign-in |
|
|
217
|
+
| 4 | Approval is pending |
|
|
218
|
+
| 5 | Policy, guardrail, selection, or approval denial |
|
|
219
|
+
| 6 | Invalid usage or unknown tool/app |
|
|
181
220
|
|
|
182
221
|
## Profiles
|
|
183
222
|
|
|
@@ -244,10 +283,12 @@ access and points support/source inquiries at Passport's public release repo.
|
|
|
244
283
|
|
|
245
284
|
The CLI deliberately performs no background registry request, telemetry, or
|
|
246
285
|
automatic self-update. Check explicitly with `npm view passport-bridge version`
|
|
247
|
-
and upgrade with `npm install --global passport-bridge@latest`.
|
|
248
|
-
|
|
249
|
-
OIDC
|
|
250
|
-
|
|
286
|
+
and upgrade with `npm install --global passport-bridge@latest`. Releases publish
|
|
287
|
+
only through the repository's npm trusted-publisher workflow with short-lived
|
|
288
|
+
OIDC credentials, exact-source gates, verified tarball integrity, and registry
|
|
289
|
+
signature checks. npm does not expose public provenance attestations for a
|
|
290
|
+
private source repository, so Passport does not claim one. Platform signing is
|
|
291
|
+
not applicable to these JavaScript npm bins.
|
|
251
292
|
|
|
252
293
|
## MCP stdio bridge
|
|
253
294
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync } from "node:fs";
|
|
2
|
+
const READ_CHUNK_BYTES = 64 * 1024;
|
|
3
|
+
export function readBoundedUtf8Descriptor(descriptor, maxBytes) {
|
|
4
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1)
|
|
5
|
+
throw new Error("Invalid local file size limit.");
|
|
6
|
+
const chunks = [];
|
|
7
|
+
let total = 0;
|
|
8
|
+
for (;;) {
|
|
9
|
+
const chunk = Buffer.allocUnsafe(Math.min(READ_CHUNK_BYTES, maxBytes - total + 1));
|
|
10
|
+
const count = readSync(descriptor, chunk, 0, chunk.length, null);
|
|
11
|
+
if (count === 0)
|
|
12
|
+
break;
|
|
13
|
+
total += count;
|
|
14
|
+
if (total > maxBytes)
|
|
15
|
+
throw new Error("Local input exceeded Passport's safety limit.");
|
|
16
|
+
chunks.push(chunk.subarray(0, count));
|
|
17
|
+
}
|
|
18
|
+
return Buffer.concat(chunks, total).toString("utf8");
|
|
19
|
+
}
|
|
20
|
+
export function readBoundedUtf8File(path, maxBytes) {
|
|
21
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1)
|
|
22
|
+
throw new Error("Invalid local file size limit.");
|
|
23
|
+
// Inspect before open so a named pipe cannot block this synchronous boundary.
|
|
24
|
+
// O_NONBLOCK contains a replacement race; O_NOFOLLOW rejects a symlink at the
|
|
25
|
+
// actual open boundary. The descriptor identity check also covers platforms
|
|
26
|
+
// where O_NOFOLLOW is unavailable.
|
|
27
|
+
const before = lstatSync(path);
|
|
28
|
+
if (before.isSymbolicLink() || !before.isFile())
|
|
29
|
+
throw new Error("Local input must be a regular file.");
|
|
30
|
+
const noFollow = typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;
|
|
31
|
+
const descriptor = openSync(path, constants.O_RDONLY | constants.O_NONBLOCK | noFollow);
|
|
32
|
+
try {
|
|
33
|
+
const stat = fstatSync(descriptor);
|
|
34
|
+
if (!stat.isFile())
|
|
35
|
+
throw new Error("Local input must be a regular file.");
|
|
36
|
+
if (stat.dev !== before.dev || stat.ino !== before.ino) {
|
|
37
|
+
throw new Error("Local input changed while it was being opened.");
|
|
38
|
+
}
|
|
39
|
+
if (stat.size > maxBytes)
|
|
40
|
+
throw new Error("Local input exceeded Passport's safety limit.");
|
|
41
|
+
return readBoundedUtf8Descriptor(descriptor, maxBytes);
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
closeSync(descriptor);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export const CLI_MCP_RESPONSE_MAX_BYTES = 8 * 1024 * 1024;
|
|
2
|
+
/** Bound one-shot MCP JSON responses in total and long-lived SSE responses per
|
|
3
|
+
* event. The wrapper always cancels and unlocks the original reader on every
|
|
4
|
+
* terminal path so failed or abandoned CLI calls release their socket. */
|
|
5
|
+
export async function boundMcpResponse(response, maxBytes = CLI_MCP_RESPONSE_MAX_BYTES) {
|
|
6
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1)
|
|
7
|
+
throw new Error("Invalid MCP response size limit.");
|
|
8
|
+
const eventStream = response.headers.get("content-type")?.toLowerCase().startsWith("text/event-stream") ?? false;
|
|
9
|
+
const rawLength = response.headers.get("content-length");
|
|
10
|
+
if (!eventStream && rawLength !== null) {
|
|
11
|
+
if (!/^\d+$/.test(rawLength) || !Number.isSafeInteger(Number(rawLength)) || Number(rawLength) > maxBytes) {
|
|
12
|
+
await response.body?.cancel().catch(() => undefined);
|
|
13
|
+
throw new Error("MCP response exceeded Passport's safety limit.");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (!response.body)
|
|
17
|
+
return response;
|
|
18
|
+
const reader = response.body.getReader();
|
|
19
|
+
let released = false;
|
|
20
|
+
const release = () => {
|
|
21
|
+
if (released)
|
|
22
|
+
return;
|
|
23
|
+
released = true;
|
|
24
|
+
reader.releaseLock();
|
|
25
|
+
};
|
|
26
|
+
const cancel = async (reason) => {
|
|
27
|
+
try {
|
|
28
|
+
await reader.cancel(reason);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// The original stream may already be errored; releasing the lock remains
|
|
32
|
+
// mandatory even when cancellation itself cannot complete cleanly.
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
release();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
let bytes = 0;
|
|
39
|
+
let lineHasContent = false;
|
|
40
|
+
let previousWasCarriageReturn = false;
|
|
41
|
+
const body = new ReadableStream({
|
|
42
|
+
async pull(controller) {
|
|
43
|
+
try {
|
|
44
|
+
const next = await reader.read();
|
|
45
|
+
if (next.done) {
|
|
46
|
+
release();
|
|
47
|
+
controller.close();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (eventStream) {
|
|
51
|
+
for (const byte of next.value) {
|
|
52
|
+
bytes++;
|
|
53
|
+
if (byte === 13) {
|
|
54
|
+
if (!lineHasContent)
|
|
55
|
+
bytes = 0;
|
|
56
|
+
lineHasContent = false;
|
|
57
|
+
previousWasCarriageReturn = true;
|
|
58
|
+
}
|
|
59
|
+
else if (byte === 10) {
|
|
60
|
+
if (!previousWasCarriageReturn && !lineHasContent)
|
|
61
|
+
bytes = 0;
|
|
62
|
+
lineHasContent = false;
|
|
63
|
+
previousWasCarriageReturn = false;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
lineHasContent = true;
|
|
67
|
+
previousWasCarriageReturn = false;
|
|
68
|
+
}
|
|
69
|
+
if (bytes > maxBytes)
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
bytes += next.value.byteLength;
|
|
75
|
+
}
|
|
76
|
+
if (bytes > maxBytes) {
|
|
77
|
+
await cancel(new Error("MCP response exceeded Passport's safety limit."));
|
|
78
|
+
controller.error(new Error("MCP response exceeded Passport's safety limit."));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
controller.enqueue(next.value);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
await cancel();
|
|
85
|
+
controller.error(new Error("MCP response stream failed."));
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
cancel
|
|
89
|
+
});
|
|
90
|
+
return new Response(body, {
|
|
91
|
+
status: response.status,
|
|
92
|
+
statusText: response.statusText,
|
|
93
|
+
headers: response.headers
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
export function boundedMcpFetch(base, maxBytes = CLI_MCP_RESPONSE_MAX_BYTES) {
|
|
97
|
+
return (async (input, init) => boundMcpResponse(await base(input, init), maxBytes));
|
|
98
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export const DEFAULT_API_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
2
|
+
/** Parse a Fetch JSON response without trusting Content-Length or allowing a
|
|
3
|
+
* chunked Passport response to grow the client process without bound. */
|
|
4
|
+
export async function readBoundedJson(response, maxBytes = DEFAULT_API_RESPONSE_BYTES) {
|
|
5
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1) {
|
|
6
|
+
throw new Error("Passport response size limit is invalid.");
|
|
7
|
+
}
|
|
8
|
+
const rawLength = response.headers.get("content-length");
|
|
9
|
+
if (rawLength !== null && !/^\d+$/.test(rawLength)) {
|
|
10
|
+
throw new Error("Passport returned an invalid or oversized response.");
|
|
11
|
+
}
|
|
12
|
+
const declared = rawLength === null ? undefined : Number(rawLength);
|
|
13
|
+
if (declared !== undefined && (!Number.isSafeInteger(declared) || declared > maxBytes)) {
|
|
14
|
+
await response.body?.cancel().catch(() => undefined);
|
|
15
|
+
throw new Error("Passport returned an invalid or oversized response.");
|
|
16
|
+
}
|
|
17
|
+
if (!response.body)
|
|
18
|
+
throw new Error("Passport returned an invalid or oversized response.");
|
|
19
|
+
const reader = response.body.getReader();
|
|
20
|
+
const chunks = [];
|
|
21
|
+
let total = 0;
|
|
22
|
+
try {
|
|
23
|
+
for (;;) {
|
|
24
|
+
const { done, value } = await reader.read();
|
|
25
|
+
if (done)
|
|
26
|
+
break;
|
|
27
|
+
if (!(value instanceof Uint8Array) || total + value.byteLength > maxBytes) {
|
|
28
|
+
await reader.cancel().catch(() => undefined);
|
|
29
|
+
throw new Error("Passport returned an invalid or oversized response.");
|
|
30
|
+
}
|
|
31
|
+
chunks.push(value);
|
|
32
|
+
total += value.byteLength;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
throw new Error("Passport returned an invalid or oversized response.");
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
reader.releaseLock();
|
|
40
|
+
}
|
|
41
|
+
if (declared !== undefined && declared !== total) {
|
|
42
|
+
throw new Error("Passport returned an invalid or oversized response.");
|
|
43
|
+
}
|
|
44
|
+
const bytes = new Uint8Array(total);
|
|
45
|
+
let offset = 0;
|
|
46
|
+
for (const chunk of chunks) {
|
|
47
|
+
bytes.set(chunk, offset);
|
|
48
|
+
offset += chunk.byteLength;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
throw new Error("Passport returned invalid JSON.");
|
|
55
|
+
}
|
|
56
|
+
}
|