@relayfile/core 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/webhooks.d.ts +14 -4
- package/dist/webhooks.js +9 -1
- package/package.json +1 -1
package/dist/webhooks.d.ts
CHANGED
|
@@ -62,12 +62,22 @@ export interface IngestWebhookOptions {
|
|
|
62
62
|
generateEnvelopeId?: () => string;
|
|
63
63
|
coalesceWindowMs?: number;
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
65
|
+
* Signature verification callback. Called with the raw input before
|
|
66
|
+
* processing. Return `true` if the payload signature is valid, `false` to
|
|
67
|
+
* reject the webhook. Callers should implement HMAC/RSA verification in
|
|
68
|
+
* this callback at the HTTP handler layer.
|
|
69
|
+
*
|
|
70
|
+
* When not provided, all webhooks are rejected unless
|
|
71
|
+
* `requireSignature` is explicitly set to `false`.
|
|
69
72
|
*/
|
|
70
73
|
signatureVerifier?: (input: IngestWebhookInput) => boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Whether signature verification is required. Defaults to `true`
|
|
76
|
+
* (fail-closed). When `true` and no `signatureVerifier` is provided,
|
|
77
|
+
* all webhooks are rejected with status `"signature_missing"`.
|
|
78
|
+
* Set to `false` only in trusted/internal environments.
|
|
79
|
+
*/
|
|
80
|
+
requireSignature?: boolean;
|
|
71
81
|
}
|
|
72
82
|
export interface WebhookStorageAdapter extends StorageAdapter {
|
|
73
83
|
getEnvelopeByDelivery(workspaceId: string, provider: string, deliveryId: string): EnvelopeRow | null;
|
package/dist/webhooks.js
CHANGED
|
@@ -17,6 +17,14 @@ import { normalizePath, DEFAULT_CONTENT_TYPE, MAX_FILE_BYTES, encodedSize } from
|
|
|
17
17
|
export function ingestWebhook(storage, input, options = {}) {
|
|
18
18
|
const envelopeStorage = getWebhookStorage(storage);
|
|
19
19
|
const correlationId = input.correlationId?.trim() ?? "";
|
|
20
|
+
const requireSignature = options.requireSignature === true;
|
|
21
|
+
if (requireSignature && !options.signatureVerifier) {
|
|
22
|
+
return {
|
|
23
|
+
status: "signature_missing",
|
|
24
|
+
envelopeId: "",
|
|
25
|
+
correlationId,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
20
28
|
if (options.signatureVerifier && !options.signatureVerifier(input)) {
|
|
21
29
|
return {
|
|
22
30
|
status: "signature_invalid",
|
|
@@ -210,7 +218,6 @@ export function applyWebhookEnvelope(storage, envelope, options = {}) {
|
|
|
210
218
|
revision: null,
|
|
211
219
|
};
|
|
212
220
|
}
|
|
213
|
-
const revision = storage.nextRevision();
|
|
214
221
|
const content = typeof event.content === "string"
|
|
215
222
|
? event.content
|
|
216
223
|
: JSON.stringify(event.data ?? {});
|
|
@@ -224,6 +231,7 @@ export function applyWebhookEnvelope(storage, envelope, options = {}) {
|
|
|
224
231
|
reason: "file_too_large",
|
|
225
232
|
};
|
|
226
233
|
}
|
|
234
|
+
const revision = storage.nextRevision();
|
|
227
235
|
// Strip permissions from webhook-provided semantics to prevent
|
|
228
236
|
// external webhooks from injecting or overwriting ACL rules.
|
|
229
237
|
const semantics = normalizeSemantics(event.semantics);
|
package/package.json
CHANGED