A board's name is a name: the create door validates it, and the list is all strings (#1506) #1581
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jaylouisw/packetforge!1581
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/1116-0136"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #1506
POST /api/topologiestook the id from a JSON body and stored it unexamined, so{"id":123}set a NUMBER map key that no URL could reach,{"id":{"a":1}}wrote_object_Object_-<hash>.jsonand put an object in the list of ids,{"id":"."}wrote..json, and a 400-character name was acknowledged with 201 and then failed every save with ENOENT behind a console.error.boardIdProblem()now states the rule once, next to the file-name derivation that depends on it: a caller-chosen name is a string, non-empty after trimming, at most 128 characters (so<sanitised>-<hash>.jsonstays inside NAME_MAX), free of control characters, and not.or... A refusal is400 {"error": �, "field": "id"}naming the rule that was broken. An absent, null or empty id still means "make me one".GET /api/topologiesreturns only string keys.test/board-id-is-a-name.test.js, 65 passed / 0 failed; against the old handler 32 of those 65 fail (nine refused shapes all answered 201, the list held a number, a boolean, an object, an array and
..).Full suite 261 suites / 9503 assertions / 0 failed; syntax 331 files; check-control-bytes clean; api-errors 13/13, server-persistence 13/13, persistence 27/27, api-config-door 24/24, api-change-clock 12/12.
`POST /api/topologies` took the id from a JSON body, which is not a URL, and stored it unexamined. Three kinds of board could be created that nothing downstream could honour: {"id": 123} a NUMBER map key, 123.json written, and GET /api/topologies/123 404s - every lookup builds its key from a URL segment, a string {"id": {"a": 1}} `_object_Object_-<hash>.json`, and an object in the list of ids {"id": "."} `..json`, i.e. a file named after a directory and a 400-character name was acknowledged with 201 and then failed every save with ENOENT, with a console.error as the only signal. The list endpoint meanwhile handed out numbers, booleans and objects, so "list the boards" was not a list of names. Now `boardIdProblem()` states the rule once, where the file name is derived from it: a caller-chosen name is a string, non-empty after trimming, at most 128 characters (which keeps `<sanitised>-<hash>.json` inside NAME_MAX), free of control characters, and not `.` or `..`. A refusal is `400 {"error": ..., "field": "id"}` and the message names the rule that was broken, not "invalid id". An absent, null or empty id still means "make me one", which is what the client asks for. `GET /api/topologies` returns only string keys. The control-character test is a code-point loop rather than a character class: a class holding a literal NUL is a collapse waiting to happen in the next scripted edit, and check-control-bytes.js was right to refuse the first version of it. test/board-id-is-a-name.test.js, 65 checks: nine refused shapes each get a 400 whose message names the rule; a refused create changes nothing and writes no file; the list is all strings and holds none of the refused names; `{}`, `{"id":""}`, `null` 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; every file name is inside NAME_MAX and every saved board records a string name; and after a restart the 128-character board and the one with a space are still listed and readable. Against the old handler, 32 of those 65 failed. Full suite 261 suites / 9503 assertions / 0 failed. Syntax 331 files.4218af57102154f08491