Skip to content

Commit 607a0d1

Browse files
committed
test(trigger-api, runtime, lint): pin the declared vendor signature through the real door; readiness reads the hook's one verifier
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WGufzeeFznzXxc61VmVH12
1 parent 07dc391 commit 607a0d1

6 files changed

Lines changed: 469 additions & 6 deletions

File tree

‎packages/lint/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export {
145145
FLOW_TIME_RELATIVE_DESCRIPTOR_UNROUTABLE,
146146
FLOW_TRIGGER_UNROUTABLE,
147147
FLOW_API_TRIGGER_SECRET_MISSING,
148+
FLOW_API_TRIGGER_SIGNATURE_UNUSABLE,
148149
} from './validate-flow-trigger-readiness.js';
149150
export type {
150151
FlowTriggerReadinessFinding,

‎packages/lint/src/rule-explanations.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,32 @@ const FLOW_API_TRIGGER_SECRET_MISSING_EXPLANATION: RuleExplanation = {
20662066
],
20672067
};
20682068

2069+
const FLOW_API_TRIGGER_SIGNATURE_UNUSABLE_EXPLANATION: RuleExplanation = {
2070+
rule: 'flow-api-trigger-signature-unusable',
2071+
covers: 'why a hook with a broken sender signature admits nothing',
2072+
paragraphs: [
2073+
'An inbound api hook may declare how a third-party sender signs its posts, in its start node\'s ' +
2074+
'`config.signature`: the header the sender writes its digest in, `hmac-sha256`, `hex` or `base64`, and ' +
2075+
'what is signed, the raw body (`signs: \'body\'`, as DocuSign Connect signs it) or `<t>.<raw body>` ' +
2076+
'(`signs: \'timestamp.body\'`, a Stripe-style `t=…,v1=…` header). The key is the one ' +
2077+
'`config.secretRef` names, never a literal. A declared scheme REPLACES the `x-objectstack-signature` ' +
2078+
'check for its hook: the hook has that one verifier and never reads the platform header.',
2079+
'The finding means the declaration is present and the spec refuses it: an unknown algorithm or ' +
2080+
'encoding, a reserved header name, a timestamped scheme without its elements, no `config.secretRef`, ' +
2081+
'or a literal `config.secret` beside it. The verdict names the key the spec refuses at; the flow ' +
2082+
'parse prints the refusal itself in full.',
2083+
'A broken declaration never falls back to `x-objectstack-signature` and is never admitted unsigned. The ' +
2084+
'automation engine\'s flow parse refuses the flow at registration, and a trigger handed it anyway ' +
2085+
'refuses every post to its hook with the one `401 INVALID_SIGNATURE` every unverified post gets, so ' +
2086+
'the flow never receives a post. Fix the declaration, or remove `config.signature` to verify ' +
2087+
'`x-objectstack-signature` under the hook\'s secret.',
2088+
'A usable declaration is ready: the hook verifies the sender\'s header under the named key, a ' +
2089+
'timestamped scheme inside the same 300-second window `x-objectstack-signature` has, a body-only ' +
2090+
'scheme with no replay window because the sender signs no time.',
2091+
FLOW_GATE_REACH,
2092+
],
2093+
};
2094+
20692095
// `flow-trigger-unknown-object` lives in the same rule file but is not one of
20702096
// the five: its verdict depends on packages a build cannot see, so it warns —
20712097
// except under a package closure the runtime publish gate states, where the
@@ -5654,6 +5680,7 @@ export const RULE_EXPLANATIONS: Readonly<Record<string, RuleExplanation>> = Obje
56545680
[FLOW_TRIGGER_UNROUTABLE_EXPLANATION.rule]: FLOW_TRIGGER_UNROUTABLE_EXPLANATION,
56555681
[FLOW_TRIGGER_UNKNOWN_EVENT_EXPLANATION.rule]: FLOW_TRIGGER_UNKNOWN_EVENT_EXPLANATION,
56565682
[FLOW_API_TRIGGER_SECRET_MISSING_EXPLANATION.rule]: FLOW_API_TRIGGER_SECRET_MISSING_EXPLANATION,
5683+
[FLOW_API_TRIGGER_SIGNATURE_UNUSABLE_EXPLANATION.rule]: FLOW_API_TRIGGER_SIGNATURE_UNUSABLE_EXPLANATION,
56575684
[FLOW_TRIGGER_UNKNOWN_OBJECT_EXPLANATION.rule]: FLOW_TRIGGER_UNKNOWN_OBJECT_EXPLANATION,
56585685
[FLOW_INPUT_UNKNOWN_OBJECT_EXPLANATION.rule]: FLOW_INPUT_UNKNOWN_OBJECT_EXPLANATION,
56595686
[VALIDATION_RULE_REGEX_UNCOMPILABLE_EXPLANATION.rule]: VALIDATION_RULE_REGEX_UNCOMPILABLE_EXPLANATION,

‎packages/lint/src/validate-flow-trigger-readiness.test.ts‎

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
FLOW_TIME_RELATIVE_DESCRIPTOR_UNROUTABLE,
1313
FLOW_TRIGGER_UNROUTABLE,
1414
FLOW_API_TRIGGER_SECRET_MISSING,
15+
FLOW_API_TRIGGER_SIGNATURE_UNUSABLE,
1516
validateFlowApiTriggerSecret as validateFlowApiTriggerSecretUnrecorded,
1617
schemaRefusalHead,
1718
} from './validate-flow-trigger-readiness.js';
@@ -30,6 +31,7 @@ const NEVER_FIRE_IDS: readonly string[] = [
3031
FLOW_TIME_RELATIVE_DESCRIPTOR_UNROUTABLE,
3132
FLOW_TRIGGER_UNROUTABLE,
3233
FLOW_API_TRIGGER_SECRET_MISSING,
34+
FLOW_API_TRIGGER_SIGNATURE_UNUSABLE,
3335
FLOW_TRIGGER_UNKNOWN_EVENT,
3436
];
3537
const fired: Array<{ rule: string; message: string; hint: string }> = [];
@@ -1521,6 +1523,31 @@ describe('validateFlowTriggerReadiness', () => {
15211523
],
15221524
},
15231525
],
1526+
// [#30009] A declared sender scheme the spec refuses: never-fire, like a missing secret.
1527+
[
1528+
FLOW_API_TRIGGER_SIGNATURE_UNUSABLE,
1529+
'error',
1530+
{
1531+
objects: [candidateObject],
1532+
flows: [
1533+
{
1534+
name: 'broken_vendor_hook',
1535+
type: 'api',
1536+
status: 'active',
1537+
nodes: [
1538+
{
1539+
id: 'start',
1540+
type: 'start',
1541+
config: {
1542+
secretRef: 'DOCUSIGN_CONNECT_KEY',
1543+
signature: { signs: 'body', header: 'X-DocuSign-Signature-1', algorithm: 'hmac-sha1', encoding: 'base64' },
1544+
},
1545+
},
1546+
],
1547+
},
1548+
],
1549+
},
1550+
],
15241551
// ── The controls. Both are hedged, and the hedge is the whole reason the
15251552
// promotion above is not "everything in this file is an error now".
15261553
[
@@ -1753,6 +1780,89 @@ describe('validateFlowTriggerReadiness', () => {
17531780
});
17541781
});
17551782

1783+
// [#30009] A start node that declares its sender's own scheme (`config.signature`)
1784+
// is graded by the hook's ONE verifier, read through the spec's
1785+
// `apiTriggerVerifierOf` (the reader the engine and the trigger share): ready on
1786+
// the key `config.secretRef` names and nothing else, and never ready when the
1787+
// reader answers `unusable`.
1788+
describe('[#30009] api trigger readiness reads the hook\'s one verifier (config.signature)', () => {
1789+
const DOCUSIGN = { signs: 'body', header: 'X-DocuSign-Signature-1', algorithm: 'hmac-sha256', encoding: 'base64' };
1790+
const STRIPE = {
1791+
signs: 'timestamp.body', header: 'Stripe-Signature', algorithm: 'hmac-sha256', encoding: 'hex',
1792+
timestampElement: 't', digestElement: 'v1',
1793+
};
1794+
const vendorFlow = (config: Record<string, unknown>, type = 'api') => ({
1795+
name: 'vendor_hook',
1796+
label: 'Vendor hook',
1797+
type,
1798+
status: 'active',
1799+
nodes: [
1800+
{ id: 'start', type: 'start', label: 'Start', config },
1801+
{ id: 'end', type: 'end', label: 'End' },
1802+
],
1803+
edges: [{ id: 'e1', source: 'start', target: 'end' }],
1804+
});
1805+
const judge = (flow: Record<string, unknown>) => cliFlowFamily({ objects: [candidateObject], flows: [flow] });
1806+
const rules = (flow: Record<string, unknown>) => judge(flow).map((f) => [f.rule, f.severity, f.path]);
1807+
1808+
it('a usable declaration keyed by secretRef is ready, on both arms, at the CLI and the runtime publish gate', () => {
1809+
for (const signature of [DOCUSIGN, STRIPE, { ...DOCUSIGN, encoding: 'hex', prefix: 'sha256=' }]) {
1810+
const flow = vendorFlow({ hookId: 'vendor', secretRef: 'VENDOR_WEBHOOK_KEY', signature });
1811+
expect(judge(flow), JSON.stringify(signature)).toEqual([]);
1812+
expect(runRuntimeAuthoringRules({ type: 'flow', item: flow }).errors, JSON.stringify(signature)).toEqual([]);
1813+
}
1814+
});
1815+
1816+
it('an unusable declaration is never ready: one error, at the key the spec refuses', () => {
1817+
const cases: Array<[string, Record<string, unknown>, string]> = [
1818+
['an algorithm the spec refuses', { secretRef: 'K', signature: { ...DOCUSIGN, algorithm: 'hmac-sha1' } }, 'config.signature.algorithm'],
1819+
['a reserved header', { secretRef: 'K', signature: { ...DOCUSIGN, header: 'x-objectstack-signature' } }, 'config.signature.header'],
1820+
['a timestamped scheme with no timestamp element', { secretRef: 'K', signature: { ...STRIPE, timestampElement: undefined } }, 'config.signature.timestampElement'],
1821+
['no key reference', { signature: DOCUSIGN }, 'config.signature'],
1822+
['a literal secret beside it (an inline key)', { secret: 'whsec_inline', signature: DOCUSIGN }, 'config.signature'],
1823+
['a literal secret AND a secretRef beside it', { secret: 'whsec_inline', secretRef: 'K', signature: DOCUSIGN }, 'config.signature'],
1824+
['a secretRef that is not a usable name', { secretRef: 'OS_AUTH_SECRET', signature: DOCUSIGN }, 'config.secretRef'],
1825+
];
1826+
for (const [label, config, keyPath] of cases) {
1827+
const findings = judge(vendorFlow(config)).filter((f) => f.rule === FLOW_API_TRIGGER_SIGNATURE_UNUSABLE);
1828+
expect(findings.map((f) => [f.severity, f.path]), label).toEqual([['error', `flows[0].nodes[0].${keyPath}`]]);
1829+
expect(findings[0]!.message, label).toContain(keyPath);
1830+
expect(findings[0]!.message, label).toContain(`type: 'api'`);
1831+
// Never the missing-secret id beside it: one verdict per hook.
1832+
expect(judge(vendorFlow(config)).map((f) => f.rule), label).not.toContain(FLOW_API_TRIGGER_SECRET_MISSING);
1833+
// And never let through at the runtime publish gate.
1834+
expect(
1835+
runRuntimeAuthoringRules({ type: 'flow', item: vendorFlow(config) }).errors.map((f) => f.rule),
1836+
label,
1837+
).toContain(FLOW_API_TRIGGER_SIGNATURE_UNUSABLE);
1838+
}
1839+
});
1840+
1841+
it('a declared scheme is graded on its key reference alone: a withheld-and-stored literal secret does not make it ready', () => {
1842+
const flow = vendorFlow({ signature: DOCUSIGN });
1843+
const findings = validateFlowApiTriggerSecret(
1844+
{ objects: [candidateObject], flows: [flow] },
1845+
{ restoredCredentialPaths: new Set(['flows[0].nodes[0].config.secret']) },
1846+
);
1847+
expect(findings.map((f) => [f.rule, f.path])).toEqual([[FLOW_API_TRIGGER_SIGNATURE_UNUSABLE, 'flows[0].nodes[0].config.signature']]);
1848+
});
1849+
1850+
it('CONTROL: a flow that binds no api trigger is not graded by this rule, and a hook with no declaration keeps its own verdicts', () => {
1851+
expect(rules(vendorFlow({ secretRef: 'K', signature: { ...DOCUSIGN, algorithm: 'hmac-sha1' } }, 'autolaunched'))
1852+
.map(([rule]) => rule)).not.toContain(FLOW_API_TRIGGER_SIGNATURE_UNUSABLE);
1853+
expect(rules(vendorFlow({ hookId: 'vendor' }))).toEqual([[FLOW_API_TRIGGER_SECRET_MISSING, 'error', 'flows[0].nodes[0].config.secret']]);
1854+
expect(judge(vendorFlow({ secretRef: 'VENDOR_WEBHOOK_KEY' }))).toEqual([]);
1855+
});
1856+
1857+
it('`os explain flow-api-trigger-signature-unusable` says what a declared scheme is and why a broken one admits nothing', () => {
1858+
expect(FLOW_API_TRIGGER_SIGNATURE_UNUSABLE).toBe('flow-api-trigger-signature-unusable');
1859+
const text = explanationOf(FLOW_API_TRIGGER_SIGNATURE_UNUSABLE);
1860+
for (const fact of ['config.signature', 'config.secretRef', 'REPLACES', 'never falls back', '401 INVALID_SIGNATURE', '300-second']) {
1861+
expect(text, fact).toContain(fact);
1862+
}
1863+
});
1864+
});
1865+
17561866
describe('[#22161] one-line verdicts — the never-fire family', () => {
17571867
it('every verdict the cases above fired is one line of at most 200 characters', () => {
17581868
// The coverage control first: each of the five ids fired at least once, so
@@ -1798,9 +1908,10 @@ describe('[#22161] one-line verdicts — the never-fire family', () => {
17981908
[FLOW_TRIGGER_UNROUTABLE]: ['`resolveTriggerBinding`', 'manual — nothing to bind', 'one higher than its bound count', 'RESOLVED type', 'record-{before,after}-{create,insert,update,delete,write}'],
17991909
[FLOW_TRIGGER_UNKNOWN_EVENT]: ['record-{before,after}-{create,insert,update,delete,write}', 'bind-time warn', 'multi-event shape', '`record-after-write`'],
18001910
[FLOW_API_TRIGGER_SECRET_MISSING]: ['ADR-0041', 'HMAC', '`registerFlow`', 'whatever the flow\'s `status`', 'never receives a post', 'withholds'],
1911+
[FLOW_API_TRIGGER_SIGNATURE_UNUSABLE]: ['REPLACES', 'never falls back', 'flow parse refuses the flow at registration', 'names the key the spec refuses at'],
18011912
};
18021913

1803-
it('covers exactly the five ids', () => {
1914+
it('covers exactly the never-fire ids', () => {
18041915
expect(Object.keys(MOVED).sort()).toEqual([...NEVER_FIRE_IDS].sort());
18051916
});
18061917

‎packages/lint/src/validate-flow-trigger-readiness.ts‎

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
// rest of the family does not (#20611) — see its docblock for why, and see
6666
// `FLOW_API_TRIGGER_SECRET_MISSING` for why the judgement is carried here
6767
// rather than read from the runtime.
68+
// [#30009] The same rule reads the hook's ONE verifier through the spec's
69+
// `apiTriggerVerifierOf`, the reader the engine and the trigger share: a
70+
// start node that declares its sender's own scheme (`config.signature`)
71+
// is ready on the key `config.secretRef` names and nothing else, and one
72+
// whose declaration the reader answers `unusable` is never ready
73+
// (`flow-api-trigger-signature-unusable`).
6874
//
6975
// ⚠️ One more rule lived here and is RETIRED (#17396):
7076
// `flow-schedule-organization-missing`, a `warning` on a time-triggered
@@ -180,6 +186,8 @@ import {
180186
API_TRIGGER_SECRET_REF_KEY,
181187
TimeRelativeTriggerSchema,
182188
apiTriggerSecretRefOf,
189+
apiTriggerSignatureRefusals,
190+
apiTriggerVerifierOf,
183191
resolveFlowTriggerKind,
184192
} from '@objectstack/spec/automation';
185193
import { closureDependencyRemedy, recordsOf, suggestName } from './object-graph.js';
@@ -298,6 +306,17 @@ export const FLOW_TRIGGER_UNROUTABLE = 'flow-trigger-unroutable';
298306
* with the engine, so this rule restates no grammar for it.
299307
*/
300308
export const FLOW_API_TRIGGER_SECRET_MISSING = 'flow-api-trigger-secret-missing';
309+
/**
310+
* #30009 — a flow bound to the inbound `api` trigger whose start node declares
311+
* its sender's own signature scheme (`config.signature`) in a form the spec
312+
* refuses: `apiTriggerVerifierOf` answers `unusable`. The engine's flow parse
313+
* refuses the flow at registration, and a trigger handed it anyway arms a
314+
* hook that refuses every post `401 INVALID_SIGNATURE` and never falls back
315+
* to `x-objectstack-signature`, so it never receives a post. The verdict is
316+
* the spec's own reader, shared with the engine and the trigger, so this rule
317+
* restates none of the declaration's grammar.
318+
*/
319+
export const FLOW_API_TRIGGER_SIGNATURE_UNUSABLE = 'flow-api-trigger-signature-unusable';
301320

302321
type AnyRec = Record<string, unknown>;
303322

@@ -1055,17 +1074,30 @@ export function validateFlowApiTriggerSecret(
10551074
const triggerType = typeof config.triggerType === 'string' ? config.triggerType : undefined;
10561075
const bindsApiTrigger = !isArrayRecordTriggerType(config) && resolveFlowTriggerKind(flow) === 'api';
10571076
const secretPath = start ? `flows[${flowIndex}].nodes[${start.index}].config.secret` : undefined;
1058-
// [#20611] Withheld and stored ⇒ present: the host restores the stored
1059-
// secret at exactly this position before the item is persisted.
1060-
if (secretPath !== undefined && options.restoredCredentialPaths?.has(secretPath)) return;
1061-
const secretProblem = bindsApiTrigger ? describeUnusableSecret(start, config) : undefined;
1062-
if (!secretProblem) return;
10631077
// Which declaration binds it — the engine's own message names the same
10641078
// two, so an author who meets both channels reads one story.
10651079
const binds = [
10661080
flow.type === 'api' ? `type: 'api'` : undefined,
10671081
triggerType === 'api' ? `start-node triggerType: 'api'` : undefined,
10681082
].filter((s): s is string => s !== undefined);
1083+
// [#30009] The hook's ONE verifier, by the spec's reader the engine and
1084+
// the trigger share. Judged before the withheld-secret shortcut below: a
1085+
// declared scheme's key is only ever `config.secretRef`, never the stored
1086+
// literal that shortcut stands for.
1087+
const verifier = bindsApiTrigger && start ? apiTriggerVerifierOf(config) : undefined;
1088+
if (verifier?.kind === 'unusable') {
1089+
findings.push(signatureUnusableFinding(flow, flowIndex, flowName, start!, binds));
1090+
return;
1091+
}
1092+
// A declared scheme verifies under the key `config.secretRef` names, which
1093+
// `apiTriggerVerifierOf` has already found usable: the hook is ready, and
1094+
// no literal or withheld secret is consulted for it.
1095+
if (verifier?.kind === 'declared') return;
1096+
// [#20611] Withheld and stored ⇒ present: the host restores the stored
1097+
// secret at exactly this position before the item is persisted.
1098+
if (secretPath !== undefined && options.restoredCredentialPaths?.has(secretPath)) return;
1099+
const secretProblem = bindsApiTrigger ? describeUnusableSecret(start, config) : undefined;
1100+
if (!secretProblem) return;
10691101
findings.push({
10701102
// `error` — the never-fire family, and the strongest verdict in it: the
10711103
// engine does not merely leave this flow unfired, it refuses to register
@@ -1089,3 +1121,42 @@ export function validateFlowApiTriggerSecret(
10891121
});
10901122
return findings;
10911123
}
1124+
1125+
/**
1126+
* The 1h finding for an `api`-bound start node whose `config.signature` the
1127+
* spec's reader answers `unusable` ({@link FLOW_API_TRIGGER_SIGNATURE_UNUSABLE}).
1128+
* Located at the first refusal the spec's own judge raises for that node; a
1129+
* node the judge raises nothing for is unusable because its
1130+
* `config.secretRef` is, and is located there. The verdict names the key, not
1131+
* the refusal's prose: the flow parse already prints that in full, and a
1132+
* verdict here stays one line (#22161).
1133+
*/
1134+
function signatureUnusableFinding(
1135+
flow: AnyRec,
1136+
flowIndex: number,
1137+
flowName: string,
1138+
start: { node: AnyRec; index: number },
1139+
binds: readonly string[],
1140+
): FlowTriggerReadinessFinding {
1141+
const nodePrefix = ['nodes', start.index, 'config'];
1142+
const own = apiTriggerSignatureRefusals(flow).find((r) => nodePrefix.every((seg, i) => r.path[i] === seg));
1143+
const keyPath = own
1144+
? own.path.slice(2).reduce<string>((acc, seg) => (typeof seg === 'number' ? `${acc}[${seg}]` : `${acc}.${seg}`), '').slice(1)
1145+
: `config.${API_TRIGGER_SECRET_REF_KEY}`;
1146+
return {
1147+
// `error` — the never-fire family: the engine's flow parse refuses the
1148+
// flow at registration, and the trigger admits no post to such a hook.
1149+
severity: 'error',
1150+
rule: FLOW_API_TRIGGER_SIGNATURE_UNUSABLE,
1151+
where: `flow "${flowName}" › start node`,
1152+
path: `flows[${flowIndex}].nodes[${start.index}].${keyPath}`,
1153+
// [#22161] One verdict sentence; what a declared scheme is, and why a
1154+
// broken one admits nothing, is `os explain flow-api-trigger-signature-unusable`.
1155+
message:
1156+
`binds the inbound api trigger (${binds.join(' and ')}) and declares config.signature, refused at ` +
1157+
`${keyPath}, so the engine refuses the flow and its hook admits no post`,
1158+
hint:
1159+
`Fix config.signature (its key named by config.secretRef only), or remove it to verify ` +
1160+
`x-objectstack-signature`,
1161+
};
1162+
}

0 commit comments

Comments
 (0)