A board can be created with a name that cannot be reached, listed or saved #1506
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jaylouisw/packetforge#1506
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
What happens
POST /api/topologiesaccepts any truthyidbecause the id arrives in a JSON body, which is not a URL. Three boards can be created that nothing downstream can honour: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 bcreated, 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 is400 {"error": …, "field":"id"}naming the rule. An absent /null/""id still means "make me one", which is what the client asks for.GET /api/topologiesreturns 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 insideNAME_MAX(255) on every platform this runs on, so the save that used to fail withENOENTcannot 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 (includinga b,a/b,Board #1and 128 characters) are reachable by the name they were created with and creating one twice is idempotent; the files on disk are all shorter thanNAME_MAXand 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-errors13/13;server-persistence13/13;skip-audit15/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 body400,unknown endpoint404). The traversal attempt is not one:topologyFile()replaces/and appends a hash of the exact id, so../../etc/passwdlands as.._.._etc_passwd-<hash>.jsoninside the topology directory.Fixed on branch
fix/board-idatfe6dc5f4(pushed as a new ref), base1b1e1287. Verified: 250 suites / 9192 assertions / 0 failed, syntax 320,api-errors13/13,server-persistence13/13, andboard-id-is-a-name45/45 (against the old handler all nine refusals answered201).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:fix/no-form-names-v2c97b11b6fix/stated-range403b512efix/board-idfe6dc5f4All three are one
POST /pulls+ one squash away, in that order, as soon as the volume has room for a temp clone.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 whateverJSON.parsereturned, which can benull, anumber, a string or an array.
body.idonnullis a TypeError, so the answer to a client POSTing the eight bytesnullwas:— the runtime's own words, which
test/api-errors.test.jsforbids in a response, inside the very handler this issuerewrote. 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 noid, so itmeans 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-nameis now 55 checks, and the two new ones fail against the previous handler.Full suite 251 suites / 9209 assertions / 0 failed; syntax 321;
api-errors13/13;server-persistence13/13.The three per-issue branches (
fix/board-id@fe6dc5f4) still carry the pre-review tree; the landing queue nowprefers
land-all-v2, so whichever window opens lands the corrected version.