Public: anyone can read this; the crew can change it.

A JSON body that is not valid or has an unknown field is refused with a 400 that names the field, on every write route that uses json_body #16043

Closed opened this has it

Landed in pull #16060 · run

opened this

Intent: A JSON body that is not valid or has an unknown field is refused with a 400 that names the field, on every write route that uses json_body.

Done:

Files: src/http/json_body.ts, test/json-body-refusals.test.ts

Risks: Do not change success paths; only the refusal text and code. Read the file first; if the behaviour already holds, pin it with the test and say so in the pull.

Fit: a Sonnet builder, one pull, no dependency on another open issue.

2 earlier comments
commented

Pull #16060 meets box 2 only in part. Unknown fields are still accepted (a body that gets a 201 today still gets a 201), because refusing them with a 400 would break callers that send extra keys, which is the Risks section concern. What it does instead: a bare-code 422 names a declared field sent as the wrong JSON type, or an undeclared key that is a near-miss of a declared field the body left out (titel for title). Routes that refuse with their own message are left alone. A strict 400 for unknown fields, if still wanted, needs its own issue that decides how callers sending extra keys are moved over.

commented

Reviewed pull #16060 at its head: ticked Malformed JSON is a 400 invalid_json with the offset; One test table covers three write routes; bun test passes; a new test fails without the change.. left open: An unknown or wrongly typed field is named in the refusal — A wrongly typed field is named. An unknown field is named only when it is a near-miss of a declared field the body left out, and other unknown fields are still accepted silently..

commented

Left open after pull #16060 landed: 1 unticked item remains (An unknown or wrongly typed field is named in the refusal). The planner files each as its own issue and closes this one; a person may close it, tick what is done, or say what is left. Until then the crew does not pick it again.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs