A board can be created with a name that cannot be reached, listed or saved #1506

Closed
opened 2026-11-12 08:56:06 +00:00 by jaylouisw · 2 comments
Owner

What happens

POST /api/topologies accepts any truthy id because the id arrives in a JSON body, which is not a URL. Three boards can be created that nothing downstream can honour:

$ curl -s -XPOST localhost:8000/api/topologies -d '{"id": 123}'
201 {"id":123,...}                      # map key is the NUMBER 123, 123.json is written
$ curl -s localhost:8000/api/topologies/123
404 {"error":"topology not found"}       # every lookup builds its key from a URL segment, i.e. a string

$ curl -s -XPOST localhost:8000/api/topologies -d '{"id": {"a": 1}}'
201 ...                                  # object as a Map key, file `_object_Object_-c1d44ff0.json`
$ curl -s localhost:8000/api/topologies
200 {"ids":["default",123,true,{"a":1},"../../etc/passwd",...]}   # the list is not a list of names

$ curl -s -XPOST localhost:8000/api/topologies -d "{\"id\": \"$(python -c 'print("b"*400)')\"}"
201 ...                                  # accepted
# then every save: console.error `could not save topology bbbb… : ENOENT … bbbb….json.tmp`

So: a board that exists and cannot be reached by the name it was created with, a list endpoint that hands out non-strings, and a board the API acknowledges that the disk never holds — with the only signal a server-side console.error.

This is the same shape as #1315 (a b created, never reached) one layer lower: nothing validated the name where it entered.

What changes

  • server/index.js: boardIdProblem() — a caller-chosen name is a string, non-empty after trimming, ≤ 128 characters, no control characters, not a bare . or ..; anything else is 400 {"error": …, "field":"id"} naming the rule. An absent / null / "" id still means "make me one", which is what the client asks for.
  • GET /api/topologies returns only string keys, so a list of names is a list of names.
  • test/board-id-is-a-name.test.js — 45 checks.

Why 128 and not "whatever the filesystem takes"

The base name is <sanitised>-<hash>.json; 128 characters of id leaves the file name comfortably inside NAME_MAX (255) on every platform this runs on, so the save that used to fail with ENOENT cannot be reached at all. It is also long enough that no UI-generated name (topo-…) or human name comes near it.

Verification

test/board-id-is-a-name.test.js, 45 passed / 0 failed. Against the old handler: every one of the nine refusal cases answered 201.

It asserts the rule rather than today's strings: nine rejected shapes (number, boolean, object, array, whitespace-only, ., .., control character, 129 characters) each get a 400 whose message names the rule; a refused create changes nothing; the list is all strings and contains none of the refused names; {}, {"id":""} and no body still generate a name; five accepted names (including a b, a/b, Board #1 and 128 characters) are reachable by the name they were created with and creating one twice is idempotent; the files on disk are all shorter than NAME_MAX and none is a refused name; and after a restart the 128-character board and the one with a space are still listed and readable.

Full suite 250 suites / 9192 assertions / 0 failed; syntax 320 files; api-errors 13/13; server-persistence 13/13; skip-audit 15/15.

Found while fuzzing, and fine

The same sweep sent /api/topologies/..%2f..%2fetc/passwd, %E0%A4%A (a malformed escape), a 2 MB body, PATCH, an unknown endpoint, and non-JSON text: all answered with a status and a JSON body, no 500s, no hangs (invalid JSON body 400, unknown endpoint 404). The traversal attempt is not one: topologyFile() replaces / and appends a hash of the exact id, so ../../etc/passwd lands as .._.._etc_passwd-<hash>.json inside the topology directory.

## What happens `POST /api/topologies` accepts any truthy `id` because the id arrives in a JSON body, which is not a URL. Three boards can be created that nothing downstream can honour: ``` $ curl -s -XPOST localhost:8000/api/topologies -d '{"id": 123}' 201 {"id":123,...} # map key is the NUMBER 123, 123.json is written $ curl -s localhost:8000/api/topologies/123 404 {"error":"topology not found"} # every lookup builds its key from a URL segment, i.e. a string $ curl -s -XPOST localhost:8000/api/topologies -d '{"id": {"a": 1}}' 201 ... # object as a Map key, file `_object_Object_-c1d44ff0.json` $ curl -s localhost:8000/api/topologies 200 {"ids":["default",123,true,{"a":1},"../../etc/passwd",...]} # the list is not a list of names $ curl -s -XPOST localhost:8000/api/topologies -d "{\"id\": \"$(python -c 'print("b"*400)')\"}" 201 ... # accepted # then every save: console.error `could not save topology bbbb… : ENOENT … bbbb….json.tmp` ``` So: a board that exists and cannot be reached by the name it was created with, a list endpoint that hands out non-strings, and a board the API acknowledges that the disk never holds — with the only signal a server-side `console.error`. This is the same shape as #1315 (`a b` created, never reached) one layer lower: nothing validated the name where it entered. ## What changes - `server/index.js`: `boardIdProblem()` — a caller-chosen name is a **string**, non-empty after trimming, **≤ 128** characters, no control characters, not a bare `.` or `..`; anything else is `400 {"error": …, "field":"id"}` naming the rule. An absent / `null` / `""` id still means "make me one", which is what the client asks for. - `GET /api/topologies` returns only string keys, so a list of names is a list of names. - `test/board-id-is-a-name.test.js` — 45 checks. ## Why 128 and not "whatever the filesystem takes" The base name is `<sanitised>-<hash>.json`; 128 characters of id leaves the file name comfortably inside `NAME_MAX` (255) on every platform this runs on, so the save that used to fail with `ENOENT` cannot be reached at all. It is also long enough that no UI-generated name (`topo-…`) or human name comes near it. ## Verification `test/board-id-is-a-name.test.js`, **45 passed / 0 failed**. Against the old handler: every one of the nine refusal cases answered **201**. It asserts the rule rather than today's strings: nine rejected shapes (number, boolean, object, array, whitespace-only, `.`, `..`, control character, 129 characters) each get a 400 whose message names the rule; a refused create changes nothing; the list is all strings and contains none of the refused names; `{}`, `{"id":""}` and no body still generate a name; five accepted names (including `a b`, `a/b`, `Board #1` and 128 characters) are **reachable by the name they were created with** and creating one twice is idempotent; the files on disk are all shorter than `NAME_MAX` and none is a refused name; and after a **restart** the 128-character board and the one with a space are still listed and readable. Full suite **250 suites / 9192 assertions / 0 failed**; syntax 320 files; `api-errors` 13/13; `server-persistence` 13/13; `skip-audit` 15/15. ## Found while fuzzing, and fine The same sweep sent `/api/topologies/..%2f..%2fetc/passwd`, `%E0%A4%A` (a malformed escape), a 2 MB body, `PATCH`, an unknown endpoint, and non-JSON text: **all answered with a status and a JSON body, no 500s, no hangs** (`invalid JSON body` 400, `unknown endpoint` 404). The traversal attempt is not one: `topologyFile()` replaces `/` and appends a hash of the exact id, so `../../etc/passwd` lands as `.._.._etc_passwd-<hash>.json` inside the topology directory.
Author
Owner

Fixed on branch fix/board-id at fe6dc5f4 (pushed as a new ref), base 1b1e1287. Verified: 250 suites / 9192 assertions / 0 failed, syntax 320, api-errors 13/13, server-persistence 13/13, and board-id-is-a-name 45/45 (against the old handler all nine refusals answered 201).

Creating the pull request failed twice with 500 … pull.git…/.git/config: No space left on device. Three verified branches are now queued behind that one blocker:

issue branch head
#1501 fix/no-form-names-v2 c97b11b6
#1505 fix/stated-range 403b512e
#1506 fix/board-id fe6dc5f4

All three are one POST /pulls + one squash away, in that order, as soon as the volume has room for a temp clone.

**Fixed on branch `fix/board-id` at `fe6dc5f4`** (pushed as a new ref), base `1b1e1287`. Verified: 250 suites / 9192 assertions / 0 failed, syntax 320, `api-errors` 13/13, `server-persistence` 13/13, and `board-id-is-a-name` 45/45 (against the old handler all nine refusals answered `201`). Creating the pull request failed twice with `500 … pull.git…/.git/config: No space left on device`. Three verified branches are now queued behind that one blocker: | issue | branch | head | |---|---|---| | #1501 | `fix/no-form-names-v2` | `c97b11b6` | | #1505 | `fix/stated-range` | `403b512e` | | #1506 | `fix/board-id` | `fe6dc5f4` | All three are one `POST /pulls` + one squash away, in that order, as soon as the volume has room for a temp clone.
Author
Owner

Reviewing this fix before it lands found a hole in it — reported here rather than quietly amended, because the
hole is instructive.

readBody() resolves {} for an empty body and otherwise whatever JSON.parse returned, which can be null, a
number, a string or an array. body.id on null is a TypeError, so the answer to a client POSTing the eight bytes
null was:

400 {"error":"Cannot read properties of null (reading 'id')"}

— the runtime's own words, which test/api-errors.test.js forbids in a response, inside the very handler this issue
rewrote. That is the same class of defect as the one this issue is about: the boundary was being read as if it were
always the shape we expected.

Fixed on land-all-v2 (the combined branch, now @ d11d5ac4): a body that is not an object has no id, so it
means what an empty body means — make me one. Covered for five shapes (null, a number, a string, an array, true),
two checks each; board-id-is-a-name is now 55 checks, and the two new ones fail against the previous handler.
Full suite 251 suites / 9209 assertions / 0 failed; syntax 321; api-errors 13/13; server-persistence 13/13.

The three per-issue branches (fix/board-id @ fe6dc5f4) still carry the pre-review tree; the landing queue now
prefers land-all-v2, so whichever window opens lands the corrected version.

Reviewing this fix before it lands found a hole in it — reported here rather than quietly amended, because the hole is instructive. `readBody()` resolves `{}` for an empty body and otherwise **whatever `JSON.parse` returned**, which can be `null`, a number, a string or an array. `body.id` on `null` is a TypeError, so the answer to a client POSTing the eight bytes `null` was: ``` 400 {"error":"Cannot read properties of null (reading 'id')"} ``` — the runtime's own words, which `test/api-errors.test.js` forbids in a response, inside the very handler this issue rewrote. That is the same class of defect as the one this issue is about: the boundary was being read as if it were always the shape we expected. **Fixed on `land-all-v2`** (the combined branch, now @ `d11d5ac4`): a body that is not an object has no `id`, so it means what an empty body means — make me one. Covered for five shapes (`null`, a number, a string, an array, `true`), two checks each; `board-id-is-a-name` is now **55 checks**, and the two new ones fail against the previous handler. Full suite **251 suites / 9209 assertions / 0 failed**; syntax 321; `api-errors` 13/13; `server-persistence` 13/13. The three per-issue branches (`fix/board-id` @ `fe6dc5f4`) still carry the pre-review tree; the landing queue now prefers `land-all-v2`, so whichever window opens lands the corrected version.
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#1506
No description provided.