Open-source document signature platform. Not affiliated with DocuSign.
TypeScript
Refuse a void body that is not a JSON object
Claudea6c98a42c2ee
diff --git a/e2e/signing-flow.spec.ts b/e2e/signing-flow.spec.tsindex d113f82..a73fc38 100644--- a/e2e/signing-flow.spec.ts+++ b/e2e/signing-flow.spec.ts@@ -1384,13 +1384,17 @@ test("an administrator makes an API key, an app sends and downloads an envelopeawait expect(signerPage).toHaveURL(/\/sign\/[^/]+\/done/);await signer.close();- // A cut-off body is refused, never read as "no reason given".- const cutOff = await api.post(`/api/v1/envelopes/${envelope.id}/void`, {- data: '{"reason":',- headers: { ...auth, "content-type": "application/json" },- });+ // A cut-off body, or JSON that is not an object, is refused, never+ // read as "no reason given". Sent as bytes: Playwright would turn a+ // string that is not JSON into a JSON string.+ for (const data of [Buffer.from('{"reason":'), Buffer.from('"stop"')]) {+ const refused = await api.post(`/api/v1/envelopes/${envelope.id}/void`, {+ data,+ headers: { ...auth, "content-type": "application/json" },+ });- expect(cutOff.status()).toBe(400);+ expect(refused.status(), await refused.text()).toBe(400);+ }const finished = await api.get(`/api/v1/envelopes/${envelope.id}`, {headers: auth,diff --git a/src/app/api/v1/envelopes/[id]/void/route.ts b/src/app/api/v1/envelopes/[id]/void/route.tsindex fff08a9..08e149c 100644--- a/src/app/api/v1/envelopes/[id]/void/route.ts+++ b/src/app/api/v1/envelopes/[id]/void/route.ts@@ -15,8 +15,8 @@ export async function POST(request: Request, context: Context) {"write","api_envelope_void_failure",async ({ actor }) => {- // No body is fine; a body that is not JSON is refused, so a cut-off- // request never voids without the reason it meant to give.+ // No body is fine; a body that is not a JSON object is refused, so a+ // cut-off request never voids without the reason it meant to give.const text = await request.text();let body: unknown = {};@@ -32,10 +32,15 @@ export async function POST(request: Request, context: Context) {}}- const reason =- typeof body === "object" && body !== null- ? (body as { reason?: unknown }).reason- : undefined;+ if (typeof body !== "object" || body === null || Array.isArray(body)) {+ return apiError(+ 400,+ "invalid_request",+ 'The body must be a JSON object, such as {"reason": "..."}.',+ );+ }++ const reason = (body as { reason?: unknown }).reason;if (reason !== undefined &&