Two boards can share one file, a created board is never saved, a non-board file loads as an empty lab, and a board named a b cannot be reached #1315

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

The persistence code reads well and carries a comment explaining why the debounce was removed (on Windows a kill
calls TerminateProcess, so nothing on a timer survives). Nobody had ever checked the disk. Four defects.

1. Two boards whose names look alike share one file

const safe = String(id).replace(/[^A-Za-z0-9._-]/g, '_');
return path.join(TOPO_DIR, safe + '.json');

a b and a_b both become a_b.json. Two boards, one file: whichever saves last wins, and after a restart only
one of them exists. Measured — POST /api/topologies {id:"a b"} and {id:"a_b"}, then a device on each:

files on disk: a_b.json, default.json     (two, not three)

2. A board that was created is not saved

POST /api/topologies {id:"lab"} answers 201 and puts the board in memory. Nothing writes it until something else
mutates it, so "make a board, name it, come back tomorrow" loses it — and GET /api/topologies will not list it
after a restart.

3. A file that parses but is not a board is adopted as an EMPTY board

const raw = body && body.topology ? body.topology : body;
const topo = Topology.fromJSON(raw);   // tolerant by design -> {} becomes an empty lab
topologies.set(id, topo);

Topology.fromJSON() is tolerant on purpose (it reads old files), so {"format":"packetforge-topology"} — or any
object without devices/links — becomes an empty board under that id. The operator opens the app and their lab
is gone, with nothing said and nothing logged. This is the read-side twin of #1309, where /load emptied the board
and reported success.

4. A board called a b can be created and then never reached again

The topology id is taken straight out of the path (parts[2]) with no decoding, so once a client percent-encodes
it — which it must — every endpoint answers 404:

POST /api/topologies {"id":"a b"}      -> 201
POST /api/topologies/a%20b/devices     -> 404  (a%20b is not a board)
GET  /api/topologies/a%20b             -> 404

Port names learned this in #1307. Boards had not.

What must be true instead

  • the file name is injective — and the id is written inside the file, so the name never has to be reversed;
  • a created board is saved when it is acknowledged;
  • the envelope is checked before a file is adopted, and a file that is not a board is left alone and named in the
    log
    (it is the operator's work; a later version may read it);
  • the path segment for a board id is percent-decoded, with a malformed escape treated as a bad request rather than
    an exception;
  • and the invariances the comment claims are tested from outside: every mutating endpoint has written its change by
    the time it answers, and a SIGKILL immediately after an answer loses nothing.
The persistence code reads well and carries a comment explaining why the debounce was removed (on Windows a kill calls TerminateProcess, so nothing on a timer survives). Nobody had ever checked the disk. Four defects. ## 1. Two boards whose names look alike share one file ```js const safe = String(id).replace(/[^A-Za-z0-9._-]/g, '_'); return path.join(TOPO_DIR, safe + '.json'); ``` `a b` and `a_b` both become `a_b.json`. Two boards, one file: whichever saves last wins, and after a restart only one of them exists. Measured — `POST /api/topologies {id:"a b"}` and `{id:"a_b"}`, then a device on each: ``` files on disk: a_b.json, default.json (two, not three) ``` ## 2. A board that was created is not saved `POST /api/topologies {id:"lab"}` answers 201 and puts the board in memory. Nothing writes it until something else mutates it, so "make a board, name it, come back tomorrow" loses it — and `GET /api/topologies` will not list it after a restart. ## 3. A file that parses but is not a board is adopted as an EMPTY board ```js const raw = body && body.topology ? body.topology : body; const topo = Topology.fromJSON(raw); // tolerant by design -> {} becomes an empty lab topologies.set(id, topo); ``` `Topology.fromJSON()` is tolerant on purpose (it reads old files), so `{"format":"packetforge-topology"}` — or any object without `devices`/`links` — becomes an empty board under that id. The operator opens the app and their lab is gone, with nothing said and nothing logged. This is the read-side twin of #1309, where `/load` emptied the board and reported success. ## 4. A board called `a b` can be created and then never reached again The topology id is taken straight out of the path (`parts[2]`) with no decoding, so once a client percent-encodes it — which it must — every endpoint answers 404: ``` POST /api/topologies {"id":"a b"} -> 201 POST /api/topologies/a%20b/devices -> 404 (a%20b is not a board) GET /api/topologies/a%20b -> 404 ``` Port names learned this in #1307. Boards had not. ## What must be true instead * the file name is injective — and the id is written inside the file, so the name never has to be reversed; * a created board is saved when it is acknowledged; * the envelope is checked before a file is adopted, and a file that is not a board is **left alone and named in the log** (it is the operator's work; a later version may read it); * the path segment for a board id is percent-decoded, with a malformed escape treated as a bad request rather than an exception; * and the invariances the comment claims are tested from outside: every mutating endpoint has written its change by the time it answers, and a SIGKILL immediately after an answer loses nothing.
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#1315
No description provided.