HandleCreateSession and HandlePostMessage in internal/handlers/api.go and HandleLogin in internal/handlers/auth.go wrap the body in http.MaxBytesReader with MAX_MESSAGE_SIZE and then call json.NewDecoder(body).Decode(&payload). Decode stops after the first JSON value. The rest of the body is never read, so the limit never fires on it, and nothing checks for trailing data.
Example: POST /api/v1/session with {"nick":"alice"} followed by 100 KiB of spaces, or of anything else, is accepted with 201. README.md says a body larger than MAX_MESSAGE_SIZE bytes gets 400invalid request body. That holds only when the first JSON value itself does not end within the limit.
Definition of done:
On all three endpoints, a body larger than MAX_MESSAGE_SIZE bytes gets 400invalid request body, whether or not its first JSON value ends within the limit.
Trailing bytes after the JSON value, other than whitespace, get the same 400 (reading the whole limited body and calling json.Unmarshal gives both for free).
One test per endpoint sends a small valid value followed by bytes past the limit and asserts 400.
make check is green. README.md needs no change.
Found during the fresh read of README.md for #190.
Model: fable-5-1
`HandleCreateSession` and `HandlePostMessage` in `internal/handlers/api.go` and `HandleLogin` in `internal/handlers/auth.go` wrap the body in `http.MaxBytesReader` with `MAX_MESSAGE_SIZE` and then call `json.NewDecoder(body).Decode(&payload)`. `Decode` stops after the first JSON value. The rest of the body is never read, so the limit never fires on it, and nothing checks for trailing data.
Example: `POST /api/v1/session` with `{"nick":"alice"}` followed by 100 KiB of spaces, or of anything else, is accepted with `201`. `README.md` says a body larger than `MAX_MESSAGE_SIZE` bytes gets `400` `invalid request body`. That holds only when the first JSON value itself does not end within the limit.
Definition of done:
- On all three endpoints, a body larger than `MAX_MESSAGE_SIZE` bytes gets `400` `invalid request body`, whether or not its first JSON value ends within the limit.
- Trailing bytes after the JSON value, other than whitespace, get the same `400` (reading the whole limited body and calling `json.Unmarshal` gives both for free).
- One test per endpoint sends a small valid value followed by bytes past the limit and asserts `400`.
- `make check` is green. `README.md` needs no change.
Found during the fresh read of `README.md` for https://git.eeqj.de/sneak/neoirc/issues/190.
Model: fable-5-1
Built in #253: all three endpoints now read the whole limited body and decode it with json.Unmarshal. Posting a message without a valid session still gets 401, and logging in over the rate limit still gets 429, whatever the body size.
Model: opus-5-5
Built in https://git.eeqj.de/sneak/neoirc/pulls/253: all three endpoints now read the whole limited body and decode it with `json.Unmarshal`. Posting a message without a valid session still gets `401`, and logging in over the rate limit still gets `429`, whatever the body size.
Model: opus-5-5
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
HandleCreateSessionandHandlePostMessageininternal/handlers/api.goandHandleLoginininternal/handlers/auth.gowrap the body inhttp.MaxBytesReaderwithMAX_MESSAGE_SIZEand then calljson.NewDecoder(body).Decode(&payload).Decodestops after the first JSON value. The rest of the body is never read, so the limit never fires on it, and nothing checks for trailing data.Example:
POST /api/v1/sessionwith{"nick":"alice"}followed by 100 KiB of spaces, or of anything else, is accepted with201.README.mdsays a body larger thanMAX_MESSAGE_SIZEbytes gets400invalid request body. That holds only when the first JSON value itself does not end within the limit.Definition of done:
MAX_MESSAGE_SIZEbytes gets400invalid request body, whether or not its first JSON value ends within the limit.400(reading the whole limited body and callingjson.Unmarshalgives both for free).400.make checkis green.README.mdneeds no change.Found during the fresh read of
README.mdfor #190.Model: fable-5-1
Built in #253: all three endpoints now read the whole limited body and decode it with
json.Unmarshal. Posting a message without a valid session still gets401, and logging in over the rate limit still gets429, whatever the body size.Model: opus-5-5