@osd-project/osd-cli 0.0.0 → 0.8.3
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/LICENSE +202 -0
- package/README.md +585 -4
- package/THIRD_PARTY_NOTICES.md +96 -0
- package/dist/auth-store.d.ts +38 -0
- package/dist/auth-store.js +239 -0
- package/dist/brand-catalog.d.ts +65 -0
- package/dist/brand-catalog.js +175 -0
- package/dist/connect-gate.d.ts +31 -0
- package/dist/connect-gate.js +82 -0
- package/dist/contracts.d.ts +61 -0
- package/dist/contracts.js +145 -0
- package/dist/exit-codes.d.ts +32 -0
- package/dist/exit-codes.js +40 -0
- package/dist/format.d.ts +71 -0
- package/dist/format.js +99 -0
- package/dist/generated/schemas.d.ts +2 -0
- package/dist/generated/schemas.js +1781 -0
- package/dist/guarded-fetch.d.ts +28 -0
- package/dist/guarded-fetch.js +252 -0
- package/dist/help.d.ts +27 -0
- package/dist/help.js +32 -0
- package/dist/http-fetch.d.ts +1 -0
- package/dist/http-fetch.js +17 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +821 -0
- package/dist/logout.d.ts +16 -0
- package/dist/logout.js +82 -0
- package/dist/mcp-auth.d.ts +70 -0
- package/dist/mcp-auth.js +603 -0
- package/dist/mcp-card.d.ts +23 -0
- package/dist/mcp-card.js +18 -0
- package/dist/mcp-client.d.ts +77 -0
- package/dist/mcp-client.js +193 -0
- package/dist/net-guard.d.ts +66 -0
- package/dist/net-guard.js +152 -0
- package/dist/proxy-config.d.ts +51 -0
- package/dist/proxy-config.js +147 -0
- package/dist/request.d.ts +32 -0
- package/dist/request.js +62 -0
- package/dist/resolve-endpoint.d.ts +62 -0
- package/dist/resolve-endpoint.js +172 -0
- package/dist/search.d.ts +39 -0
- package/dist/search.js +69 -0
- package/dist/skill.d.ts +155 -0
- package/dist/skill.js +320 -0
- package/dist/updates.d.ts +101 -0
- package/dist/updates.js +541 -0
- package/dist/verify.d.ts +92 -0
- package/dist/verify.js +379 -0
- package/package.json +51 -3
- package/skill/osd/SKILL.md +400 -0
- package/skill/osd/references/connect-mcp.md +48 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
OSD profiles [Agentic Resource Discovery (ARD)](https://github.com/ards-project/ard-spec).
|
|
4
|
+
This package vendors JSON schemas derived from the ARD specification
|
|
5
|
+
repository under `contracts/schemas/`. Twelve schemas in total are derived from
|
|
6
|
+
upstream files: three copies of upstream JSON Schema files and nine OSD schemas
|
|
7
|
+
derived from the upstream OpenAPI definitions. All of them are embedded in the
|
|
8
|
+
published package in `dist/generated/schemas.js`.
|
|
9
|
+
|
|
10
|
+
## Upstream copyright and license
|
|
11
|
+
|
|
12
|
+
The ARD schemas are licensed under the Apache License, Version 2.0. The
|
|
13
|
+
upstream `LICENSE` file at both pinned revisions below carries this copyright
|
|
14
|
+
line:
|
|
15
|
+
|
|
16
|
+
Copyright 2026 Agentic Resource Discovery project
|
|
17
|
+
|
|
18
|
+
The Apache License 2.0 text is in the [LICENSE](LICENSE) file at the root of
|
|
19
|
+
this repository. The upstream repository has no `NOTICE` file at either pinned
|
|
20
|
+
revision.
|
|
21
|
+
|
|
22
|
+
## Vendored schemas and upstream revisions
|
|
23
|
+
|
|
24
|
+
### Copies of upstream JSON Schema files
|
|
25
|
+
|
|
26
|
+
| File in this repository | Upstream file | Upstream revision |
|
|
27
|
+
|-------------------------|---------------|-------------------|
|
|
28
|
+
| `contracts/schemas/ard-entry/0.3.0.schema.json` | `spec/schemas/ard-entry.schema.json` (ARD v0.91) | `aa3e598bb7752a9175897823234311216acfa864` |
|
|
29
|
+
| `contracts/schemas/ard-ai-catalog/0.1.0.schema.json` | `spec/schemas/ai-catalog.schema.json` (ARD v0.9) | `5fa2f5aef790b478319f6a3b43adf4661b0ed0e0` |
|
|
30
|
+
| `contracts/schemas/ard-ai-catalog/0.2.0.schema.json` | `spec/schemas/ai-catalog.schema.json` (ARD v0.9) | `5fa2f5aef790b478319f6a3b43adf4661b0ed0e0` |
|
|
31
|
+
|
|
32
|
+
### OSD schemas derived from the upstream OpenAPI definitions
|
|
33
|
+
|
|
34
|
+
These nine files are OSD schemas, not copies. They are JSON Schema versions of
|
|
35
|
+
components in the upstream OpenAPI file `spec/schemas/ard.openapi.yaml`.
|
|
36
|
+
|
|
37
|
+
| File in this repository | Upstream OpenAPI component | Upstream revision |
|
|
38
|
+
|-------------------------|----------------------------|-------------------|
|
|
39
|
+
| `contracts/schemas/registry-search-request/0.1.0.schema.json` | `SearchRequest` (ARD v0.9) | `5fa2f5aef790b478319f6a3b43adf4661b0ed0e0` |
|
|
40
|
+
| `contracts/schemas/registry-search-request/0.2.0.schema.json` | `SearchRequest` (ARD v0.9) | `5fa2f5aef790b478319f6a3b43adf4661b0ed0e0` |
|
|
41
|
+
| `contracts/schemas/registry-search-request/0.3.0.schema.json` | `SearchRequest` (ARD v0.91) | `aa3e598bb7752a9175897823234311216acfa864` |
|
|
42
|
+
| `contracts/schemas/registry-search-response/0.1.0.schema.json` | `SearchResponse`, `SearchResultItem`, `RegistryReferral` (ARD v0.9) | `5fa2f5aef790b478319f6a3b43adf4661b0ed0e0` |
|
|
43
|
+
| `contracts/schemas/registry-search-response/0.2.0.schema.json` | `SearchResponse`, `SearchResultItem`, `RegistryReferral` (ARD v0.9) | `5fa2f5aef790b478319f6a3b43adf4661b0ed0e0` |
|
|
44
|
+
| `contracts/schemas/registry-search-response/0.3.0.schema.json` | `SearchResponse`, `SearchResultItem`, `RegistryReferral` (ARD v0.91) | `aa3e598bb7752a9175897823234311216acfa864` |
|
|
45
|
+
| `contracts/schemas/error-response/0.1.0.schema.json` | `Error` (ARD v0.9) | `5fa2f5aef790b478319f6a3b43adf4661b0ed0e0` |
|
|
46
|
+
| `contracts/schemas/error-response/0.2.0.schema.json` | `Error` (ARD v0.9) | `5fa2f5aef790b478319f6a3b43adf4661b0ed0e0` |
|
|
47
|
+
| `contracts/schemas/error-response/0.3.0.schema.json` | `Error` (ARD v0.91) | `aa3e598bb7752a9175897823234311216acfa864` |
|
|
48
|
+
|
|
49
|
+
Upstream repository: https://github.com/ards-project/ard-spec
|
|
50
|
+
|
|
51
|
+
## Changes made to the vendored schemas
|
|
52
|
+
|
|
53
|
+
- `ard-entry/0.3.0`: the schema `$id` is replaced with an OSD schema ID and a
|
|
54
|
+
`$comment` source annotation is added. No other change to the schema
|
|
55
|
+
content.
|
|
56
|
+
- `ard-ai-catalog/0.1.0`: the schema `$id` is replaced with an OSD schema ID
|
|
57
|
+
and a `$comment` source annotation is added. In addition, `additionalProperties`
|
|
58
|
+
of `catalogEntry.metadata` is `true` (any JSON value) instead of
|
|
59
|
+
restricting values to string, number, boolean or null.
|
|
60
|
+
- `ard-ai-catalog/0.2.0`: the schema `$id` is replaced with an OSD schema ID
|
|
61
|
+
and a `$comment` source annotation is added. The file is also reformatted
|
|
62
|
+
(whitespace and line breaks only); the schema content is otherwise the same
|
|
63
|
+
as upstream.
|
|
64
|
+
|
|
65
|
+
The nine OpenAPI-derived schemas differ from upstream as follows:
|
|
66
|
+
|
|
67
|
+
- They are converted from OpenAPI schema objects to standalone JSON Schema
|
|
68
|
+
(draft 2020-12) files, each with an OSD `$id`, a `title` and a `$comment`
|
|
69
|
+
source annotation.
|
|
70
|
+
- Property names, types, enums, defaults, required lists, numeric bounds and
|
|
71
|
+
`additionalProperties: false` on the request and response envelopes follow
|
|
72
|
+
upstream. Many property descriptions are shortened or reworded, and the
|
|
73
|
+
upstream `example` values are not carried into the schemas.
|
|
74
|
+
- `registry-search-request`: `QueryModel` and `SearchQueryModel` become the
|
|
75
|
+
`query` and `searchQuery` definitions. In 0.1.0 and 0.2.0 the upstream
|
|
76
|
+
v0.9 text is the basis; the 0.2.0 file also has a `@context` query property,
|
|
77
|
+
which the ARD v0.9 OpenAPI file does not have (it appears in ARD v0.91). The
|
|
78
|
+
0.3.0 file follows the ARD v0.91 definition, with a shortened `@context`
|
|
79
|
+
and `filter` description.
|
|
80
|
+
- `registry-search-response`: the result item references the OSD catalog entry
|
|
81
|
+
schema of the same contract version, not the upstream catalog entry or
|
|
82
|
+
`EntryFields` schema, and then adds the upstream `score` and `source`
|
|
83
|
+
fields. The upstream `RegistryReferral` shape is kept (identifier,
|
|
84
|
+
displayName, type, url).
|
|
85
|
+
- `error-response`: the `errorCode` and `message` properties are kept. The
|
|
86
|
+
files for 0.1.0 and 0.2.0 differ only in `$id` and formatting.
|
|
87
|
+
|
|
88
|
+
The fixtures under `contracts/fixtures/` in the source repository (not in the
|
|
89
|
+
npm package) reuse the referral example values from the upstream OpenAPI file
|
|
90
|
+
(`urn:air:nlweb.ai:registry:public`, "Public Agent Finder",
|
|
91
|
+
`https://finder.nlweb.ai/search`) in the `registry-search-response-referral`
|
|
92
|
+
valid fixtures for each contract version, and in the 0.1.0
|
|
93
|
+
`registry-search-response-referral-bad-type` invalid fixture.
|
|
94
|
+
|
|
95
|
+
These files are vendored copies. Changes to them are made in the OSD contracts
|
|
96
|
+
source and re-synced, not edited in place here.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Stats } from "node:fs";
|
|
2
|
+
import type { OAuthClientInformationMixed, OAuthTokens } from "@modelcontextprotocol/client";
|
|
3
|
+
export interface AuthRecord {
|
|
4
|
+
clientInformation?: OAuthClientInformationMixed;
|
|
5
|
+
tokens?: OAuthTokens;
|
|
6
|
+
}
|
|
7
|
+
export type AuthRunner = (command: string, args: string[], input?: string) => Promise<string>;
|
|
8
|
+
interface AuthStoreOptions {
|
|
9
|
+
runner?: AuthRunner;
|
|
10
|
+
platform?: NodeJS.Platform;
|
|
11
|
+
chmod?: (file: string, mode: number) => Promise<void>;
|
|
12
|
+
stat?: (file: string) => Promise<Stats>;
|
|
13
|
+
aclProbe?: (file: string) => Promise<string>;
|
|
14
|
+
}
|
|
15
|
+
export declare class AuthStore {
|
|
16
|
+
private readonly options;
|
|
17
|
+
private readonly dir;
|
|
18
|
+
private readonly platform;
|
|
19
|
+
private readonly runner;
|
|
20
|
+
private readonly changeMode;
|
|
21
|
+
private readonly fileStat;
|
|
22
|
+
constructor(options?: AuthStoreOptions);
|
|
23
|
+
private file;
|
|
24
|
+
private vault;
|
|
25
|
+
private ensurePrivate;
|
|
26
|
+
private prepareDirectory;
|
|
27
|
+
private removeFile;
|
|
28
|
+
private markVault;
|
|
29
|
+
private migrate;
|
|
30
|
+
read(endpoint: string, { migrate }?: {
|
|
31
|
+
migrate?: boolean;
|
|
32
|
+
}): Promise<AuthRecord>;
|
|
33
|
+
write(endpoint: string, record: AuthRecord): Promise<void>;
|
|
34
|
+
private deleteAccount;
|
|
35
|
+
delete(endpoint: string): Promise<boolean>;
|
|
36
|
+
deleteAll(): Promise<boolean>;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { chmod, mkdir, readFile, readdir, stat, unlink, writeFile } from "node:fs/promises";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
const run = (command, args, input) => new Promise((resolve, reject) => {
|
|
7
|
+
const child = execFile(command, args, { encoding: "utf8", timeout: 15_000 }, (error, stdout, stderr) => {
|
|
8
|
+
if (error)
|
|
9
|
+
reject(Object.assign(error, { stderr }));
|
|
10
|
+
else
|
|
11
|
+
resolve(stdout);
|
|
12
|
+
});
|
|
13
|
+
child.stdin?.on("error", () => undefined); // An early process exit can close stdin before the write.
|
|
14
|
+
child.stdin?.end(input ?? "");
|
|
15
|
+
});
|
|
16
|
+
function account(endpoint) {
|
|
17
|
+
return createHash("sha256").update(endpoint).digest("hex").slice(0, 16);
|
|
18
|
+
}
|
|
19
|
+
function parseRecord(payload) {
|
|
20
|
+
const value = JSON.parse(payload);
|
|
21
|
+
return value !== null && typeof value === "object"
|
|
22
|
+
? { clientInformation: value.clientInformation, tokens: value.tokens }
|
|
23
|
+
: {};
|
|
24
|
+
}
|
|
25
|
+
const powershellArgs = (script) => [
|
|
26
|
+
"-NoLogo", "-NoProfile", "-NonInteractive", "-Command",
|
|
27
|
+
`$ErrorActionPreference = 'Stop'; [Console]::InputEncoding = [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new(); ${script}`,
|
|
28
|
+
];
|
|
29
|
+
export class AuthStore {
|
|
30
|
+
options;
|
|
31
|
+
dir = process.env.OSD_AUTH_DIR ?? path.join(homedir(), ".osd", "auth");
|
|
32
|
+
platform;
|
|
33
|
+
runner;
|
|
34
|
+
changeMode;
|
|
35
|
+
fileStat;
|
|
36
|
+
constructor(options = {}) {
|
|
37
|
+
this.options = options;
|
|
38
|
+
this.platform = options.platform ?? process.platform;
|
|
39
|
+
this.runner = options.runner ?? run;
|
|
40
|
+
this.changeMode = options.chmod ?? chmod;
|
|
41
|
+
this.fileStat = options.stat ?? stat;
|
|
42
|
+
}
|
|
43
|
+
file(key) {
|
|
44
|
+
return path.join(this.dir, `${key}.json`);
|
|
45
|
+
}
|
|
46
|
+
async vault(action, key, payload) {
|
|
47
|
+
let command;
|
|
48
|
+
let args;
|
|
49
|
+
let input;
|
|
50
|
+
if (this.platform === "darwin") {
|
|
51
|
+
command = "security";
|
|
52
|
+
args = [action === "read" ? "find-generic-password" : action === "write" ? "add-generic-password" : "delete-generic-password", "-s", "osd-cli", "-a", key];
|
|
53
|
+
if (action === "read")
|
|
54
|
+
args.push("-w");
|
|
55
|
+
// shortcut: password is briefly visible in process arguments via -w, switch to a native keychain API if that window matters
|
|
56
|
+
if (action === "write")
|
|
57
|
+
args.push("-U", "-w", payload);
|
|
58
|
+
}
|
|
59
|
+
else if (this.platform === "linux") {
|
|
60
|
+
command = "secret-tool";
|
|
61
|
+
args = [action === "read" ? "lookup" : action === "write" ? "store" : "clear"];
|
|
62
|
+
if (action === "write")
|
|
63
|
+
args.push("--label=osd-cli");
|
|
64
|
+
args.push("service", "osd-cli", "account", key);
|
|
65
|
+
if (action === "write")
|
|
66
|
+
input = payload;
|
|
67
|
+
}
|
|
68
|
+
else if (this.platform === "win32") {
|
|
69
|
+
command = "powershell.exe";
|
|
70
|
+
const operation = action === "write"
|
|
71
|
+
? `try { $vault.Remove($vault.Retrieve('osd-cli', '${key}')) } catch { if ($_.Exception.GetBaseException().HResult -ne -2147023728) { throw } }; ` +
|
|
72
|
+
`$vault.Add([Windows.Security.Credentials.PasswordCredential]::new('osd-cli', '${key}', [Console]::In.ReadToEnd()))`
|
|
73
|
+
: `$credential = $vault.Retrieve('osd-cli', '${key}'); ${action === "read" ? "$credential.RetrievePassword(); [Console]::Out.Write($credential.Password)" : "$vault.Remove($credential)"}`;
|
|
74
|
+
args = powershellArgs(`[void][Windows.Security.Credentials.PasswordVault,Windows.Security.Credentials,ContentType=WindowsRuntime]; ` +
|
|
75
|
+
`$vault = [Windows.Security.Credentials.PasswordVault]::new(); ` +
|
|
76
|
+
`try { ${operation} } catch { if ($_.Exception.GetBaseException().HResult -eq -2147023728) { exit 44 }; exit 1 }`);
|
|
77
|
+
if (action === "write")
|
|
78
|
+
input = payload;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
return { available: false };
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
return { available: true, payload: await this.runner(command, args, input), removed: action === "delete" };
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
const { code, stderr = "" } = error;
|
|
88
|
+
if (code === "ENOENT" || code === 127 || /(?:command|executable|program).*not found/i.test(stderr))
|
|
89
|
+
return { available: false };
|
|
90
|
+
if (action !== "write" && (code === 44 || (this.platform === "linux" && code === 1 && stderr.trim() === "")))
|
|
91
|
+
return { available: true };
|
|
92
|
+
// execFile errors can contain the full command, including macOS's -w secret.
|
|
93
|
+
throw new Error(`Could not ${action} OAuth credentials in the system vault.`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async ensurePrivate(file, directory) {
|
|
97
|
+
if (this.platform === "win32") {
|
|
98
|
+
const text = this.options.aclProbe
|
|
99
|
+
? await this.options.aclProbe(file)
|
|
100
|
+
: await this.runner("powershell.exe", powershellArgs(`$acl = Get-Acl -LiteralPath ([Console]::In.ReadToEnd()); ` +
|
|
101
|
+
`$sid = [System.Security.Principal.SecurityIdentifier]; ` +
|
|
102
|
+
`@{ owner = $acl.GetOwner($sid).Value; access = @($acl.Access | ForEach-Object { ` +
|
|
103
|
+
`@{ identity = $_.IdentityReference.Translate($sid).Value; type = $_.AccessControlType.ToString() } }) } | ConvertTo-Json -Depth 4 -Compress`), file);
|
|
104
|
+
const acl = JSON.parse(text);
|
|
105
|
+
const allowed = [acl.owner, "S-1-5-18", "S-1-5-32-544"];
|
|
106
|
+
const broad = ["S-1-1-0", "S-1-5-32-545", "S-1-5-11"];
|
|
107
|
+
if (!acl.owner || !Array.isArray(acl.access) || acl.access.length === 0 ||
|
|
108
|
+
acl.access.some((ace) => !["Allow", "Deny"].includes(ace.type) ||
|
|
109
|
+
(ace.type === "Allow" && (broad.includes(ace.identity) || !allowed.includes(ace.identity))))) {
|
|
110
|
+
throw new Error(`OAuth cache must be private: ${file}`);
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
await this.changeMode(file, directory ? 0o700 : 0o600);
|
|
115
|
+
const info = await this.fileStat(file);
|
|
116
|
+
if ((info.mode & 0o077) !== 0 || (directory ? !info.isDirectory() : !info.isFile())) {
|
|
117
|
+
throw new Error(`OAuth cache must be private: ${file}`);
|
|
118
|
+
}
|
|
119
|
+
if (typeof process.getuid === "function" && info.uid !== process.getuid()) {
|
|
120
|
+
throw new Error(`OAuth cache must be private: ${file}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async prepareDirectory() {
|
|
124
|
+
await mkdir(this.dir, { recursive: true, mode: 0o700 });
|
|
125
|
+
await this.ensurePrivate(this.dir, true);
|
|
126
|
+
}
|
|
127
|
+
async removeFile(key) {
|
|
128
|
+
try {
|
|
129
|
+
await unlink(this.file(key));
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
if (error.code !== "ENOENT")
|
|
134
|
+
throw error;
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async markVault(key) {
|
|
139
|
+
// Remove legacy plaintext even if this directory cannot hold a private marker.
|
|
140
|
+
await this.removeFile(key);
|
|
141
|
+
try {
|
|
142
|
+
await this.prepareDirectory();
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return; // The vault save succeeded; targeted logout can still delete by hash.
|
|
146
|
+
}
|
|
147
|
+
await writeFile(this.file(key), '{"storage":"keychain"}', { mode: 0o600 });
|
|
148
|
+
await this.ensurePrivate(this.file(key), false);
|
|
149
|
+
}
|
|
150
|
+
async migrate(key, record) {
|
|
151
|
+
try {
|
|
152
|
+
if ((await this.vault("write", key, JSON.stringify(record))).available)
|
|
153
|
+
await this.markVault(key);
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
// A failed vault migration must not prevent use of the private legacy cache.
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
async read(endpoint, { migrate = true } = {}) {
|
|
160
|
+
const key = account(endpoint);
|
|
161
|
+
const stored = await this.vault("read", key);
|
|
162
|
+
if (stored.payload) {
|
|
163
|
+
let record;
|
|
164
|
+
try {
|
|
165
|
+
record = parseRecord(stored.payload);
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
return {};
|
|
169
|
+
}
|
|
170
|
+
if (migrate)
|
|
171
|
+
await this.markVault(key);
|
|
172
|
+
return record;
|
|
173
|
+
}
|
|
174
|
+
let record;
|
|
175
|
+
try {
|
|
176
|
+
await this.ensurePrivate(this.dir, true);
|
|
177
|
+
await this.ensurePrivate(this.file(key), false);
|
|
178
|
+
record = parseRecord(await readFile(this.file(key), "utf8"));
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
return {};
|
|
182
|
+
}
|
|
183
|
+
if (migrate && stored.available && (record.tokens || record.clientInformation))
|
|
184
|
+
await this.migrate(key, record);
|
|
185
|
+
return record;
|
|
186
|
+
}
|
|
187
|
+
async write(endpoint, record) {
|
|
188
|
+
const key = account(endpoint);
|
|
189
|
+
const payload = JSON.stringify(record);
|
|
190
|
+
if ((await this.vault("write", key, payload)).available) {
|
|
191
|
+
await this.markVault(key);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
await this.prepareDirectory();
|
|
195
|
+
try {
|
|
196
|
+
await this.fileStat(this.file(key));
|
|
197
|
+
await this.ensurePrivate(this.file(key), false);
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
if (error.code !== "ENOENT")
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
await writeFile(this.file(key), payload, { mode: 0o600 });
|
|
204
|
+
try {
|
|
205
|
+
await this.ensurePrivate(this.file(key), false);
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
await this.removeFile(key);
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async deleteAccount(key) {
|
|
213
|
+
let removed = false;
|
|
214
|
+
try {
|
|
215
|
+
removed = (await this.vault("delete", key)).removed === true;
|
|
216
|
+
}
|
|
217
|
+
finally {
|
|
218
|
+
removed = await this.removeFile(key) || removed;
|
|
219
|
+
}
|
|
220
|
+
return removed;
|
|
221
|
+
}
|
|
222
|
+
async delete(endpoint) {
|
|
223
|
+
return this.deleteAccount(account(endpoint));
|
|
224
|
+
}
|
|
225
|
+
async deleteAll() {
|
|
226
|
+
let entries;
|
|
227
|
+
try {
|
|
228
|
+
entries = await readdir(this.dir);
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
if (error.code === "ENOENT")
|
|
232
|
+
return false;
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
const removed = await Promise.all(entries.filter((entry) => /^[a-f0-9]{16}\.json$/.test(entry))
|
|
236
|
+
.map((entry) => this.deleteAccount(entry.slice(0, 16))));
|
|
237
|
+
return removed.some(Boolean);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export { isBlockedAddress } from "./net-guard.js";
|
|
2
|
+
/**
|
|
3
|
+
* Fetches a brand domain's published catalog for verification.
|
|
4
|
+
*
|
|
5
|
+
* The fetch target is attacker-influenceable (the contract types
|
|
6
|
+
* `osd:brandDomain` as a bare string), so this module is deliberately hardened:
|
|
7
|
+
* strict hostname validation, a private/reserved
|
|
8
|
+
* address blocklist at connection time, https-only URL construction, no
|
|
9
|
+
* redirect following, a shared time budget, and a body size cap.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Catalog path per contract version. Unknown versions fail closed.
|
|
13
|
+
*
|
|
14
|
+
* 0.1.0 targets the app route `/api/mcp/ai-catalog.json`: the endorsed
|
|
15
|
+
* `/.well-known/` surface is deferred pending the platform hosting decision
|
|
16
|
+
* (a tracked issue), so the app route is the interim endorsement location.
|
|
17
|
+
* OSD 0.3.0 fetches `/.well-known/ard.json`, now routed by the public
|
|
18
|
+
* edge.
|
|
19
|
+
*/
|
|
20
|
+
export declare const CATALOG_PATH_BY_CONTRACT_VERSION: Record<string, string>;
|
|
21
|
+
export declare const MAX_CATALOG_BYTES: number;
|
|
22
|
+
export declare const FETCH_BUDGET_MS = 8000;
|
|
23
|
+
export type LookupFn = (hostname: string, options: {
|
|
24
|
+
all: true;
|
|
25
|
+
}) => Promise<{
|
|
26
|
+
address: string;
|
|
27
|
+
family: number;
|
|
28
|
+
}[]>;
|
|
29
|
+
export interface FetchBrandCatalogOptions {
|
|
30
|
+
/** Test seam: DNS resolution cannot be stubbed via vi.stubGlobal. */
|
|
31
|
+
lookup?: LookupFn;
|
|
32
|
+
}
|
|
33
|
+
export type BrandCatalogOutcome = {
|
|
34
|
+
kind: "ok";
|
|
35
|
+
body: string;
|
|
36
|
+
catalogUrl: string;
|
|
37
|
+
} | {
|
|
38
|
+
kind: "invalidBrandDomain";
|
|
39
|
+
message: string;
|
|
40
|
+
} | {
|
|
41
|
+
kind: "unsupportedContractVersion";
|
|
42
|
+
contractVersion: string;
|
|
43
|
+
} | {
|
|
44
|
+
kind: "unreachable";
|
|
45
|
+
message: string;
|
|
46
|
+
catalogUrl?: string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Normalizes a brandDomain to a bare lowercase hostname, or null if it is
|
|
50
|
+
* anything else (IP literal in any radix, userinfo, port, path, unicode,
|
|
51
|
+
* single label, over-length, bad label characters).
|
|
52
|
+
*
|
|
53
|
+
* The URL normalization diff is the load-bearing check: the WHATWG parser
|
|
54
|
+
* canonicalizes every IP-literal form (decimal/hex/octal, short quads), so
|
|
55
|
+
* anything that parses to a different hostname than the input was not a bare
|
|
56
|
+
* hostname.
|
|
57
|
+
*/
|
|
58
|
+
export declare function normalizeBrandDomain(input: unknown): string | null;
|
|
59
|
+
/**
|
|
60
|
+
* Fetches `https://<brandDomain>/<path>` and returns the raw body.
|
|
61
|
+
* Never throws: every failure mode is a classified outcome. Never follows
|
|
62
|
+
* redirects; any 3xx is unreachable (fail-closed until redirect policy is
|
|
63
|
+
* decided).
|
|
64
|
+
*/
|
|
65
|
+
export declare function fetchBrandCatalog(brandDomain: unknown, contractVersion: string, options?: FetchBrandCatalogOptions): Promise<BrandCatalogOutcome>;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { lookup as dnsLookup } from "node:dns/promises";
|
|
2
|
+
import { createGuardedFetch, describeFetchFailure } from "./guarded-fetch.js";
|
|
3
|
+
// Re-exported: the SSRF blocklist now lives in net-guard.ts (ipaddr.js-backed),
|
|
4
|
+
// shared by brand catalogs, endpoint resolution, and the MCP transport.
|
|
5
|
+
export { isBlockedAddress } from "./net-guard.js";
|
|
6
|
+
/**
|
|
7
|
+
* Fetches a brand domain's published catalog for verification.
|
|
8
|
+
*
|
|
9
|
+
* The fetch target is attacker-influenceable (the contract types
|
|
10
|
+
* `osd:brandDomain` as a bare string), so this module is deliberately hardened:
|
|
11
|
+
* strict hostname validation, a private/reserved
|
|
12
|
+
* address blocklist at connection time, https-only URL construction, no
|
|
13
|
+
* redirect following, a shared time budget, and a body size cap.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Catalog path per contract version. Unknown versions fail closed.
|
|
17
|
+
*
|
|
18
|
+
* 0.1.0 targets the app route `/api/mcp/ai-catalog.json`: the endorsed
|
|
19
|
+
* `/.well-known/` surface is deferred pending the platform hosting decision
|
|
20
|
+
* (a tracked issue), so the app route is the interim endorsement location.
|
|
21
|
+
* OSD 0.3.0 fetches `/.well-known/ard.json`, now routed by the public
|
|
22
|
+
* edge.
|
|
23
|
+
*/
|
|
24
|
+
export const CATALOG_PATH_BY_CONTRACT_VERSION = {
|
|
25
|
+
"0.1.0": "api/mcp/ai-catalog.json",
|
|
26
|
+
"0.3.0": ".well-known/ard.json",
|
|
27
|
+
};
|
|
28
|
+
export const MAX_CATALOG_BYTES = 1024 * 1024;
|
|
29
|
+
export const FETCH_BUDGET_MS = 8000;
|
|
30
|
+
const RFC1123_LABEL = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
31
|
+
/**
|
|
32
|
+
* Normalizes a brandDomain to a bare lowercase hostname, or null if it is
|
|
33
|
+
* anything else (IP literal in any radix, userinfo, port, path, unicode,
|
|
34
|
+
* single label, over-length, bad label characters).
|
|
35
|
+
*
|
|
36
|
+
* The URL normalization diff is the load-bearing check: the WHATWG parser
|
|
37
|
+
* canonicalizes every IP-literal form (decimal/hex/octal, short quads), so
|
|
38
|
+
* anything that parses to a different hostname than the input was not a bare
|
|
39
|
+
* hostname.
|
|
40
|
+
*/
|
|
41
|
+
export function normalizeBrandDomain(input) {
|
|
42
|
+
if (typeof input !== "string")
|
|
43
|
+
return null;
|
|
44
|
+
if (!/^[\x21-\x7e]+$/.test(input))
|
|
45
|
+
return null; // printable ASCII only
|
|
46
|
+
let host = input.endsWith(".") ? input.slice(0, -1) : input; // strip at most one trailing dot
|
|
47
|
+
host = host.toLowerCase();
|
|
48
|
+
if (host.length === 0 || host.length > 253)
|
|
49
|
+
return null;
|
|
50
|
+
let parsed;
|
|
51
|
+
try {
|
|
52
|
+
parsed = new URL(`https://${host}`);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
if (parsed.hostname !== host)
|
|
58
|
+
return null;
|
|
59
|
+
const labels = host.split(".");
|
|
60
|
+
if (labels.length < 2)
|
|
61
|
+
return null; // a brand domain is a real FQDN
|
|
62
|
+
if (!labels.every((label) => RFC1123_LABEL.test(label)))
|
|
63
|
+
return null;
|
|
64
|
+
if (/^\d+$/.test(labels[labels.length - 1]))
|
|
65
|
+
return null; // all-numeric TLD (dotted-quad-ish forms)
|
|
66
|
+
return host;
|
|
67
|
+
}
|
|
68
|
+
function unreachable(message, catalogUrl) {
|
|
69
|
+
return catalogUrl === undefined
|
|
70
|
+
? { kind: "unreachable", message }
|
|
71
|
+
: { kind: "unreachable", message, catalogUrl };
|
|
72
|
+
}
|
|
73
|
+
function errorMessage(cause) {
|
|
74
|
+
return cause instanceof Error ? cause.message : String(cause);
|
|
75
|
+
}
|
|
76
|
+
/** Rejects with a timeout error after `ms`; the underlying promise is left dangling (unref'd). */
|
|
77
|
+
function raceWithDeadline(promise, ms, what) {
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
79
|
+
if (ms <= 0) {
|
|
80
|
+
reject(new Error(`${what} timed out`));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const timer = setTimeout(() => reject(new Error(`${what} timed out after ${ms}ms`)), ms);
|
|
84
|
+
timer.unref?.();
|
|
85
|
+
promise.then((value) => {
|
|
86
|
+
clearTimeout(timer);
|
|
87
|
+
resolve(value);
|
|
88
|
+
}, (error) => {
|
|
89
|
+
clearTimeout(timer);
|
|
90
|
+
reject(error);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Fetches `https://<brandDomain>/<path>` and returns the raw body.
|
|
96
|
+
* Never throws: every failure mode is a classified outcome. Never follows
|
|
97
|
+
* redirects; any 3xx is unreachable (fail-closed until redirect policy is
|
|
98
|
+
* decided).
|
|
99
|
+
*/
|
|
100
|
+
export async function fetchBrandCatalog(brandDomain, contractVersion, options = {}) {
|
|
101
|
+
const path = CATALOG_PATH_BY_CONTRACT_VERSION[contractVersion];
|
|
102
|
+
if (path === undefined) {
|
|
103
|
+
return { kind: "unsupportedContractVersion", contractVersion };
|
|
104
|
+
}
|
|
105
|
+
const host = normalizeBrandDomain(brandDomain);
|
|
106
|
+
if (host === null) {
|
|
107
|
+
return {
|
|
108
|
+
kind: "invalidBrandDomain",
|
|
109
|
+
message: `brandDomain ${JSON.stringify(brandDomain)} is not a valid DNS hostname`,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const catalogUrl = `https://${host}/${path}`;
|
|
113
|
+
const deadline = Date.now() + FETCH_BUDGET_MS;
|
|
114
|
+
const remaining = () => deadline - Date.now();
|
|
115
|
+
const lookup = options.lookup ?? ((hostname) => dnsLookup(hostname, { all: true }));
|
|
116
|
+
const guarded = createGuardedFetch(async (hostname) => {
|
|
117
|
+
const addresses = await raceWithDeadline(lookup(hostname, { all: true }), remaining(), `DNS lookup for ${hostname}`);
|
|
118
|
+
return addresses.map((entry) => entry.address);
|
|
119
|
+
});
|
|
120
|
+
try {
|
|
121
|
+
let response;
|
|
122
|
+
try {
|
|
123
|
+
response = await guarded.fetchFn(catalogUrl, {
|
|
124
|
+
redirect: "manual",
|
|
125
|
+
signal: AbortSignal.timeout(Math.max(1, remaining())),
|
|
126
|
+
headers: { accept: "application/json" },
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
catch (cause) {
|
|
130
|
+
// Distinguish a guard refusal (policy), a proxy/TLS failure, and other
|
|
131
|
+
// network errors so "couldn't verify" says WHY it couldn't.
|
|
132
|
+
return unreachable(`could not fetch ${catalogUrl}: ${describeFetchFailure(cause)}`, catalogUrl);
|
|
133
|
+
}
|
|
134
|
+
if (response.status >= 300 && response.status < 400) {
|
|
135
|
+
return unreachable(`${catalogUrl} returned a redirect (HTTP ${response.status}); redirects are not followed`, catalogUrl);
|
|
136
|
+
}
|
|
137
|
+
if (!response.ok) {
|
|
138
|
+
return unreachable(`${catalogUrl} returned HTTP ${response.status}`, catalogUrl);
|
|
139
|
+
}
|
|
140
|
+
const contentType = (response.headers.get("content-type") ?? "").split(";")[0].trim().toLowerCase();
|
|
141
|
+
if (contentType !== "application/json") {
|
|
142
|
+
return unreachable(`${catalogUrl} returned a non-JSON content-type (${contentType || "none"})`, catalogUrl);
|
|
143
|
+
}
|
|
144
|
+
if (response.body === null) {
|
|
145
|
+
return unreachable(`${catalogUrl} returned no body`, catalogUrl);
|
|
146
|
+
}
|
|
147
|
+
const reader = response.body.getReader();
|
|
148
|
+
const chunks = [];
|
|
149
|
+
let total = 0;
|
|
150
|
+
try {
|
|
151
|
+
for (;;) {
|
|
152
|
+
if (remaining() <= 0) {
|
|
153
|
+
await reader.cancel();
|
|
154
|
+
return unreachable(`reading ${catalogUrl} timed out`, catalogUrl);
|
|
155
|
+
}
|
|
156
|
+
const { done, value } = await reader.read();
|
|
157
|
+
if (done)
|
|
158
|
+
break;
|
|
159
|
+
total += value.byteLength;
|
|
160
|
+
if (total > MAX_CATALOG_BYTES) {
|
|
161
|
+
await reader.cancel();
|
|
162
|
+
return unreachable(`${catalogUrl} exceeded the ${MAX_CATALOG_BYTES}-byte cap`, catalogUrl);
|
|
163
|
+
}
|
|
164
|
+
chunks.push(value);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch (cause) {
|
|
168
|
+
return unreachable(`could not read ${catalogUrl}: ${errorMessage(cause)}`, catalogUrl);
|
|
169
|
+
}
|
|
170
|
+
return { kind: "ok", body: Buffer.concat(chunks).toString("utf8"), catalogUrl };
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
await guarded.close().catch(() => undefined);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { LookupFn } from "./brand-catalog.js";
|
|
2
|
+
import { ExitCode } from "./exit-codes.js";
|
|
3
|
+
/**
|
|
4
|
+
* Verify-before-connect gate for `osd mcp`.
|
|
5
|
+
*
|
|
6
|
+
* The mcp command used to connect to any URL it was handed. Now, before any
|
|
7
|
+
* resolution or connection, the target must be listed in the configured OSD
|
|
8
|
+
* directory under its EXACT url (the registry-side `url` filter) and
|
|
9
|
+
* that listing must verify against the brand domain's own published catalog.
|
|
10
|
+
* This module only renders the decision; the interactive bypass prompt lives
|
|
11
|
+
* in the mcp command itself.
|
|
12
|
+
*/
|
|
13
|
+
export type GateOutcome = {
|
|
14
|
+
kind: "verified";
|
|
15
|
+
} | {
|
|
16
|
+
kind: "refused";
|
|
17
|
+
message: string;
|
|
18
|
+
exitCode: ExitCode;
|
|
19
|
+
};
|
|
20
|
+
export interface GateOptions {
|
|
21
|
+
/** Base URL of the OSD directory to look the target up in. */
|
|
22
|
+
registry: string;
|
|
23
|
+
contractVersion: string;
|
|
24
|
+
lookup?: LookupFn;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Looks the target up in the directory by exact url and verifies the single
|
|
28
|
+
* listing that claims it. Any doubt -- not listed, ambiguous, unverifiable,
|
|
29
|
+
* or a directory that cannot answer -- is a refusal.
|
|
30
|
+
*/
|
|
31
|
+
export declare function checkTargetVerified(target: string, options: GateOptions): Promise<GateOutcome>;
|