Skip to content

Commit 6d544e6

Browse files
committed
wip(spec): connector URL and nested-key pins
Claude-Session: https://claude.ai/code/session_01Q4EjjP1K353tLKWRMajLsE Co-authored-by: Claude <noreply@anthropic.com>
1 parent 337c7d5 commit 6d544e6

5 files changed

Lines changed: 370 additions & 10 deletions

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,43 @@ describe('the connector redactor — credentials inside a URL under `providerCon
265265
});
266266
});
267267

268+
describe('the connector redactor — credentials inside a URL under `auth`', () => {
269+
const oauth2 = (over: Record<string, unknown>) => ({
270+
type: 'oauth2', grant: 'authorization_code', clientId: 'client-1', credentialRef: 'V_CLIENT_SECRET',
271+
authorizationUrl: 'https://auth.vendor.example/authorize', tokenUrl: 'https://auth.vendor.example/token', ...over,
272+
});
273+
274+
it('rewrites the userinfo out of `auth.tokenUrl` and `auth.authorizationUrl`, keeping the rest byte for byte', () => {
275+
const { item: served, redactedKeys } = redactConnectorItem({
276+
...base,
277+
auth: oauth2({
278+
tokenUrl: `https://c:${P(60)}@auth.vendor.example:8443/oauth/token?region=eu`,
279+
authorizationUrl: `https://${P(61)}@auth.vendor.example/authorize`,
280+
}),
281+
});
282+
expect(redactedKeys).toEqual(['auth.authorizationUrl', 'auth.tokenUrl']);
283+
expect(served.auth).toEqual(oauth2({
284+
tokenUrl: 'https://auth.vendor.example:8443/oauth/token?region=eu',
285+
authorizationUrl: 'https://auth.vendor.example/authorize',
286+
}));
287+
expect(holds(served, P(60), P(61))).toBe(false);
288+
});
289+
290+
it('strips a credential query parameter from `auth.resource`', () => {
291+
const { item: served, redactedKeys } = redactConnectorItem({
292+
...base,
293+
auth: oauth2({ resource: `https://api.vendor.example/?audience=v1&token=${P(62)}` }),
294+
});
295+
expect(redactedKeys).toEqual(['auth.resource']);
296+
expect((served.auth as Record<string, unknown>).resource).toBe('https://api.vendor.example/?audience=v1');
297+
});
298+
299+
it('declared `auth` URLs with no credential part are untouched', () => {
300+
const item = { ...base, auth: oauth2({ resource: 'https://api.vendor.example/' }) };
301+
expect(redactConnectorItem(item)).toEqual({ item, redactedKeys: [] });
302+
});
303+
});
304+
268305
describe('the connector redactor — top-level keys the entry does not declare', () => {
269306
it.each([
270307
['a credential-shaped scalar', { apiKey: P(50) }, ['apiKey']],

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ import { ConnectorActionSchema, DeclarativeConnectorEntrySchema, RetryConfigSche
130130
import { METADATA_READ_DECORATIONS } from '../kernel/metadata-read-decorations';
131131
import { redactUrlCredentialQueryParams } from '../data/datasource-credential-redaction';
132132
import {
133+
CONNECTOR_CREDENTIAL_MAP_PATHS,
133134
CONNECTOR_CREDENTIAL_URL_QUERY_PARAM_NAMES,
134135
CONNECTOR_URL_ROOTS,
135136
URL_USERINFO_RE,
@@ -140,12 +141,7 @@ import { objectShapeOf, wrapperChainOf, zodDefOf } from '../kernel/metadata-cred
140141
import type { MetadataRedactionResult } from '../kernel/metadata-type-redaction';
141142

142143
/** The map positions under `providerConfig` withheld whole (see the module note, item 3). */
143-
export const CONNECTOR_CREDENTIAL_MAP_PATHS: readonly (readonly string[])[] = Object.freeze([
144-
['providerConfig', 'headers'],
145-
['providerConfig', 'defaultHeaders'],
146-
['providerConfig', 'transport', 'headers'],
147-
['providerConfig', 'transport', 'env'],
148-
]);
144+
export { CONNECTOR_CREDENTIAL_MAP_PATHS };
149145

150146
/**
151147
* The query parameters whose value a connector URL is read as carrying a
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// An authored connector entry (`DeclarativeConnectorEntrySchema`, behind
4+
// `defineConnector()`, `defineStack({ connectors })`, `os validate` /
5+
// `os compile`, the artifact load and `PUT /meta/connector/:name`) refuses a
6+
// key its two nested shapes do not declare — inside `retryConfig`, and inside
7+
// each `actions` element — as it refuses one at its own top level. Every
8+
// refusal is pinned by its issue `code`, `path` and `keys`, with a CONTROL
9+
// accept beside it. The open carriers a plugin's connector def and the runtime
10+
// use (`ConnectorSchema`, `RetryConfigSchema`, `ConnectorActionSchema`) keep
11+
// their posture, pinned as controls.
12+
//
13+
// Every value below is an obviously-fake placeholder, and the refusal must
14+
// never echo it.
15+
16+
import { describe, it, expect } from 'vitest';
17+
import {
18+
ConnectorActionSchema,
19+
ConnectorSchema,
20+
DeclarativeConnectorEntrySchema,
21+
RetryConfigSchema,
22+
defineConnector,
23+
} from './connector.zod';
24+
import { ObjectStackDefinitionSchema } from '../stack.zod';
25+
26+
const PLACEHOLDER = 'TEST_PLACEHOLDER_NOT_A_SECRET';
27+
28+
const INSTANCE = {
29+
name: 'vendor',
30+
label: 'Vendor',
31+
type: 'api',
32+
provider: 'rest',
33+
providerConfig: { baseUrl: 'https://vendor.example.com' },
34+
auth: { type: 'bearer', credentialRef: 'VENDOR_TOKEN' },
35+
} as const;
36+
37+
const DESCRIPTOR = { name: 'erp', label: 'ERP', type: 'saas' } as const;
38+
39+
const RETRY = { strategy: 'exponential_backoff', maxAttempts: 2, initialDelayMs: 500, jitter: false } as const;
40+
const ACTION = { key: 'get_invoice', label: 'Get invoice', description: 'One invoice.', effect: 'read', inputSchema: { type: 'object' } } as const;
41+
42+
/** The one issue of a refused parse, as `[code, path, keys]`, and its message. */
43+
function refusal(input: unknown): { located: [string, string, unknown]; message: string } {
44+
const result = DeclarativeConnectorEntrySchema.safeParse(input);
45+
expect(result.success, 'the entry must be refused').toBe(false);
46+
expect(result.error!.issues, JSON.stringify(result.error!.issues)).toHaveLength(1);
47+
const issue = result.error!.issues[0]!;
48+
return { located: [issue.code, issue.path.join('.'), (issue as { keys?: unknown }).keys], message: issue.message };
49+
}
50+
51+
describe('an authored connector entry refuses a key its nested shapes do not declare', () => {
52+
it.each([
53+
['an instance with every declared `retryConfig` key', { ...INSTANCE, retryConfig: RETRY }],
54+
['a descriptor with every declared action key', { ...DESCRIPTOR, actions: [ACTION, { key: 'list', label: 'List' }] }],
55+
['an empty `retryConfig` (clears the policy)', { ...INSTANCE, retryConfig: {} }],
56+
] as const)('CONTROL: %s parses', (_label, entry) => {
57+
expect(DeclarativeConnectorEntrySchema.safeParse(entry).success).toBe(true);
58+
});
59+
60+
it.each([
61+
['a credential-shaped key', { secret: PLACEHOLDER }, ['secret']],
62+
['a misspelled policy key', { maxRetries: 4 }, ['maxRetries']],
63+
['several keys', { secret: PLACEHOLDER, timeoutMs: 100 }, ['secret', 'timeoutMs']],
64+
] as const)('`retryConfig` with %s is refused at `retryConfig`', (_label, extra, keys) => {
65+
const { located, message } = refusal({ ...INSTANCE, retryConfig: { ...RETRY, ...extra } });
66+
expect(located).toEqual(['unrecognized_keys', 'retryConfig', keys]);
67+
expect(message).toContain("connector entry's `retryConfig`");
68+
expect(message).not.toContain(PLACEHOLDER);
69+
});
70+
71+
it.each([
72+
['a credential-shaped key', { token: PLACEHOLDER }, ['token']],
73+
['an execution binding', { method: 'GET', path: '/invoices/{id}' }, ['method', 'path']],
74+
] as const)('an `actions` element with %s is refused at that element', (_label, extra, keys) => {
75+
const { located, message } = refusal({ ...DESCRIPTOR, actions: [{ key: 'list', label: 'List' }, { ...ACTION, ...extra }] });
76+
expect(located).toEqual(['unrecognized_keys', 'actions.1', keys]);
77+
expect(message).toContain('this connector action');
78+
expect(message).not.toContain(PLACEHOLDER);
79+
});
80+
81+
it('inside a stack, the issue is located under the entry', () => {
82+
const result = ObjectStackDefinitionSchema.safeParse({
83+
manifest: { id: 'com.example.app', name: 'app', version: '1.0.0', type: 'app' },
84+
connectors: [{ ...INSTANCE, retryConfig: { ...RETRY, secret: PLACEHOLDER } }],
85+
});
86+
expect(result.success).toBe(false);
87+
expect(result.error!.issues.map((issue) => issue.path.join('.'))).toContain('connectors.0.retryConfig');
88+
});
89+
90+
it('`defineConnector()` refuses it too, and accepts the declared keys', () => {
91+
expect(() => defineConnector({ ...DESCRIPTOR, actions: [{ ...ACTION, token: PLACEHOLDER } as never] })).toThrow(/this connector action/);
92+
expect(() => defineConnector({ ...DESCRIPTOR, actions: [ACTION] })).not.toThrow();
93+
});
94+
95+
it('CONTROL: the open carriers keep their posture (an undeclared nested key is dropped, not refused)', () => {
96+
const def = ConnectorSchema.parse({ ...DESCRIPTOR, retryConfig: { ...RETRY, secret: PLACEHOLDER }, actions: [{ ...ACTION, token: PLACEHOLDER }] });
97+
expect(JSON.stringify(def)).not.toContain(PLACEHOLDER);
98+
expect(RetryConfigSchema.safeParse({ ...RETRY, secret: PLACEHOLDER }).success).toBe(true);
99+
expect(ConnectorActionSchema.safeParse({ ...ACTION, token: PLACEHOLDER }).success).toBe(true);
100+
});
101+
102+
it('the closed nested shapes declare exactly the open shapes\' keys', () => {
103+
const entry = DeclarativeConnectorEntrySchema.safeParse({ ...INSTANCE, retryConfig: RETRY });
104+
expect(entry.success).toBe(true);
105+
const retryKeys = Object.keys((RetryConfigSchema as unknown as { shape: Record<string, unknown> }).shape).sort();
106+
const actionKeys = Object.keys((ConnectorActionSchema as unknown as { shape: Record<string, unknown> }).shape).sort();
107+
// Every declared key is accepted by the closed entry …
108+
const everyRetry = Object.fromEntries(retryKeys.map((k) => [k, (RetryConfigSchema.parse({}) as Record<string, unknown>)[k]]));
109+
expect(DeclarativeConnectorEntrySchema.safeParse({ ...INSTANCE, retryConfig: everyRetry }).success).toBe(true);
110+
const everyAction = { ...ACTION, outputSchema: { type: 'object' } };
111+
expect(Object.keys(everyAction).sort()).toEqual(actionKeys);
112+
expect(DeclarativeConnectorEntrySchema.safeParse({ ...DESCRIPTOR, actions: [everyAction] }).success).toBe(true);
113+
});
114+
});
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// An authored connector entry (`DeclarativeConnectorEntrySchema`, behind
4+
// `defineStack({ connectors })`, `os validate` / `os compile`, the artifact load
5+
// and `PUT /meta/connector/:name`) keeps no credential part in a URL: under
6+
// `providerConfig` (any key, any depth, array elements included) and under
7+
// `auth` (`tokenUrl`, `authorizationUrl`, `resource`), a URL holding a userinfo
8+
// or a credential query parameter is refused, one issue per URL, located at
9+
// the URL. Every refusal has a CONTROL accept beside it, so a refusal that fired
10+
// on everything could not pass, and the last block pins that the write door
11+
// refuses exactly what the read redactor rewrites.
12+
//
13+
// Every value below is an obviously-fake placeholder, and the refusal must
14+
// never echo it.
15+
16+
import { describe, it, expect } from 'vitest';
17+
import { ConnectorSchema, DeclarativeConnectorEntrySchema } from './connector.zod';
18+
import { redactConnectorItem } from './connector-credential-redaction';
19+
import { ObjectStackDefinitionSchema } from '../stack.zod';
20+
21+
const PLACEHOLDER = 'TEST_PLACEHOLDER_NOT_A_SECRET';
22+
23+
const rest = (baseUrl: string, auth: Record<string, unknown> = { type: 'bearer', credentialRef: 'VENDOR_TOKEN' }) => ({
24+
name: 'vendor',
25+
label: 'Vendor',
26+
type: 'api',
27+
provider: 'rest',
28+
providerConfig: { baseUrl },
29+
auth,
30+
});
31+
32+
const mcp = (url: string) => ({
33+
name: 'tools',
34+
label: 'Tools',
35+
type: 'api',
36+
provider: 'mcp',
37+
providerConfig: { transport: { kind: 'http', url } },
38+
});
39+
40+
const openapi = (spec: string) => ({
41+
name: 'billing',
42+
label: 'Billing',
43+
type: 'api',
44+
provider: 'openapi',
45+
providerConfig: { spec },
46+
auth: { type: 'bearer', credentialRef: 'BILLING_TOKEN' },
47+
});
48+
49+
const oauth2 = (over: Record<string, unknown>) => rest('https://api.vendor.example.com', {
50+
type: 'oauth2',
51+
grant: 'authorization_code',
52+
authorizationUrl: 'https://auth.vendor.example.com/authorize',
53+
tokenUrl: 'https://auth.vendor.example.com/token',
54+
clientId: 'client-1',
55+
credentialRef: 'VENDOR_CLIENT_SECRET',
56+
...over,
57+
});
58+
59+
/** Every issue of a refused parse, as `[code, path]`, and the messages. */
60+
function refusals(input: unknown): { located: Array<[string, string]>; messages: string[] } {
61+
const result = DeclarativeConnectorEntrySchema.safeParse(input);
62+
expect(result.success, 'the entry must be refused').toBe(false);
63+
const issues = result.error!.issues;
64+
return {
65+
located: issues.map((issue) => [issue.code, issue.path.join('.')]),
66+
messages: issues.map((issue) => issue.message),
67+
};
68+
}
69+
70+
const accepts = (input: unknown): void => {
71+
const result = DeclarativeConnectorEntrySchema.safeParse(input);
72+
expect(result.success, JSON.stringify(result.success ? null : result.error.issues)).toBe(true);
73+
};
74+
75+
describe('an authored connector URL holds no credential part', () => {
76+
describe('CONTROL: a URL with no credential part is accepted at every position', () => {
77+
it.each([
78+
['a rest baseUrl', rest('https://api.vendor.example.com/v1')],
79+
['a baseUrl with an ordinary query', rest('https://api.vendor.example.com/v1?region=eu&page=2')],
80+
['a baseUrl whose credential parameter is empty', rest('https://api.vendor.example.com/v1?token=&api_key=')],
81+
['a baseUrl whose credential name sits in the fragment', rest(`https://api.vendor.example.com/v1#token=${PLACEHOLDER}`)],
82+
['an mcp http transport url', mcp('https://mcp.vendor.example.com/mcp')],
83+
['an openapi spec URL', openapi('https://api.vendor.example.com/openapi.json')],
84+
['an openapi spec that is a path, not a URL', openapi('./specs/billing.yaml')],
85+
['oauth2 endpoints and resource', oauth2({ resource: 'https://api.vendor.example.com/' })],
86+
['a credentialRef-only instance', rest('https://api.vendor.example.com', { type: 'api-key', credentialRef: 'VENDOR_KEY', paramName: 'key' })],
87+
] as const)('%s', (_label, entry) => accepts(entry));
88+
});
89+
90+
describe('REFUSED: a userinfo or a credential query parameter, at each URL position', () => {
91+
it.each([
92+
['a userinfo password in the baseUrl', rest(`https://user:${PLACEHOLDER}@api.vendor.example.com/v1`), 'providerConfig.baseUrl'],
93+
['a userinfo token in the baseUrl', rest(`https://${PLACEHOLDER}@api.vendor.example.com/v1`), 'providerConfig.baseUrl'],
94+
['`api_key` in the baseUrl query', rest(`https://api.vendor.example.com/v1?api_key=${PLACEHOLDER}`), 'providerConfig.baseUrl'],
95+
['`token` in the baseUrl query', rest(`https://api.vendor.example.com/v1?region=eu&token=${PLACEHOLDER}`), 'providerConfig.baseUrl'],
96+
['`access_token` in the baseUrl query', rest(`https://api.vendor.example.com/v1?access_token=${PLACEHOLDER}`), 'providerConfig.baseUrl'],
97+
['a credential name spelled in another case', rest(`https://api.vendor.example.com/v1?Access_Token=${PLACEHOLDER}`), 'providerConfig.baseUrl'],
98+
['a percent-encoded credential name', rest(`https://api.vendor.example.com/v1?api%5Fkey=${PLACEHOLDER}`), 'providerConfig.baseUrl'],
99+
[
100+
'the instance\'s own `auth.paramName` in the baseUrl query',
101+
rest(`https://api.vendor.example.com/v1?vendor_key=${PLACEHOLDER}`, { type: 'api-key', credentialRef: 'VENDOR_KEY', paramName: 'vendor_key' }),
102+
'providerConfig.baseUrl',
103+
],
104+
['a userinfo password in an mcp transport url', mcp(`https://user:${PLACEHOLDER}@mcp.vendor.example.com/mcp`), 'providerConfig.transport.url'],
105+
['`token` in an openapi spec URL', openapi(`https://api.vendor.example.com/openapi.json?token=${PLACEHOLDER}`), 'providerConfig.spec'],
106+
['a userinfo password in `auth.tokenUrl`', oauth2({ tokenUrl: `https://c:${PLACEHOLDER}@auth.vendor.example.com/token` }), 'auth.tokenUrl'],
107+
['`client_secret` in `auth.tokenUrl`', oauth2({ tokenUrl: `https://auth.vendor.example.com/token?client_secret=${PLACEHOLDER}` }), 'auth.tokenUrl'],
108+
['a userinfo in `auth.authorizationUrl`', oauth2({ authorizationUrl: `https://c:${PLACEHOLDER}@auth.vendor.example.com/authorize` }), 'auth.authorizationUrl'],
109+
['`key` in `auth.resource`', oauth2({ resource: `https://api.vendor.example.com/?key=${PLACEHOLDER}` }), 'auth.resource'],
110+
] as const)('%s', (_label, entry, at) => {
111+
const { located, messages } = refusals(entry);
112+
expect(located).toEqual([['custom', at]]);
113+
expect(messages[0]).toContain(`\`${at}\``);
114+
expect(messages[0]).toContain('auth: { type, credentialRef }');
115+
expect(messages[0]).not.toContain(PLACEHOLDER);
116+
});
117+
118+
it('a URL at any depth under `providerConfig`, an array element and a dotted key included', () => {
119+
const entry = {
120+
...rest('https://api.vendor.example.com'),
121+
providerConfig: {
122+
baseUrl: 'https://api.vendor.example.com',
123+
mirrors: ['https://eu.vendor.example.com', `https://us.vendor.example.com?sig=${PLACEHOLDER}`],
124+
'x.callback': `https://hooks.vendor.example.com?secret=${PLACEHOLDER}`,
125+
nested: { deeper: { url: `https://u:${PLACEHOLDER}@deep.vendor.example.com` } },
126+
},
127+
};
128+
expect(refusals(entry).located).toEqual([
129+
['custom', 'providerConfig.mirrors.1'],
130+
['custom', 'providerConfig.x.callback'],
131+
['custom', 'providerConfig.nested.deeper.url'],
132+
]);
133+
});
134+
135+
it('one issue per URL, naming every credential part it holds', () => {
136+
const entry = oauth2({ tokenUrl: `https://c:${PLACEHOLDER}@auth.vendor.example.com/token?token=${PLACEHOLDER}&key=${PLACEHOLDER}` });
137+
const { located, messages } = refusals(entry);
138+
expect(located).toEqual([['custom', 'auth.tokenUrl']]);
139+
expect(messages[0]).toContain('a userinfo');
140+
expect(messages[0]).toContain('the `token` query parameter');
141+
expect(messages[0]).toContain('the `key` query parameter');
142+
});
143+
144+
it('inside a stack, the issue is located under the entry', () => {
145+
const result = ObjectStackDefinitionSchema.safeParse({
146+
manifest: { id: 'com.example.app', name: 'app', version: '1.0.0', type: 'app' },
147+
connectors: [rest(`https://api.vendor.example.com?token=${PLACEHOLDER}`)],
148+
});
149+
expect(result.success).toBe(false);
150+
const paths = result.error!.issues.map((issue) => issue.path.join('.'));
151+
expect(paths).toContain('connectors.0.providerConfig.baseUrl');
152+
});
153+
});
154+
155+
it('CONTROL: a URL inside a header or environment map is left to the map\'s own rules (the read withholds the map whole)', () => {
156+
accepts({
157+
...rest('https://api.vendor.example.com'),
158+
providerConfig: { baseUrl: 'https://api.vendor.example.com', headers: { Referer: `https://u:${PLACEHOLDER}@app.example.com` } },
159+
});
160+
accepts({
161+
name: 'local_tools', label: 'Local tools', type: 'api', provider: 'mcp',
162+
providerConfig: { transport: { kind: 'stdio', command: 'tools', env: { UPSTREAM_URL: `https://u:${PLACEHOLDER}@db.example.com` } } },
163+
});
164+
});
165+
166+
it('CONTROL: the open runtime carrier `ConnectorSchema` keeps its posture', () => {
167+
expect(ConnectorSchema.safeParse(rest(`https://api.vendor.example.com?token=${PLACEHOLDER}`)).success).toBe(true);
168+
});
169+
170+
describe('the write door refuses exactly what the read redactor rewrites', () => {
171+
const urls = [
172+
'https://api.vendor.example.com/v1',
173+
'https://api.vendor.example.com/v1?page=2',
174+
'https://api.vendor.example.com/v1?token=',
175+
`https://user:${PLACEHOLDER}@api.vendor.example.com/v1`,
176+
`https://${PLACEHOLDER}@api.vendor.example.com/v1`,
177+
`https://api.vendor.example.com/v1?apikey=${PLACEHOLDER}`,
178+
`https://api.vendor.example.com/v1?page=2&signature=${PLACEHOLDER}#token=x`,
179+
`https://api.vendor.example.com/v1#api_key=${PLACEHOLDER}`,
180+
];
181+
it.each(urls)('%s', (url) => {
182+
for (const entry of [rest(url), oauth2({ tokenUrl: url })]) {
183+
const refused = !DeclarativeConnectorEntrySchema.safeParse(entry).success;
184+
const rewritten = redactConnectorItem(entry as Record<string, unknown>).redactedKeys.length > 0;
185+
expect(refused, `${url}: refused ⇔ rewritten`).toBe(rewritten);
186+
}
187+
});
188+
});
189+
});

0 commit comments

Comments
 (0)