A malformed body gets JavaScript's own words back, a 409, and one of them empties the board #1309

Closed
opened 2026-11-10 01:06:07 +00:00 by jaylouisw · 0 comments
Owner

Every test in this repository drove the engine. I drove the HTTP surface with malformed requests on purpose,
and three failures came out — one of them is data loss.

1. POST /load empties the board and says it worked

POST /api/topologies/default/load   {"format":"x"}
  -> 200 {"ok":true,"state":{"devices":[],"links":[]}}

The live topology is replaced by whatever the body says, and Topology.fromJSON() is (deliberately) tolerant, so
a document with the wrong format marker and no devices becomes an empty lab — reported as success, with the
operator's work gone. {"format":"packetforge-topology"} alone does the same. There is no shape check of any kind
before the swap.

2. A missing body is dereferenced straight through

POST /api/topologies/default/config/d1   (no body)
  -> 400 {"error":"Cannot read properties of undefined (reading 'trim')"}
POST /api/topologies/default/links       (no body)
  -> 409 {"error":"Cannot read properties of undefined (reading 'deviceId')","code":"E_LINK"}

The runtime's own words, and the second one calls a missing body a conflict. /config with {} and with
{commands:[null]} leak the same way, and {"commands":"hostname X"} (a string, not a list) turns into
[undefined]... The interface the operator reads is the JSON.

3. A request that names nothing blames a device

POST /api/topologies/default/ping   (no body)  -> 404 source device not found
POST /api/topologies/default/flows  (no body)  -> 400 "Unknown source device: undefined"

Both are 400s about a malformed request, not 404s or messages containing undefined.

The three rules that must hold

  1. a response never contains the runtime's own words — no Cannot read properties, no undefined in a
    sentence, no [object Object];
  2. the status says what the client can do — 400 for a request that does not parse, 404 for an id that does not
    exist, 409/422 for content the engine refuses;
  3. a rejected request changes nothing — in particular, a document that is not a topology must not be able to
    empty the board. Topology.fromJSON() stays tolerant (it reads old files); tolerance belongs to reading, not
    to replacing.
Every test in this repository drove the engine. I drove the HTTP surface with malformed requests on purpose, and three failures came out — one of them is data loss. ## 1. `POST /load` empties the board and says it worked ``` POST /api/topologies/default/load {"format":"x"} -> 200 {"ok":true,"state":{"devices":[],"links":[]}} ``` The live topology is replaced by whatever the body says, and `Topology.fromJSON()` is (deliberately) tolerant, so a document with the wrong format marker and no devices becomes an empty lab — reported as success, with the operator's work gone. `{"format":"packetforge-topology"}` alone does the same. There is no shape check of any kind before the swap. ## 2. A missing body is dereferenced straight through ``` POST /api/topologies/default/config/d1 (no body) -> 400 {"error":"Cannot read properties of undefined (reading 'trim')"} POST /api/topologies/default/links (no body) -> 409 {"error":"Cannot read properties of undefined (reading 'deviceId')","code":"E_LINK"} ``` The runtime's own words, and the second one calls a missing body a **conflict**. `/config` with `{}` and with `{commands:[null]}` leak the same way, and `{"commands":"hostname X"}` (a string, not a list) turns into `[undefined]`... The interface the operator reads is the JSON. ## 3. A request that names nothing blames a device ``` POST /api/topologies/default/ping (no body) -> 404 source device not found POST /api/topologies/default/flows (no body) -> 400 "Unknown source device: undefined" ``` Both are 400s about a malformed request, not 404s or messages containing `undefined`. ## The three rules that must hold 1. **a response never contains the runtime's own words** — no `Cannot read properties`, no `undefined` in a sentence, no `[object Object]`; 2. **the status says what the client can do** — 400 for a request that does not parse, 404 for an id that does not exist, 409/422 for content the engine refuses; 3. **a rejected request changes nothing** — in particular, a document that is not a topology must not be able to empty the board. `Topology.fromJSON()` stays tolerant (it reads old files); tolerance belongs to reading, not to replacing.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jaylouisw/packetforge#1309
No description provided.