Skip to content

Commit cf8111f

Browse files
MarcoDotIOclaude
andcommitted
fix(server): truncated webhook delivery bodies no longer end in a replacement character
The delivery log keeps the first 64 KiB of a request body. When that cut landed inside a multibyte UTF-8 character, the decoder turned the partial bytes into U+FFFD, so Settings showed a character the sender never sent. Decode the truncated bytes in streaming mode so the split character is dropped instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5b15cfc commit cf8111f

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎apps/server/src/scheduledTasks/ScheduledTaskService.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,8 +1380,11 @@ export const layer = Layer.effect(
13801380
const truncated = request.body.byteLength > WEBHOOK_DELIVERY_LOG_BODY_LIMIT;
13811381
return {
13821382
truncated,
1383+
// Streaming decode drops a character the byte limit split, instead of ending in U+FFFD.
13831384
body: truncated
1384-
? new TextDecoder().decode(request.body.subarray(0, WEBHOOK_DELIVERY_LOG_BODY_LIMIT))
1385+
? new TextDecoder().decode(request.body.subarray(0, WEBHOOK_DELIVERY_LOG_BODY_LIMIT), {
1386+
stream: true,
1387+
})
13851388
: request.bodyText,
13861389
};
13871390
};

‎apps/server/src/scheduledTasks/ScheduledTaskService.webhook.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,33 @@ it.effect("keeps credential headers and query values out of the delivery log", (
481481
),
482482
);
483483

484+
it.effect("drops a character split by the delivery log's body limit", () =>
485+
withService(({ service }) =>
486+
Effect.gen(function* () {
487+
const { task } = yield* service.upsert(yield* webhookTaskInput({ enabled: false }));
488+
const limit = 64 * 1024;
489+
const euro = new TextEncoder().encode("€");
490+
const body = new Uint8Array(limit - 1 + euro.length).fill(0x61);
491+
body.set(euro, limit - 1);
492+
yield* service.triggerWebhook(
493+
requestFor(task, { body, bodyText: new TextDecoder().decode(body) }),
494+
);
495+
const [summary] = (yield* service.listWebhookDeliveries({
496+
id: task.id,
497+
acceptAnyOutcome: true,
498+
})).deliveries;
499+
const { delivery } = yield* service.getWebhookDelivery({
500+
id: task.id,
501+
deliveryId: summary!.id,
502+
});
503+
assert.isTrue(delivery.bodyTruncated);
504+
assert.equal(delivery.bodyBytes, body.byteLength);
505+
assert.equal(delivery.body.slice(-3), "aaa");
506+
assert.equal(delivery.body.length, limit - 1);
507+
}),
508+
),
509+
);
510+
484511
const queuedDeliveryCases = [
485512
{
486513
change: "paused",

0 commit comments

Comments
 (0)