Skip to content

Open-source document signature platform. Not affiliated with DocuSign.

TypeScript

Refuse a webhook log cursor too large for Postgres

Claude4efb5cbabc15
diff --git a/src/lib/webhooks/log.ts b/src/lib/webhooks/log.ts
index 8c9f52b..d9f29a5 100644
--- a/src/lib/webhooks/log.ts
+++ b/src/lib/webhooks/log.ts
@@ -110,7 +110,10 @@ function decodeCursor(
const createdAt = Number(decoded.slice(0, separator));
const id = decoded.slice(separator + 1);
- return separator > 0 && Number.isInteger(createdAt) && id.startsWith("msg_")
+ return separator > 0 &&
+ Number.isSafeInteger(createdAt) &&
+ createdAt >= 0 &&
+ id.startsWith("msg_")
? { createdAt, id }
: null;
}
diff --git a/src/lib/webhooks/webhooks.dbtest.ts b/src/lib/webhooks/webhooks.dbtest.ts
index ab3e1ba..ebf5ef7 100644
--- a/src/lib/webhooks/webhooks.dbtest.ts
+++ b/src/lib/webhooks/webhooks.dbtest.ts
@@ -598,6 +598,19 @@ test("a test event is sent at once, tried once, and left out of the API list", a
await listApiWebhookDeliveries({ cursor: "nonsense", limit: 10 }, database),
null,
);
+ // Too large for Postgres: refused, not a server error.
+ assert.equal(
+ await listApiWebhookDeliveries(
+ {
+ cursor: Buffer.from("100000000000000000000:msg_x").toString(
+ "base64url",
+ ),
+ limit: 10,
+ },
+ database,
+ ),
+ null,
+ );
});
test("the API list pages with a cursor", async () => {