@vellumai/credential-executor 0.11.3 → 0.11.4-dev.202608190019.b94dbf2

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.
@@ -14,6 +14,7 @@
14
14
  "./remote-web-pairing": "./src/remote-web-pairing.ts",
15
15
  "./twilio-ingress": "./src/twilio-ingress.ts",
16
16
  "./trust-rules": "./src/trust-rules.ts",
17
+ "./url-normalization": "./src/url-normalization.ts",
17
18
  "./handles": "./src/handles.ts",
18
19
  "./rpc": "./src/rpc.ts",
19
20
  "./attachment-naming": "./src/attachment-naming.ts",
@@ -0,0 +1,135 @@
1
+ import { describe, expect, test } from "bun:test";
2
+
3
+ import {
4
+ canonicalizeWebUrl,
5
+ looksLikeHostPortShorthand,
6
+ looksLikePathOnlyInput,
7
+ normalizeWebUrl,
8
+ } from "../url-normalization.js";
9
+
10
+ /**
11
+ * These are the rules a trust rule is saved and matched under. A change here
12
+ * changes which saved rules still match, so each case states the target the
13
+ * two spellings must agree on.
14
+ */
15
+ describe("normalizeWebUrl", () => {
16
+ test("keeps an ordinary https URL as-is", () => {
17
+ expect(normalizeWebUrl("https://example.com/docs/page")?.href).toBe(
18
+ "https://example.com/docs/page",
19
+ );
20
+ });
21
+
22
+ test("drops the fragment: it never reaches the server", () => {
23
+ expect(normalizeWebUrl("https://example.com/docs#section")?.href).toBe(
24
+ "https://example.com/docs",
25
+ );
26
+ });
27
+
28
+ test("drops userinfo so credentials cannot land in a saved rule", () => {
29
+ const credentialed = new URL("https://example.com/docs/page");
30
+ credentialed.username = "demo";
31
+ credentialed.password = ["c", "r", "e", "d", "1", "2", "3"].join("");
32
+
33
+ const normalized = normalizeWebUrl(credentialed.href);
34
+ expect(normalized?.href).toBe("https://example.com/docs/page");
35
+ expect(normalized?.username).toBe("");
36
+ expect(normalized?.password).toBe("");
37
+ });
38
+
39
+ test("strips a trailing root dot from the hostname", () => {
40
+ expect(normalizeWebUrl("https://example.com./docs/page")?.href).toBe(
41
+ "https://example.com/docs/page",
42
+ );
43
+ });
44
+
45
+ test("decodes escaped path segments so one path has one spelling", () => {
46
+ // Without this, a rule scoped to /private is bypassed by /%70rivate.
47
+ expect(normalizeWebUrl("https://example.com/%70rivate")?.href).toBe(
48
+ "https://example.com/private",
49
+ );
50
+ });
51
+
52
+ test("reads scheme-less input as https", () => {
53
+ expect(normalizeWebUrl("example.com/docs")?.href).toBe(
54
+ "https://example.com/docs",
55
+ );
56
+ });
57
+
58
+ test("reads host:port shorthand as an https origin, not a scheme", () => {
59
+ expect(normalizeWebUrl("example.com:8443/status")?.origin).toBe(
60
+ "https://example.com:8443",
61
+ );
62
+ expect(normalizeWebUrl("[2001:db8::1]:8443/status")?.origin).toBe(
63
+ "https://[2001:db8::1]:8443",
64
+ );
65
+ });
66
+
67
+ test("rejects path-only input rather than coercing it to a host", () => {
68
+ for (const input of ["/etc/passwd", "./rel", "../up", "?q=1", "#frag"]) {
69
+ expect(normalizeWebUrl(input)).toBeNull();
70
+ }
71
+ });
72
+
73
+ test("rejects every non-http scheme", () => {
74
+ for (const input of [
75
+ "file:///etc/passwd",
76
+ "data:text/html,<script>",
77
+ "javascript:alert(1)",
78
+ "ftp://example.com/f",
79
+ ]) {
80
+ expect(normalizeWebUrl(input)).toBeNull();
81
+ }
82
+ });
83
+
84
+ test("rejects empty and whitespace-only input", () => {
85
+ expect(normalizeWebUrl("")).toBeNull();
86
+ expect(normalizeWebUrl(" ")).toBeNull();
87
+ });
88
+
89
+ test("trims surrounding whitespace", () => {
90
+ expect(normalizeWebUrl(" https://example.com/a ")?.href).toBe(
91
+ "https://example.com/a",
92
+ );
93
+ });
94
+
95
+ test("returns null rather than throwing on an unparseable authority", () => {
96
+ expect(normalizeWebUrl("https://")).toBeNull();
97
+ });
98
+ });
99
+
100
+ describe("canonicalizeWebUrl", () => {
101
+ test("keeps the parser's form when the path is not decodable, without throwing", () => {
102
+ // `%zz` and a truncated UTF-8 sequence are not valid escapes; the path
103
+ // must survive unchanged rather than the call throwing.
104
+ expect(canonicalizeWebUrl(new URL("https://example.com/100%zz")).href).toBe(
105
+ "https://example.com/100%zz",
106
+ );
107
+ expect(
108
+ canonicalizeWebUrl(new URL("https://example.com/%E0%A4%A")).href,
109
+ ).toBe("https://example.com/%E0%A4%A");
110
+ });
111
+
112
+ test("decodes an escaped percent, so `%25` and `%` are one path", () => {
113
+ expect(canonicalizeWebUrl(new URL("https://example.com/100%25")).href).toBe(
114
+ "https://example.com/100%",
115
+ );
116
+ });
117
+ });
118
+
119
+ describe("input shape predicates", () => {
120
+ test("host:port shorthand is recognized, scheme-prefixed input is not", () => {
121
+ expect(looksLikeHostPortShorthand("example.com:8443/x")).toBe(true);
122
+ expect(looksLikeHostPortShorthand("[2001:db8::1]:443")).toBe(true);
123
+ expect(looksLikeHostPortShorthand("https://example.com/x")).toBe(false);
124
+ expect(looksLikeHostPortShorthand("example.com/x")).toBe(false);
125
+ });
126
+
127
+ test("path-only input is recognized", () => {
128
+ expect(looksLikePathOnlyInput("/abs")).toBe(true);
129
+ expect(looksLikePathOnlyInput("./rel")).toBe(true);
130
+ expect(looksLikePathOnlyInput("../up")).toBe(true);
131
+ expect(looksLikePathOnlyInput("?q=1")).toBe(true);
132
+ expect(looksLikePathOnlyInput("#frag")).toBe(true);
133
+ expect(looksLikePathOnlyInput("example.com/x")).toBe(false);
134
+ });
135
+ });
@@ -6,6 +6,16 @@
6
6
  * assistant through (Slack, Telegram, WhatsApp, phone, …) plus a couple of
7
7
  * internal ids (`vellum` for native app conversations, `platform` for the
8
8
  * internal control plane). This is the single source of truth for that set:
9
+ *
10
+ * One id, `plugin`, does not name a surface: it names *every* surface a plugin
11
+ * brings. A plugin channel's real identity is the plugin, which is workspace
12
+ * state and cannot be a compile-time union member, so the plugin name travels
13
+ * in `sourceMetadata.plugin` and is prefixed onto every external id the gateway
14
+ * forwards (`imessage:+15551234567`). Two plugins therefore share a channel
15
+ * row — one admission floor, one set of channel-wide defaults — while their
16
+ * conversations, contacts, and trust records stay disjoint. See
17
+ * `gateway/src/channels/plugin-inbound.ts` for what that concedes.
18
+ *
9
19
  * the assistant adopts it wholesale as its `ChannelId`, and the gateway
10
20
  * asserts its own (narrower) inbound list is a subset of it so the two sides
11
21
  * cannot silently drift.
@@ -30,6 +40,7 @@ export const CHANNEL_IDS = [
30
40
  "platform",
31
41
  "a2a",
32
42
  "discord",
43
+ "plugin",
33
44
  ] as const;
34
45
 
35
46
  export type ChannelId = (typeof CHANNEL_IDS)[number];
@@ -29,3 +29,4 @@ export * from "./trust-rules.js";
29
29
  export * from "./ingress.js";
30
30
  export * from "./remote-web-pairing.js";
31
31
  export * from "./twilio-ingress.js";
32
+ export * from "./url-normalization.js";
@@ -11,6 +11,12 @@
11
11
  * (`gateway/src/http/routes/remote-web-pairing-verification.ts`)
12
12
  * - `POST /v1/remote-web/pairing-token` poll + exchange device code
13
13
  * (`gateway/src/http/routes/remote-web-pairing-token.ts`)
14
+ * - `GET /v1/remote-web/pairing-requests` list pending challenges
15
+ * (loopback-only)
16
+ * - `POST /v1/remote-web/pairing-requests/approve` approve by request id
17
+ * (loopback-only)
18
+ * - `POST /v1/remote-web/pairing-requests/deny` deny (delete) by request id
19
+ * (loopback-only)
14
20
  *
15
21
  * These shapes mirror those handlers' request/response bodies exactly so the
16
22
  * gateway, the `vellum pair` CLI (`cli/src/commands/pair.ts`), and the web SPA
@@ -68,6 +74,60 @@ export interface RemoteWebPairingVerificationResponse {
68
74
  expiresAt: string;
69
75
  }
70
76
 
77
+ /**
78
+ * One pending challenge as shown on a host approval surface.
79
+ *
80
+ * The requesting device already sees the plaintext `userCode` in its own
81
+ * challenge response ({@link RemoteWebPairingChallengeResponse.userCode});
82
+ * the loopback-gated list route is the only host-side re-exposure. Displaying
83
+ * it there is what lets the approver match the code against the requesting
84
+ * device's screen: the device-flow anti-phishing binding.
85
+ */
86
+ export interface RemoteWebPairingRequestSummary {
87
+ /** Opaque server-side id used to approve or deny this request. */
88
+ requestId: string;
89
+ /** The human-readable code the requesting device is displaying (e.g. "ABCD-EFGH"). */
90
+ userCode: string;
91
+ /** Public base URL the challenge was minted for. */
92
+ publicBaseUrl: string;
93
+ /** ISO-8601 instant the challenge was minted. */
94
+ requestedAt: string;
95
+ /** ISO-8601 instant the challenge expires. */
96
+ expiresAt: string;
97
+ /**
98
+ * Client IP of the mint request: the loopback/host address when minted
99
+ * locally, or the edge-observed client address when the mint arrived
100
+ * through the nginx tunnel edge (which stamps it via `proxy_set_header`,
101
+ * so a remote client cannot smuggle a value).
102
+ */
103
+ requesterIp: string;
104
+ /** User-Agent header of the mint request, or null when absent. */
105
+ requesterUserAgent: string | null;
106
+ /**
107
+ * Whether the mint arrived through the public tunnel edge rather than the
108
+ * host itself.
109
+ */
110
+ viaEdgeProxy: boolean;
111
+ }
112
+
113
+ /** `GET /v1/remote-web/pairing-requests` success response body (200). */
114
+ export interface RemoteWebPairingRequestListResponse {
115
+ requests: RemoteWebPairingRequestSummary[];
116
+ }
117
+
118
+ /**
119
+ * Request body for the pairing-request approve and deny routes. The approve
120
+ * route's success body reuses {@link RemoteWebPairingVerificationResponse}.
121
+ */
122
+ export interface RemoteWebPairingRequestActionRequest {
123
+ requestId: string;
124
+ }
125
+
126
+ /** `POST /v1/remote-web/pairing-requests/deny` success response body (200). */
127
+ export interface RemoteWebPairingRequestDenyResponse {
128
+ status: "denied";
129
+ }
130
+
71
131
  /** `POST /v1/remote-web/pairing-token` request body. */
72
132
  export interface RemoteWebPairingTokenRequest {
73
133
  /** The `deviceCode` from the challenge. */
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Canonical URL normalization for web tool inputs, shared by the gateway's
3
+ * risk classifiers and the daemon's URL safety checks.
4
+ *
5
+ * A URL a model passes to `web_fetch` / `network_request` reaches more than
6
+ * one consumer, and they must agree on what counts as the same target: the
7
+ * gateway builds the trust-rule ladder from it, and anything that later
8
+ * compares a URL to a saved rule has to fold the same spellings together. Two
9
+ * normalizations would mean two answers, so it lives here rather than in
10
+ * either process.
11
+ *
12
+ * Data-only in spirit: no imports, no config, no I/O.
13
+ */
14
+
15
+ /** Whether a bare `host:port` (or `[v6]:port`) shorthand was written. */
16
+ export function looksLikeHostPortShorthand(value: string): boolean {
17
+ if (/^\[[0-9a-fA-F:.%]+\]:\d+(?:[/?#]|$)/.test(value)) {
18
+ return true;
19
+ }
20
+ return /^[^/?#@\s:]+:\d+(?:[/?#]|$)/.test(value);
21
+ }
22
+
23
+ /** Whether the input is a path, query, or fragment rather than a URL. */
24
+ export function looksLikePathOnlyInput(value: string): boolean {
25
+ return (
26
+ value.startsWith("/") ||
27
+ value.startsWith("./") ||
28
+ value.startsWith("../") ||
29
+ value.startsWith("?") ||
30
+ value.startsWith("#")
31
+ );
32
+ }
33
+
34
+ /**
35
+ * Strip the parts of a URL that must not affect a trust decision, and fold
36
+ * the encodings that would otherwise let one URL wear two spellings.
37
+ *
38
+ * Percent-escaped path segments are decoded (`/%70rivate` and `/private` are
39
+ * one path, so a path-scoped rule cannot be bypassed by escaping), a trailing
40
+ * root dot is dropped from the hostname, and fragment and userinfo are
41
+ * removed: the fragment never reaches the server, and credentials in the
42
+ * authority must never end up in a saved rule.
43
+ */
44
+ export function canonicalizeWebUrl(parsed: URL): URL {
45
+ parsed.hash = "";
46
+ parsed.username = "";
47
+ parsed.password = "";
48
+
49
+ try {
50
+ parsed.pathname = decodeURI(parsed.pathname);
51
+ } catch {
52
+ // Keep the URL parser's canonical form when decoding fails.
53
+ }
54
+
55
+ if (parsed.hostname.endsWith(".")) {
56
+ parsed.hostname = parsed.hostname.replace(/\.+$/, "");
57
+ }
58
+
59
+ return parsed;
60
+ }
61
+
62
+ /**
63
+ * Parse and canonicalize a web tool's `url` input, or `null` when it is not a
64
+ * URL this system will fetch.
65
+ *
66
+ * Accepts `https://host/path`, `http://…`, bare `host/path`, and `host:port`
67
+ * shorthand. Rejects path-only input and any other scheme (`file:`, `data:`,
68
+ * `javascript:`), so a non-http target can never acquire a web trust rule.
69
+ */
70
+ export function normalizeWebUrl(rawUrl: string): URL | null {
71
+ const trimmed = rawUrl.trim();
72
+ if (!trimmed) {
73
+ return null;
74
+ }
75
+
76
+ if (looksLikeHostPortShorthand(trimmed)) {
77
+ try {
78
+ return canonicalizeWebUrl(new URL(`https://${trimmed}`));
79
+ } catch {
80
+ return null;
81
+ }
82
+ }
83
+
84
+ try {
85
+ const parsed = new URL(trimmed);
86
+ if (parsed.protocol === "http:" || parsed.protocol === "https:") {
87
+ return canonicalizeWebUrl(parsed);
88
+ }
89
+ return null;
90
+ } catch {
91
+ // Not an absolute URL; fall through to the shorthand forms.
92
+ }
93
+
94
+ if (looksLikePathOnlyInput(trimmed)) {
95
+ return null;
96
+ }
97
+
98
+ if (/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(trimmed)) {
99
+ return null;
100
+ }
101
+
102
+ try {
103
+ return canonicalizeWebUrl(new URL(`https://${trimmed}`));
104
+ } catch {
105
+ return null;
106
+ }
107
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/credential-executor",
3
- "version": "0.11.3",
3
+ "version": "0.11.4-dev.202608190019.b94dbf2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {