Skip to content

Commit ce07e1f

Browse files
committed
fix(spec): config.signature refuses x-objectstack-signature and the reserved headers as its header
Contract review round 1. A declared header naming x-objectstack-signature, in any case, re-admitted the body-only sha256= form that ruling B on #22805 refuses inbound; it is now refused at parse, as is a closed list of credential, routing, framing and idempotency headers (API_TRIGGER_SIGNATURE_RESERVED_HEADERS). The contract states that a repeated header is verified as its one comma-joined value, and that an unusable declaration answers the same 401 INVALID_SIGNATURE. Claude-Session: https://claude.ai/code/session_01WGufzggC8errMtPRYBUmoY Co-authored-by: Claude <noreply@anthropic.com>
1 parent db0c0f8 commit ce07e1f

7 files changed

Lines changed: 150 additions & 24 deletions

File tree

‎.changeset/29983-api-trigger-signature.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ An inbound `api` hook admitted a post only by ObjectStack's own `x-objectstack-s
1414
- `signs: 'body'`: the raw body alone, the whole header value (after an optional `prefix`) is the digest. DocuSign Connect: `{ signs: 'body', header: 'X-DocuSign-Signature-1', algorithm: 'hmac-sha256', encoding: 'base64' }`.
1515
- `signs: 'timestamp.body'`: `T.RAW_BODY`, the header being `NAME=value` elements whose `timestampElement` carries `T` and whose `digestElement` carries the digest. Stripe-style: `{ signs: 'timestamp.body', header: 'Stripe-Signature', algorithm: 'hmac-sha256', encoding: 'hex', timestampElement: 't', digestElement: 'v1' }`.
1616

17-
The key is the start node's `config.secretRef`, as for an ObjectStack-signed hook. Declared, the scheme REPLACES the `x-objectstack-signature` check for that hook (one verifier per hook, never optional). The flow parse refuses a `signature` with no `secretRef`, one beside a literal `secret`, an algorithm other than `hmac-sha256`, an encoding other than `hex` or `base64`, a `timestamp.body` scheme with no `timestampElement` (or no `digestElement`, or the same name for both), a body-only scheme that names a timestamp element, and one on a flow that binds no `api` trigger.
17+
The key is the start node's `config.secretRef`, as for an ObjectStack-signed hook. Declared, the scheme REPLACES the `x-objectstack-signature` check for that hook (one verifier per hook, never optional). The flow parse refuses a `signature` with no `secretRef`, one beside a literal `secret`, an algorithm other than `hmac-sha256`, an encoding other than `hex` or `base64`, a `timestamp.body` scheme with no `timestampElement` (or no `digestElement`, or the same name for both), a body-only scheme that names a timestamp element, a `header` naming `x-objectstack-signature` or another reserved header (`authorization`, `proxy-authorization`, `cookie`, `host`, `content-length`, `transfer-encoding`, `x-idempotency-key`) in any case, and one on a flow that binds no `api` trigger.
1818

19-
New exports from `@objectstack/spec/automation`: `ApiTriggerSignatureSchema`, `ApiTriggerSignature`, its two arms `ApiTriggerBodySignatureSchema` / `ApiTriggerBodySignature` and `ApiTriggerTimestampedSignatureSchema` / `ApiTriggerTimestampedSignature`, `API_TRIGGER_SIGNATURE_KEY`, `apiTriggerVerifierOf` (the one reader of which verifier a hook has: `objectstack-signature`, `declared` or `unusable`), `ApiTriggerVerifier`, `apiTriggerSignatureRefusals` and `ApiTriggerSignatureRefusal`. The `ITriggerApiService.handleInboundHook` contract text states what the implementer owes: a constant-time compare of the decoded 32 bytes, the same 300-second window as `x-objectstack-signature` for a scheme that signs a timestamp, no replay window for a body-only scheme, and the one `401 INVALID_SIGNATURE` for every failure.
19+
New exports from `@objectstack/spec/automation`: `ApiTriggerSignatureSchema`, `ApiTriggerSignature`, its two arms `ApiTriggerBodySignatureSchema` / `ApiTriggerBodySignature` and `ApiTriggerTimestampedSignatureSchema` / `ApiTriggerTimestampedSignature`, `API_TRIGGER_SIGNATURE_KEY`, `API_TRIGGER_SIGNATURE_RESERVED_HEADERS`, `apiTriggerVerifierOf` (the one reader of which verifier a hook has: `objectstack-signature`, `declared` or `unusable`), `ApiTriggerVerifier`, `apiTriggerSignatureRefusals` and `ApiTriggerSignatureRefusal`. The `ITriggerApiService.handleInboundHook` contract text states what the implementer owes: a constant-time compare of the decoded 32 bytes, the same 300-second window as `x-objectstack-signature` for a scheme that signs a timestamp, no replay window for a body-only scheme, a repeated header read as its one comma-joined value, and the one `401 INVALID_SIGNATURE` for every failure, an unusable declaration included.
2020

2121
This release declares the key; the `api` trigger does not verify it yet. Until it does, a hook that declares `signature` is still verified by `x-objectstack-signature` alone, so every post its vendor sends is refused `401`, and none is admitted unverified.

‎content/docs/references/automation/api-trigger-signature.mdx‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ Refusals, each anchored on the start node's `config.signature`:
4949
scheme that names one, an undeclared key;
5050
- a `timestamp.body` scheme whose timestamp and digest are the same
5151
element of the header;
52+
- a `header` that names `x-objectstack-signature`, in any case: the
53+
platform's own header, whose body-only `sha256=` form ruling B on #22805
54+
refuses inbound, so no declaration may re-admit it there without a
55+
replay bound; or another reserved header
56+
(`API_TRIGGER_SIGNATURE_RESERVED_HEADERS`: the request's
57+
credentials, routing or framing, or the hook's idempotency key);
5258
- a verifier with no key reference (`config.secretRef` absent);
5359
- a verifier beside a literal `config.secret`: an inline key, and a second
5460
source for the one key the hook has;
@@ -84,7 +90,7 @@ A sender that signs the raw body alone (DocuSign Connect, a GitHub-style `sha256
8490
| Property | Type | Required | Description |
8591
| :--- | :--- | :--- | :--- |
8692
| **signs** | `'body'` | ✅ | The sender signs the raw body alone. No replay window applies. |
87-
| **header** | `string` | ✅ | The HTTP header the sender puts its signature in (`X-DocuSign-Signature-1`, `Stripe-Signature`), matched without regard to case. The hook reads this header and never `x-objectstack-signature`. |
93+
| **header** | `string` | ✅ | The HTTP header the sender puts its signature in (`X-DocuSign-Signature-1`, `Stripe-Signature`), matched without regard to case. The hook reads this header and never `x-objectstack-signature`. A reserved name is refused, in any case: `x-objectstack-signature`, `authorization`, `proxy-authorization`, `cookie`, `host`, `content-length`, `transfer-encoding` and `x-idempotency-key`. |
8894
| **algorithm** | `Enum<'hmac-sha256'>` | ✅ | The MAC the sender computes under the key `config.secretRef` names. `hmac-sha256` is the only one. |
8995
| **encoding** | `Enum<'hex' \| 'base64'>` | ✅ | How the sender writes the digest in the header: `hex` or `base64` (the RFC 4648 standard alphabet). The digest is decoded and compared as the 32 bytes of the HMAC. |
9096
| **prefix** | `string` | optional | Literal text the sender writes before the digest in the header value (`sha256=` for a GitHub-style sender), checked and removed before decoding. Absent: the whole value is the digest. |
@@ -109,7 +115,7 @@ A sender that signs the raw body alone (DocuSign Connect, a GitHub-style `sha256
109115
| Property | Type | Required | Description |
110116
| :--- | :--- | :--- | :--- |
111117
| **signs** | `'body'` | ✅ | The sender signs the raw body alone. No replay window applies. |
112-
| **header** | `string` | ✅ | The HTTP header the sender puts its signature in (`X-DocuSign-Signature-1`, `Stripe-Signature`), matched without regard to case. The hook reads this header and never `x-objectstack-signature`. |
118+
| **header** | `string` | ✅ | The HTTP header the sender puts its signature in (`X-DocuSign-Signature-1`, `Stripe-Signature`), matched without regard to case. The hook reads this header and never `x-objectstack-signature`. A reserved name is refused, in any case: `x-objectstack-signature`, `authorization`, `proxy-authorization`, `cookie`, `host`, `content-length`, `transfer-encoding` and `x-idempotency-key`. |
113119
| **algorithm** | `Enum<'hmac-sha256'>` | ✅ | The MAC the sender computes under the key `config.secretRef` names. `hmac-sha256` is the only one. |
114120
| **encoding** | `Enum<'hex' \| 'base64'>` | ✅ | How the sender writes the digest in the header: `hex` or `base64` (the RFC 4648 standard alphabet). The digest is decoded and compared as the 32 bytes of the HMAC. |
115121
| **prefix** | `string` | optional | Literal text the sender writes before the digest in the header value (`sha256=` for a GitHub-style sender), checked and removed before decoding. Absent: the whole value is the digest. |
@@ -125,7 +131,7 @@ A sender that signs `<t>.<raw body>` and writes `t` beside the digest as `NAME=v
125131
| Property | Type | Required | Description |
126132
| :--- | :--- | :--- | :--- |
127133
| **signs** | `'timestamp.body'` | ✅ | The sender signs `<t>.<raw body>`, `t` read from `timestampElement`. The replay window applies. |
128-
| **header** | `string` | ✅ | The HTTP header the sender puts its signature in (`X-DocuSign-Signature-1`, `Stripe-Signature`), matched without regard to case. The hook reads this header and never `x-objectstack-signature`. |
134+
| **header** | `string` | ✅ | The HTTP header the sender puts its signature in (`X-DocuSign-Signature-1`, `Stripe-Signature`), matched without regard to case. The hook reads this header and never `x-objectstack-signature`. A reserved name is refused, in any case: `x-objectstack-signature`, `authorization`, `proxy-authorization`, `cookie`, `host`, `content-length`, `transfer-encoding` and `x-idempotency-key`. |
129135
| **algorithm** | `Enum<'hmac-sha256'>` | ✅ | The MAC the sender computes under the key `config.secretRef` names. `hmac-sha256` is the only one. |
130136
| **encoding** | `Enum<'hex' \| 'base64'>` | ✅ | How the sender writes the digest in the header: `hex` or `base64` (the RFC 4648 standard alphabet). The digest is decoded and compared as the 32 bytes of the HMAC. |
131137
| **timestampElement** | `string` | ✅ | Where the timestamp comes from: the NAME of the header element `NAME=<unix seconds>` (`t`). Its value, exactly as received, is the `<t>` of the signed `<t>.<raw body>`. |
@@ -145,7 +151,7 @@ A sender that signs `<t>.<raw body>` and writes `t` beside the digest as `NAME=v
145151
| Property | Type | Required | Description |
146152
| :--- | :--- | :--- | :--- |
147153
| **signs** | `'timestamp.body'` | ✅ | The sender signs `<t>.<raw body>`, `t` read from `timestampElement`. The replay window applies. |
148-
| **header** | `string` | ✅ | The HTTP header the sender puts its signature in (`X-DocuSign-Signature-1`, `Stripe-Signature`), matched without regard to case. The hook reads this header and never `x-objectstack-signature`. |
154+
| **header** | `string` | ✅ | The HTTP header the sender puts its signature in (`X-DocuSign-Signature-1`, `Stripe-Signature`), matched without regard to case. The hook reads this header and never `x-objectstack-signature`. A reserved name is refused, in any case: `x-objectstack-signature`, `authorization`, `proxy-authorization`, `cookie`, `host`, `content-length`, `transfer-encoding` and `x-idempotency-key`. |
149155
| **algorithm** | `Enum<'hmac-sha256'>` | ✅ | The MAC the sender computes under the key `config.secretRef` names. `hmac-sha256` is the only one. |
150156
| **encoding** | `Enum<'hex' \| 'base64'>` | ✅ | How the sender writes the digest in the header: `hex` or `base64` (the RFC 4648 standard alphabet). The digest is decoded and compared as the 32 bytes of the HMAC. |
151157
| **timestampElement** | `string` | ✅ | Where the timestamp comes from: the NAME of the header element `NAME=<unix seconds>` (`t`). Its value, exactly as received, is the `<t>` of the signed `<t>.<raw body>`. |

‎packages/spec/api-surface/automation.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"API_TRIGGER_SECRET_REF_KEY (const)",
66
"API_TRIGGER_SECRET_REF_RESERVED_PREFIX (const)",
77
"API_TRIGGER_SIGNATURE_KEY (const)",
8+
"API_TRIGGER_SIGNATURE_RESERVED_HEADERS (const)",
89
"APPROVAL_BRANCH_LABELS (const)",
910
"APPROVAL_NODE_TYPE (const)",
1011
"APPROVAL_REVISE_NODE_TYPE (const)",

‎packages/spec/export-origins/automation.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"API_TRIGGER_SECRET_REF_KEY": "src/automation/api-trigger-secret-ref.zod.ts#API_TRIGGER_SECRET_REF_KEY (const)",
66
"API_TRIGGER_SECRET_REF_RESERVED_PREFIX": "src/automation/api-trigger-secret-ref.zod.ts#API_TRIGGER_SECRET_REF_RESERVED_PREFIX (const)",
77
"API_TRIGGER_SIGNATURE_KEY": "src/automation/api-trigger-signature.zod.ts#API_TRIGGER_SIGNATURE_KEY (const)",
8+
"API_TRIGGER_SIGNATURE_RESERVED_HEADERS": "src/automation/api-trigger-signature.zod.ts#API_TRIGGER_SIGNATURE_RESERVED_HEADERS (const)",
89
"APPROVAL_BRANCH_LABELS": "src/automation/approval.zod.ts#APPROVAL_BRANCH_LABELS (const)",
910
"APPROVAL_NODE_TYPE": "src/automation/approval.zod.ts#APPROVAL_NODE_TYPE (const)",
1011
"APPROVAL_REVISE_NODE_TYPE": "src/automation/approval.zod.ts#APPROVAL_REVISE_NODE_TYPE (const)",

‎packages/spec/src/automation/api-trigger-signature.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { describe, expect, it } from 'vitest';
44
import {
55
API_TRIGGER_SIGNATURE_KEY,
6+
API_TRIGGER_SIGNATURE_RESERVED_HEADERS,
67
ApiTriggerSignatureSchema,
78
apiTriggerSignatureRefusals,
89
apiTriggerVerifierOf,
@@ -204,6 +205,48 @@ describe('refused at parse, at the start node config.signature', () => {
204205
}
205206
});
206207

208+
it('a header naming x-objectstack-signature, in any case: the body-only sha256= form stays refused on it (ruling B on #22805)', () => {
209+
for (const header of ['x-objectstack-signature', 'X-Objectstack-Signature', 'X-OBJECTSTACK-SIGNATURE']) {
210+
// The platform's own header in its body-only `sha256=` form, declared: what the hook's own check refuses.
211+
const declared = { ...KEYED, signature: { ...GITHUB_STYLE, header } };
212+
const issues = refusalsUnderSignature(FlowSchema.safeParse(flow('api', declared)));
213+
expect(pathsOf(issues)).toEqual(['nodes.0.config.signature.header']);
214+
expect(issues[0]!.message).toMatch(/ruling B on #22805/);
215+
expect(apiTriggerVerifierOf(declared)).toEqual({ kind: 'unusable' });
216+
const timestamped = refusalsUnderSignature(FlowSchema.safeParse(flow('api', { ...KEYED, signature: { ...STRIPE_STYLE, header } })));
217+
expect(pathsOf(timestamped)).toEqual(['nodes.0.config.signature.header']);
218+
}
219+
});
220+
221+
it('a header that carries the request credentials, routing or framing, or the idempotency key: a closed list, in any case', () => {
222+
expect([...API_TRIGGER_SIGNATURE_RESERVED_HEADERS]).toEqual([
223+
'x-objectstack-signature',
224+
'authorization',
225+
'proxy-authorization',
226+
'cookie',
227+
'host',
228+
'content-length',
229+
'transfer-encoding',
230+
'x-idempotency-key',
231+
]);
232+
expect(Object.isFrozen(API_TRIGGER_SIGNATURE_RESERVED_HEADERS)).toBe(true);
233+
for (const name of API_TRIGGER_SIGNATURE_RESERVED_HEADERS.slice(1)) {
234+
for (const header of [name, name.toUpperCase(), name.replace(/(^|-)([a-z])/g, (_, dash, c) => dash + c.toUpperCase())]) {
235+
const declared = { ...KEYED, signature: { ...DOCUSIGN, header } };
236+
const issues = refusalsUnderSignature(FlowSchema.safeParse(flow('api', declared)));
237+
expect(pathsOf(issues)).toEqual(['nodes.0.config.signature.header']);
238+
expect(issues[0]!.message).toMatch(/never a sender's signature/);
239+
expect(apiTriggerVerifierOf(declared)).toEqual({ kind: 'unusable' });
240+
}
241+
}
242+
});
243+
244+
it('a header whose name only contains a reserved one is a sender header, not reserved', () => {
245+
for (const header of ['X-Objectstack-Signature-1', 'X-Authorization-Signature', 'Signature', 'X-Cookie-Sig']) {
246+
expect(FlowSchema.safeParse(flow('api', { ...KEYED, signature: { ...DOCUSIGN, header } })).success).toBe(true);
247+
}
248+
});
249+
207250
it('a prefix with a space or a comma, or a blank one', () => {
208251
for (const prefix of ['', 'sha256 =', 'a,b']) {
209252
const issues = refusalsUnderSignature(FlowSchema.safeParse(withPrefix(prefix)));

0 commit comments

Comments
 (0)