Skip to content

Commit c1e0b0e

Browse files
garethxclaude
andcommitted
Distinguish source types that take no verification secret
Ten types declare their auth as an empty object — they take no secret at all — and were absent from the auth map, so a supplied Webhook Secret fell back to webhook_secret_key and was rejected at activation. They need their own answer rather than the choice-of-schemes one: pointing someone at Source Config (JSON) would send them looking for a secret that does not exist. The map is now a discriminated union of fields / choice / none, so "takes no secret" and "several possible schemes" cannot be conflated by a future regeneration the way an array of field names allowed. Also removes isTestRegistration, left unreferenced when registrationFor absorbed the logic, and whose docstring still claimed execution mode was authoritative — which the same change disproved. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 52f5f56 commit c1e0b0e

4 files changed

Lines changed: 247 additions & 212 deletions

File tree

‎nodes/Hookdeck/ConnectionPayload.ts‎

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { IDataObject, IHookFunctions } from 'n8n-workflow';
1010
import { NodeOperationError } from 'n8n-workflow';
1111

1212
import { SIGNATURE_HEADER } from './Delivery';
13-
import { SOURCE_TYPE_AUTH_FIELDS } from './SourceTypes';
13+
import { SOURCE_TYPE_AUTH } from './SourceTypes';
1414

1515
/** Field a platform's verification secret belongs in. */
1616
const DEFAULT_PLATFORM_AUTH_FIELD = 'webhook_secret_key';
@@ -19,33 +19,52 @@ const DEFAULT_PLATFORM_AUTH_FIELD = 'webhook_secret_key';
1919
* Resolve which auth field a single supplied secret should populate.
2020
*
2121
* Most platforms name it `webhook_secret_key`, but a sizeable minority use
22-
* `api_key`, `public_key` or similar, and putting a secret in the wrong field is
23-
* rejected by the API at activation. A handful need more than one value, which a
24-
* single input cannot express — those are refused here with the field names, so
25-
* the message says what to do rather than surfacing a 422.
22+
* `api_key`, `public_key` or similar, and a secret in the wrong field is
23+
* rejected by the API at activation. Three cases cannot be served by a single
24+
* input at all — a type needing several values, one accepting a choice of
25+
* schemes, and one taking no secret — and each is refused with the guidance that
26+
* fits it, rather than being allowed through to surface as a 422.
2627
*/
2728
function platformAuthField(this: IHookFunctions, sourceType: string): string {
28-
const fields = SOURCE_TYPE_AUTH_FIELDS[sourceType];
29+
const shape = SOURCE_TYPE_AUTH[sourceType];
2930

3031
// Not in the map at all: an unknown or newer type. The common field is the
3132
// best available guess, and the API says so plainly if it is wrong.
32-
if (!fields) return DEFAULT_PLATFORM_AUTH_FIELD;
33-
34-
if (fields.length === 1) return fields[0];
33+
if (!shape) return DEFAULT_PLATFORM_AUTH_FIELD;
34+
35+
if (shape.kind === 'none') {
36+
throw new NodeOperationError(
37+
this.getNode(),
38+
`${sourceType} does not take a verification secret`,
39+
{
40+
description:
41+
'Leave Webhook Secret empty. Hookdeck verifies this platform without one, and sending a secret it does not expect is rejected.',
42+
},
43+
);
44+
}
3545

36-
const reason =
37-
fields.length === 0
38-
? `${sourceType} accepts a choice of verification schemes, so a single secret cannot say which one to use`
39-
: `${sourceType} verification needs more than one value, so Webhook Secret cannot express it`;
46+
if (shape.kind === 'choice') {
47+
throw new NodeOperationError(
48+
this.getNode(),
49+
`${sourceType} accepts a choice of verification schemes, so a single secret cannot say which one to use`,
50+
{
51+
description:
52+
'Clear Webhook Secret and set Options → Source Config (JSON) to {"auth_type": "HMAC", "auth": { … }}, naming the scheme you want.',
53+
},
54+
);
55+
}
4056

41-
const shape =
42-
fields.length === 0
43-
? '"auth_type": "HMAC", "auth": { … }'
44-
: `"auth_type": "${sourceType}", "auth": {${fields.map((f) => `"${f}": "…"`).join(', ')}}`;
57+
if (shape.fields.length === 1) return shape.fields[0];
4558

46-
throw new NodeOperationError(this.getNode(), reason, {
47-
description: `Clear Webhook Secret and set Options → Source Config (JSON) to {${shape}}.`,
48-
});
59+
throw new NodeOperationError(
60+
this.getNode(),
61+
`${sourceType} verification needs more than one value, so Webhook Secret cannot express it`,
62+
{
63+
description: `Clear Webhook Secret and set Options → Source Config (JSON) to {"auth_type": "${sourceType}", "auth": {${shape.fields
64+
.map((f) => `"${f}": "…"`)
65+
.join(', ')}}}.`,
66+
},
67+
);
4968
}
5069

5170
/**

‎nodes/Hookdeck/Naming.ts‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,6 @@ export function isTestWebhookUrl(url: string): boolean {
4646
return url.includes('/webhook-test/');
4747
}
4848

49-
/**
50-
* Whether a registration belongs to an editor test listen rather than a
51-
* published workflow.
52-
*
53-
* The execution mode is the authoritative signal — n8n reports `manual` only for
54-
* a test listen — and unlike the URL it is unaffected by an instance renaming
55-
* its test endpoint via `N8N_ENDPOINT_WEBHOOK_TEST`. The path check is kept as a
56-
* fallback in case a deployment reports some other mode.
57-
*
58-
* Getting this wrong is expensive: a test run filed as production repoints the
59-
* live connection at a URL that stops answering after 120 seconds.
60-
*/
61-
export function isTestRegistration(executionMode: string, webhookUrl: string): boolean {
62-
return executionMode === 'manual' || isTestWebhookUrl(webhookUrl);
63-
}
64-
6549
/**
6650
* Reasons Hookdeck could not deliver to a given n8n URL, or undefined if it can.
6751
*

0 commit comments

Comments
 (0)