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
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
123128import { ConnectorInstanceAuthSchema } from '../shared/connector-auth.zod' ;
124129import { ConnectorActionSchema , DeclarativeConnectorEntrySchema , RetryConfigSchema } from './connector.zod' ;
125130import { METADATA_READ_DECORATIONS } from '../kernel/metadata-read-decorations' ;
126- import { CREDENTIAL_URL_QUERY_PARAM_NAMES } from '../data/driver/common.zod' ;
127131import { 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' ;
128139import { objectShapeOf , wrapperChainOf , zodDefOf } from '../kernel/metadata-credential-fields' ;
129140import 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 - z 0 - 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 - z 0 - 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. */
179161function 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. */
193166interface 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. */
398371function 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 */
416389function 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
0 commit comments