Skip to content

Commit 337c7d5

Browse files
committed
wip(spec): an authored connector URL holds no credential part; nested connector shapes close on the authored entry
Claude-Session: https://claude.ai/code/session_01Q4EjjP1K353tLKWRMajLsE Co-authored-by: Claude <noreply@anthropic.com>
1 parent aca58cd commit 337c7d5

3 files changed

Lines changed: 273 additions & 69 deletions

File tree

‎packages/spec/src/integration/connector-credential-redaction.ts‎

Lines changed: 33 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
* one came from outside them, and what it holds cannot be judged key by
4747
* key: an `auth: '<token>'` is the secret itself. Withheld whole, fail
4848
* closed, rather than served as stored.
49-
* 5. **The credential parts of every URL under `providerConfig`** — rewritten,
50-
* not removed: the userinfo (`https://user:pass@host`, and the
49+
* 5. **The credential parts of every URL under `providerConfig` and
50+
* `auth`** — rewritten, not removed: the userinfo (`https://user:pass@host`, and the
5151
* `https://<token>@host` form several HTTP APIs read as a token, so the
5252
* user part goes too) and each credential query parameter
5353
* ({@link CONNECTOR_CREDENTIAL_URL_QUERY_PARAM_NAMES}, plus the
@@ -58,8 +58,13 @@
5858
* It covers `providerConfig.baseUrl` (`rest`, `openapi`),
5959
* `providerConfig.transport.url` (`mcp` over http) and a URL
6060
* `providerConfig.spec` (`openapi`), and any other URL a provider keeps at
61-
* an OBJECT depth of `providerConfig`: a string is judged when it starts
62-
* with `scheme://`.
61+
* an OBJECT depth of `providerConfig`; and the endpoints an instance-auth
62+
* kind declares (`auth.tokenUrl`, `auth.authorizationUrl`, `auth.resource`)
63+
* and any URL a kind declares later. A string is judged when it starts
64+
* with `scheme://`. What a credential part is lives in ONE place,
65+
* `./connector-url-credentials.ts`, which the write door's refinement
66+
* judges by too: an authored URL holding one is refused, so only a row
67+
* stored before that refusal can carry one to this read.
6368
* 6. **An array under `providerConfig` that holds such a URL, WHOLE**, and
6469
* **a key under `providerConfig` whose own name carries a dot that holds
6570
* such a URL at any depth, WHOLE.** The carry-forward cannot address an
@@ -123,8 +128,14 @@
123128
import { ConnectorInstanceAuthSchema } from '../shared/connector-auth.zod';
124129
import { ConnectorActionSchema, DeclarativeConnectorEntrySchema, RetryConfigSchema } from './connector.zod';
125130
import { METADATA_READ_DECORATIONS } from '../kernel/metadata-read-decorations';
126-
import { CREDENTIAL_URL_QUERY_PARAM_NAMES } from '../data/driver/common.zod';
127131
import { redactUrlCredentialQueryParams } from '../data/datasource-credential-redaction';
132+
import {
133+
CONNECTOR_CREDENTIAL_URL_QUERY_PARAM_NAMES,
134+
CONNECTOR_URL_ROOTS,
135+
URL_USERINFO_RE,
136+
connectorCredentialQueryParamsOf,
137+
connectorUrlCredentialPartsOf,
138+
} from './connector-url-credentials';
128139
import { objectShapeOf, wrapperChainOf, zodDefOf } from '../kernel/metadata-credential-fields';
129140
import type { MetadataRedactionResult } from '../kernel/metadata-type-redaction';
130141

@@ -138,57 +149,19 @@ export const CONNECTOR_CREDENTIAL_MAP_PATHS: readonly (readonly string[])[] = Ob
138149

139150
/**
140151
* The query parameters whose value a connector URL is read as carrying a
141-
* credential in (see the module note, item 5): the datasource set
142-
* (`password`, `authToken`) and the names HTTP APIs conventionally take a key,
143-
* token or signature under. Matched case-insensitively on the decoded name
144-
* (`credentialQueryParamOf`). A name here that holds no secret on some API
145-
* costs that API's served URL the parameter, never its stored value: the
146-
* carry-forward keeps it on a save of the served form.
152+
* credential in (see the module note, item 5) — declared once, beside the
153+
* walk the write door shares (`./connector-url-credentials.ts`). A name here
154+
* that holds no secret on some API costs that API's served URL the parameter,
155+
* never its stored value: the carry-forward keeps it on a save of the served
156+
* form.
147157
*/
148-
export const CONNECTOR_CREDENTIAL_URL_QUERY_PARAM_NAMES: readonly string[] = Object.freeze([
149-
...CREDENTIAL_URL_QUERY_PARAM_NAMES,
150-
'access_token',
151-
'api_key',
152-
'api-key',
153-
'apikey',
154-
'auth_token',
155-
'client_secret',
156-
'id_token',
157-
'key',
158-
'passwd',
159-
'refresh_token',
160-
'secret',
161-
'sig',
162-
'signature',
163-
'token',
164-
'x-api-key',
165-
]);
166-
167-
/** `scheme://` — the strings item 5 judges. */
168-
const URL_SCHEME_RE = /^[a-z][a-z0-9+.\-]*:\/\//i;
169-
170-
/**
171-
* `scheme://userinfo@` — the whole userinfo. Every class excludes `/?#`, so the
172-
* `@` must sit in the authority; the greedy class backtracks to the LAST `@`
173-
* before the path, the userinfo boundary RFC 3986 defines (the reading
174-
* `URL_USERINFO_RE` in the datasource module documents).
175-
*/
176-
const URL_USERINFO_RE = /^([a-z][a-z0-9+.\-]*:\/\/)[^/?#]*@/i;
158+
export { CONNECTOR_CREDENTIAL_URL_QUERY_PARAM_NAMES };
177159

178160
/** One URL with its userinfo and credential query parameters removed; the input when there is none. */
179161
function redactConnectorUrl(value: string, params: readonly string[]): string {
180162
return redactUrlCredentialQueryParams(value.replace(URL_USERINFO_RE, '$1'), params);
181163
}
182164

183-
/** The query parameter names item 5 strips for `item`: the fixed set plus its own `auth.paramName`. */
184-
function credentialQueryParamsOf(item: Record<string, unknown>): readonly string[] {
185-
const auth = item.auth;
186-
const own = isPlainRecord(auth) && auth.type === 'api-key' && typeof auth.paramName === 'string' && auth.paramName !== ''
187-
? auth.paramName
188-
: undefined;
189-
return own === undefined ? CONNECTOR_CREDENTIAL_URL_QUERY_PARAM_NAMES : [...CONNECTOR_CREDENTIAL_URL_QUERY_PARAM_NAMES, own];
190-
}
191-
192165
/** One instance-auth kind as the union declares it: its literal-valued keys, and every key it declares. */
193166
interface DeclaredAuthKind {
194167
/** Each key whose schema is a literal, with the values it accepts (`type`, `grant`, `scheme`). */
@@ -394,9 +367,9 @@ function withValueAt(item: Record<string, unknown>, path: readonly string[], val
394367
return { ...item, [head]: withValueAt(item[head] as Record<string, unknown>, rest, value) };
395368
}
396369

397-
/** Whether `value` is a URL whose credential parts {@link redactConnectorUrl} removes. */
370+
/** Whether `value` is a URL holding a credential part — the parts {@link redactConnectorUrl} removes. */
398371
function isCredentialUrl(value: string, params: readonly string[]): boolean {
399-
return URL_SCHEME_RE.test(value) && redactConnectorUrl(value, params) !== value;
372+
return connectorUrlCredentialPartsOf(value, params) !== undefined;
400373
}
401374

402375
/** Whether `value` holds, at any depth, a URL {@link isCredentialUrl} judges (item 6). */
@@ -408,18 +381,16 @@ function holdsCredentialUrl(value: unknown, params: readonly string[]): boolean
408381
}
409382

410383
/**
411-
* Items 5 and 6: every URL under `providerConfig`, at object depth, whose
412-
* credential parts {@link redactConnectorUrl} removes — the path and the
413-
* rewritten value — and every array there holding such a URL, withheld whole
414-
* (`value` absent).
384+
* Items 5 and 6: every URL under `providerConfig` and `auth`
385+
* ({@link CONNECTOR_URL_ROOTS}), at object depth, whose credential parts
386+
* {@link redactConnectorUrl} removes — the path and the rewritten value — and
387+
* every array there holding such a URL, withheld whole (`value` absent).
415388
*/
416389
function credentialUrlRewritesOf(
417390
item: Record<string, unknown>,
418391
): Array<{ path: string[]; value?: string }> {
419392
const rewrites: Array<{ path: string[]; value?: string }> = [];
420-
const providerConfig = item.providerConfig;
421-
if (!isPlainRecord(providerConfig)) return rewrites;
422-
const params = credentialQueryParamsOf(item);
393+
const params = connectorCredentialQueryParamsOf(item);
423394
const walk = (node: Record<string, unknown>, prefix: readonly string[]): void => {
424395
for (const [key, value] of Object.entries(node)) {
425396
const path = [...prefix, key];
@@ -443,7 +414,10 @@ function credentialUrlRewritesOf(
443414
}
444415
}
445416
};
446-
walk(providerConfig, ['providerConfig']);
417+
for (const root of CONNECTOR_URL_ROOTS) {
418+
const node = item[root];
419+
if (isPlainRecord(node)) walk(node, [root]);
420+
}
447421
return rewrites;
448422
}
449423

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The credential parts of a URL a connector entry keeps — the ONE definition
5+
* both connector doors judge by. Internal: imported by the write door's
6+
* refinement (`DeclarativeConnectorEntrySchema` in `./connector.zod.ts`) and by
7+
* the read redactor (`./connector-credential-redaction.ts`), never exported on
8+
* its own.
9+
*
10+
* ## The URLs judged
11+
*
12+
* Every string that starts with `scheme://` under the two places an entry
13+
* keeps a URL ({@link CONNECTOR_URL_ROOTS}):
14+
*
15+
* - `providerConfig` — the provider's own vocabulary: `baseUrl` (`rest`,
16+
* `openapi`), `transport.url` (`mcp` over http), a URL `spec` (`openapi`),
17+
* and any other URL a provider keeps there;
18+
* - `auth` — the endpoints an instance-auth kind declares: `tokenUrl`,
19+
* `authorizationUrl` and `resource` (`oauth2`), and any URL a kind declares
20+
* later.
21+
*
22+
* No list of provider keys: a URL is recognised by its value, so a provider
23+
* that keeps a URL under a new key is judged with nothing to edit here.
24+
*
25+
* ## The credential parts
26+
*
27+
* - **the userinfo**, whole: `https://user:pass@host`, and `https://<token>@host`,
28+
* the form several HTTP APIs read as a token;
29+
* - **each credential query parameter** with a non-empty value: the names in
30+
* {@link CONNECTOR_CREDENTIAL_URL_QUERY_PARAM_NAMES}, plus the
31+
* `auth.paramName` an `api-key` instance itself names. A pair is judged by
32+
* `credentialQueryParamOf` (`data/driver/common.zod.ts`), the boundary
33+
* definition the datasource doors share: the query runs from the first `?`
34+
* to the fragment, names match case-insensitively on the percent-decoded
35+
* key, and an empty value carries nothing.
36+
*
37+
* The write door refuses a URL holding either part; the read redactor removes
38+
* exactly these parts from a stored one. One definition, so the two cannot
39+
* disagree about what a credential in a URL is.
40+
*/
41+
42+
import { CREDENTIAL_URL_QUERY_PARAM_NAMES, urlCredentialQueryParams } from '../data/driver/common.zod';
43+
44+
/** The entry keys under which a connector keeps URLs (see the module note). */
45+
export const CONNECTOR_URL_ROOTS: readonly string[] = Object.freeze(['providerConfig', 'auth']);
46+
47+
/**
48+
* The query parameters whose value a connector URL is read as carrying a
49+
* credential in: the datasource set (`password`, `authToken`) and the names
50+
* HTTP APIs conventionally take a key, token or signature under. Matched
51+
* case-insensitively on the decoded name (`credentialQueryParamOf`).
52+
*/
53+
export const CONNECTOR_CREDENTIAL_URL_QUERY_PARAM_NAMES: readonly string[] = Object.freeze([
54+
...CREDENTIAL_URL_QUERY_PARAM_NAMES,
55+
'access_token',
56+
'api_key',
57+
'api-key',
58+
'apikey',
59+
'auth_token',
60+
'client_secret',
61+
'id_token',
62+
'key',
63+
'passwd',
64+
'refresh_token',
65+
'secret',
66+
'sig',
67+
'signature',
68+
'token',
69+
'x-api-key',
70+
]);
71+
72+
/** `scheme://` — the strings judged as URLs. */
73+
export const URL_SCHEME_RE = /^[a-z][a-z0-9+.\-]*:\/\//i;
74+
75+
/**
76+
* `scheme://userinfo@` — the whole userinfo. Every class excludes `/?#`, so the
77+
* `@` must sit in the authority; the greedy class backtracks to the LAST `@`
78+
* before the path, the userinfo boundary RFC 3986 defines.
79+
*/
80+
export const URL_USERINFO_RE = /^([a-z][a-z0-9+.\-]*:\/\/)[^/?#]*@/i;
81+
82+
const isPlainRecord = (v: unknown): v is Record<string, unknown> =>
83+
!!v && typeof v === 'object' && !Array.isArray(v);
84+
85+
/** The query parameter names judged for `item`: the fixed set plus its own `auth.paramName`. */
86+
export function connectorCredentialQueryParamsOf(item: Record<string, unknown>): readonly string[] {
87+
const auth = item.auth;
88+
const own = isPlainRecord(auth) && auth.type === 'api-key' && typeof auth.paramName === 'string' && auth.paramName !== ''
89+
? auth.paramName
90+
: undefined;
91+
return own === undefined ? CONNECTOR_CREDENTIAL_URL_QUERY_PARAM_NAMES : [...CONNECTOR_CREDENTIAL_URL_QUERY_PARAM_NAMES, own];
92+
}
93+
94+
/** What credential parts one URL holds. */
95+
export interface ConnectorUrlCredentialParts {
96+
/** The URL carries a userinfo (`user@`, `user:password@`). */
97+
userinfo: boolean;
98+
/** The credential query parameters it carries with a value, as the judged name spells them. */
99+
params: string[];
100+
}
101+
102+
/** The credential parts `value` holds, or `undefined` when it is not a URL or holds none. */
103+
export function connectorUrlCredentialPartsOf(
104+
value: string,
105+
params: readonly string[],
106+
): ConnectorUrlCredentialParts | undefined {
107+
if (!URL_SCHEME_RE.test(value)) return undefined;
108+
const userinfo = URL_USERINFO_RE.test(value);
109+
const found = urlCredentialQueryParams(value, params);
110+
return userinfo || found.length > 0 ? { userinfo, params: found } : undefined;
111+
}
112+
113+
/** One URL holding credential parts, located from the entry root. */
114+
export interface ConnectorUrlCredential extends ConnectorUrlCredentialParts {
115+
/** The URL's position: object keys, and an array element's index. */
116+
path: Array<string | number>;
117+
}
118+
119+
/**
120+
* Every URL under {@link CONNECTOR_URL_ROOTS} that holds a credential part, at
121+
* any depth — inside arrays and under keys whose own name carries a dot too.
122+
* The write door's walk: it reports every position, where the read redactor
123+
* rewrites what it can address and withholds the rest whole.
124+
*/
125+
export function findConnectorUrlCredentials(item: Record<string, unknown>): ConnectorUrlCredential[] {
126+
const params = connectorCredentialQueryParamsOf(item);
127+
const found: ConnectorUrlCredential[] = [];
128+
const walk = (value: unknown, path: Array<string | number>): void => {
129+
if (typeof value === 'string') {
130+
const parts = connectorUrlCredentialPartsOf(value, params);
131+
if (parts) found.push({ path, ...parts });
132+
} else if (Array.isArray(value)) {
133+
value.forEach((element, index) => walk(element, [...path, index]));
134+
} else if (isPlainRecord(value)) {
135+
for (const [key, child] of Object.entries(value)) walk(child, [...path, key]);
136+
}
137+
};
138+
for (const root of CONNECTOR_URL_ROOTS) {
139+
if (isPlainRecord(item[root])) walk(item[root], [root]);
140+
}
141+
return found;
142+
}

0 commit comments

Comments
 (0)