/** * AUDIT A2 — a stranger with no account (owner direction, 28 Nov 2026). The object door caps a sign-in call's body at * SIGN_IN_BODY_MAX (index.ts, boundedBody), but the open host read the whole body through readJson: a stranger could * make cottondb.com read an arbitrarily large body on routes that need no credential (/v1/code, /v1/sign-in, * /v1/approval/*, /v1/passkey/sign-in, /v1/delete). Now those routes are bounded at the open host too. */import { SELF } from"cloudflare:test";import { describe, expect, it } from"vitest";import { SIGN_IN_BODY_MAX } from"../src/http.ts";const OPEN = "https://cottondb.com";const tooBig = "A".repeat(SIGN_IN_BODY_MAX + 1024);asyncfunction post(path: string, body: unknown): Promise<Response> {return SELF.fetch(`${OPEN}${path}`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) });}describe("a stranger's oversized body at the open host", () => { it("is refused 413 on /v1/code, not read in full", async () => {const res = await post("/v1/code", { phone: "+919000009001", device_id: tooBig }); expect(res.status).toBe(413); expect(((await res.json()) as { code: string }).code).toBe("too_large"); }); it("is refused 413 on /v1/sign-in", async () => {const res = await post("/v1/sign-in", { database_id: "x", pad: tooBig }); expect(res.status).toBe(413); }); it("is refused 413 on /v1/approval/ask", async () => {const res = await post("/v1/approval/ask", { phone: "+919000009002", device_id: "d", pad: tooBig }); expect(res.status).toBe(413); }); it("is refused 413 on /v1/passkey/sign-in", async () => {const res = await post("/v1/passkey/sign-in", { challenge_id: "x", device_id: "d", response: {}, pad: tooBig }); expect(res.status).toBe(413); }); it("still takes a normal small sign-in body", async () => {const res = await post("/v1/code", { phone: "+919000009009", device_id: "d" }); expect(res.status).toBe(200); });});