Skip to content
Merged
24 changes: 24 additions & 0 deletions .changeset/33553-connector-action-undeclared-input-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'@objectstack/service-automation': minor
'@objectstack/connector-openapi': minor
'@objectstack/spec': minor
---

fix(service-automation)!: a `connector_action` node refuses an input key its action does not declare, instead of sending it to the provider

Clause-②: no (narrowing) — a flow whose `connector_action` node carries a key in `connectorConfig.input` that the chosen action's `inputSchema` does not declare used to run and send that key to the provider; its step now fails before dispatch. First-party flows affected: 0 (the shipped DocuSign, Stripe, GitHub and showcase flows send only declared keys).
Metadata-protocol: narrowed

<!-- adr-0087: registered connector-action-undeclared-input-key-refused -->

**BREAKING** for a `connector_action` step whose input holds a key the action does not declare. The step now fails with `code: 'VALIDATION_ERROR'` before the handler is called, naming the node, each undeclared key by its dotted path, and the keys the action declares at that level; nothing is sent. The failure is a `runtime` one, so a `fault` edge on the node receives it, as for a missing required parameter or a value of the wrong type. A connector or action switch in the designer is the usual way such a key is left behind.

Migration, FROM → TO: `connectorConfig: { connectorId: 'slack', actionId: 'chat.postMessage', input: { channel: 'C1', text: 'hi', stale_key: 'x' } }` → drop `stale_key` from `input`, or pick the action that declares it. A key is judged at every object level the walk reaches, array items included, against the schema of that level (`input.query.stale` against the `query` properties of an OpenAPI action), and a CEL envelope is judged on the map it evaluates to.

An action whose schema lists only some of the parameters its handler forwards refuses the others now. The Slack connector's `chat.postMessage` and `chat.update` list `channel`, `text`, `blocks` and `thread_ts` / `ts` and forward the whole input to the Slack Web API, so any other Slack parameter (`unfurl_links`, `mrkdwn`, `reply_broadcast`, …) on those two actions is refused. Migration, FROM → TO: `{ actionId: 'chat.postMessage', input: { channel: 'C1', text: 'hi', unfurl_links: false } }` → `{ actionId: 'call', input: { method: 'chat.postMessage', params: { channel: 'C1', text: 'hi', unfurl_links: false } } }`; the `call` action's `params` is an object with no `properties`, so it carries any Slack parameter.

`@objectstack/connector-openapi`: what the generator cannot read without de-referencing the document is now declared open instead of left out, so a flow over an OpenAPI 3.x document nobody normalized keeps dispatching. An unresolved `$ref` parameter has no readable `in`, so it opens every location the handler sends: `path`, `query` and `header` are each emitted with `additionalProperties: true`, also when they declare no parameter of their own, and the parameters declared beside them are still judged. An unresolved `$ref` request body, or one whose content carries no `schema`, is declared as `body: {}` (any value). Running `normalize-openapi` over the document still gives each such parameter its own declaration and type check.

Which schemas declare their keys: an object schema that lists `properties`, or says `additionalProperties: false`; the declared keys are the names in `properties` plus those in `required`. A schema that admits more keys declares open input and every key still dispatches: `additionalProperties` set to `true` or to a schema, `unevaluatedProperties` other than `false`, `patternProperties`, `$ref`, `$dynamicRef`, `$recursiveRef`, `allOf` / `anyOf` / `oneOf`, `if` / `then` / `else`, `dependentSchemas` or `dependencies`; so does a schema that lists no `properties`, and an action with no `inputSchema`. An undeclared key whose value is `undefined` is absent and not refused; any other value, `null` included, is.

Judged at run time, against the schema of the instance the call dispatches to, and not when the flow registers: the boot flow pull registers every flow before a declarative connector materializes, and an instance's schema is re-read from its upstream on every re-materialization, so a registration-time verdict could be contradicted later in the same boot. The connector pull door (`connectorSource.input`) is unchanged.
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ const document = {
},
};

type Sent = { url: string; headers: Record<string, string> };
type Sent = { url: string; headers: Record<string, string>; body?: string };

/** Boot a kernel with one hand-wired OpenAPI connector `pets` over {@link document}, recording every request. */
async function boot(auth: RestAuth): Promise<{ engine: AutomationEngine; sent: Sent[]; kernel: LiteKernel }> {
/** Boot a kernel with one hand-wired OpenAPI connector `pets` over `doc` ({@link document} by default), recording every request. */
async function boot(auth: RestAuth, doc: object = document): Promise<{ engine: AutomationEngine; sent: Sent[]; kernel: LiteKernel }> {
const sent: Sent[] = [];
const fetchImpl = (async (url: string, init: { headers?: Record<string, string> }) => {
sent.push({ url, headers: { ...init?.headers } });
const fetchImpl = (async (url: string, init: { headers?: Record<string, string>; body?: string }) => {
sent.push({ url, headers: { ...init?.headers }, body: init?.body });
return { status: 200, ok: true, headers: { get: () => 'application/json' }, json: async () => ({}), text: async () => '{}' };
}) as unknown as typeof fetch;
const kernel = new LiteKernel({ logger: { level: 'silent' } } as never);
Expand All @@ -65,17 +65,17 @@ async function boot(auth: RestAuth): Promise<{ engine: AutomationEngine; sent: S
},
async start() {},
} as never);
kernel.use(new ConnectorOpenApiPlugin({ document, name: 'pets', auth, fetchImpl } as never));
kernel.use(new ConnectorOpenApiPlugin({ document: doc, name: 'pets', auth, fetchImpl } as never));
await kernel.bootstrap();
return { engine: kernel.getService<AutomationEngine>('automation'), sent, kernel };
}

async function callGetPet(engine: AutomationEngine, name: string, input: Record<string, unknown>) {
async function callGetPet(engine: AutomationEngine, name: string, input: Record<string, unknown>, actionId = 'getPet') {
engine.registerFlow(name, {
name, label: name, type: 'autolaunched',
nodes: [
{ id: 'start', type: 'start', label: 'Start' },
{ id: 'call', type: 'connector_action', label: 'Call', connectorConfig: { connectorId: 'pets', actionId: 'getPet', input } },
{ id: 'call', type: 'connector_action', label: 'Call', connectorConfig: { connectorId: 'pets', actionId, input } },
{ id: 'end', type: 'end', label: 'End' },
],
edges: [{ id: 'e1', source: 'start', target: 'call' }, { id: 'e2', source: 'call', target: 'end' }],
Expand Down Expand Up @@ -136,3 +136,97 @@ describe('connector-openapi inputSchema at the connector_action door (#27995)',
}
});
});

/**
* #33553 — the executor refuses a key an object schema does not declare, so
* what the generator skips on a document nobody de-referenced must read as
* open: an unresolved `$ref` parameter opens every location the handler
* sends, and an unresolved `$ref` or schemaless request body is `body: {}`.
* On `main` before the refusal these calls dispatched and worked; they still do.
*/
describe('connector-openapi skipped $ref inputs still dispatch under the undeclared-key refusal (#33553)', () => {
const refDocument = {
openapi: '3.0.3',
info: { title: 'Petstore', version: '1.0.0' },
servers: [{ url: 'https://petstore.example.com' }],
components: {
parameters: {
PetId: { name: 'petId', in: 'path', required: true, schema: { type: 'integer' } },
Tag: { name: 'tag', in: 'query', schema: { type: 'string' } },
},
requestBodies: { Pet: { content: { 'application/json': { schema: { type: 'object' } } } } },
},
paths: {
'/pets/{petId}': {
put: {
operationId: 'putPet',
parameters: [
{ $ref: '#/components/parameters/PetId' },
{ $ref: '#/components/parameters/Tag' },
{ name: 'limit', in: 'query', schema: { type: 'integer' } },
],
requestBody: { $ref: '#/components/requestBodies/Pet' },
responses: { '200': { description: 'ok' } },
},
post: {
operationId: 'postPetRaw',
parameters: [{ name: 'petId', in: 'path', required: true, schema: { type: 'integer' } }],
requestBody: { required: true, content: { 'application/octet-stream': {} } },
responses: { '200': { description: 'ok' } },
},
},
},
};
const none: RestAuth = { type: 'none' };

it('1. an unresolved $ref parameter opens path, query and header; the declared query parameter stays typed', async () => {
const { engine, sent, kernel } = await boot(none, refDocument);
try {
const schema = engine.getConnectorDescriptors().find((d) => d.name === 'pets')?.actions
.find((a) => a.key === 'putPet')?.inputSchema as any;
expect(schema.properties.path).toEqual({ type: 'object', additionalProperties: true });
expect(schema.properties.header).toEqual({ type: 'object', additionalProperties: true });
expect(schema.properties.query).toEqual({
type: 'object', properties: { limit: { type: 'integer' } }, additionalProperties: true,
});
expect(schema.properties.body).toEqual({});
expect(schema.required).toBeUndefined();

const result = await callGetPet(engine, 'ref_params', {
path: { petId: 7 }, query: { tag: 'dog', limit: 2 }, body: { name: 'Rex' },
}, 'putPet');
expect(result.success, result.error).toBe(true);
expect(sent).toHaveLength(1);
const url = new URL(sent[0].url);
expect(url.pathname).toBe('/pets/7');
expect(url.searchParams.get('tag')).toBe('dog');
expect(sent[0].body).toBe(JSON.stringify({ name: 'Rex' }));

const wrongType = await callGetPet(engine, 'ref_params_typed', {
path: { petId: 7 }, query: { limit: 'two' },
}, 'putPet');
expect(wrongType.success).toBe(false);
expect(sent).toHaveLength(1);
} finally {
await kernel.shutdown().catch(() => {});
}
});

it('2. a request body whose content carries no schema is declared as body: {} and dispatches', async () => {
const { engine, sent, kernel } = await boot(none, refDocument);
try {
const schema = engine.getConnectorDescriptors().find((d) => d.name === 'pets')?.actions
.find((a) => a.key === 'postPetRaw')?.inputSchema as any;
expect(schema.properties.body).toEqual({});
expect(schema.required).toEqual(['path', 'body']);
expect(schema.properties.path.additionalProperties).toBeUndefined();

const result = await callGetPet(engine, 'raw_body', { path: { petId: 3 }, body: 'raw' }, 'postPetRaw');
expect(result.success, result.error).toBe(true);
expect(sent).toHaveLength(1);
expect(new URL(sent[0].url).pathname).toBe('/pets/3');
} finally {
await kernel.shutdown().catch(() => {});
}
});
});
37 changes: 29 additions & 8 deletions packages/connectors/connector-openapi/src/openapi-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,18 @@ const IGNORED_HEADER_PARAMETERS = new Set(['accept', 'content-type', 'authorizat
* flow's `connectorConfig.input`), are left out of it — and so, for a
* connector with a credential handle, is every parameter an `apiKey` security
* scheme the operation requires places the token in (`schemeFilled`).
*
* #33553 — that executor also refuses a key an object schema does not
* declare, reading `properties` as the action's contract. So what this
* generator SKIPS must read as open, never as absent: the handler still
* sends it, and on a document nobody de-referenced it is the only way the
* input can carry it. An unresolved `$ref` parameter has no `in` to read
* without de-referencing, so it opens every location the handler sends
* (`path`, `query`, `header`): each is emitted with
* `additionalProperties: true`, even when it declares no parameter of its
* own. An unresolved `$ref` request body, or one whose content carries no
* `schema`, is declared as `body: {}` — any value. The declared parameters
* beside them are still judged as before.
*/
function buildInputSchema(op: OpenApiOperation, auth: RestAuth, schemeFilled: ReadonlySet<string>): JsonSchema | undefined {
const sections: Record<'path' | 'query' | 'header', { props: Record<string, JsonSchema>; required: string[] }> = {
Expand All @@ -518,8 +530,13 @@ function buildInputSchema(op: OpenApiOperation, auth: RestAuth, schemeFilled: Re
const authHeader = auth.type === 'api-key' && !auth.paramName ? (auth.headerName ?? 'X-API-Key').toLowerCase() : undefined;
const authQuery = auth.type === 'api-key' ? auth.paramName : undefined;

let unresolvedParameter = false;
for (const p of op.parameters ?? []) {
if (!p || typeof p !== 'object' || '$ref' in p) continue;
if (!p || typeof p !== 'object') continue;
if ('$ref' in p) {
unresolvedParameter = true;
continue;
}
if (p.in !== 'path' && p.in !== 'query' && p.in !== 'header') continue;
if (p.in === 'header' && (IGNORED_HEADER_PARAMETERS.has(p.name.toLowerCase()) || p.name.toLowerCase() === authHeader)) continue;
if (p.in === 'query' && authQuery !== undefined && p.name === authQuery) continue;
Expand All @@ -533,18 +550,22 @@ function buildInputSchema(op: OpenApiOperation, auth: RestAuth, schemeFilled: Re
const required: string[] = [];
for (const where of ['path', 'query', 'header'] as const) {
const sec = sections[where];
if (Object.keys(sec.props).length === 0) continue;
const schema: JsonSchema = { type: 'object', properties: sec.props };
const declared = Object.keys(sec.props).length > 0;
if (!declared && !unresolvedParameter) continue;
const schema: JsonSchema = { type: 'object' };
if (declared) schema.properties = sec.props;
if (sec.required.length) schema.required = sec.required;
if (unresolvedParameter) schema.additionalProperties = true;
properties[where] = schema;
// Path params are always required when present; others only if any are.
if (where === 'path' || sec.required.length) required.push(where);
if ((where === 'path' && declared) || sec.required.length) required.push(where);
}

const bodySchema = extractRequestBodySchema(op.requestBody);
if (bodySchema) {
properties.body = bodySchema;
if (op.requestBody && !('$ref' in op.requestBody) && op.requestBody.required) required.push('body');
if (op.requestBody && typeof op.requestBody === 'object') {
// An unresolved `$ref` body, or content with no `schema`, is still a
// body the handler sends: declared as `{}`, any value.
properties.body = extractRequestBodySchema(op.requestBody) ?? {};
if (!('$ref' in op.requestBody) && op.requestBody.required) required.push('body');
}

if (Object.keys(properties).length === 0) return undefined;
Expand Down
Loading
Loading