registry/internal/api
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Radoslav Dimitrov 7a4216c528
refactor: rename readBody to readErrorBody and cap body size (#1246)
## Summary

Follow-up to #1241. Two small tweaks to the `readBody` helper:

- **Rename `readBody` → `readErrorBody`.** The helper is only ever
called on the error path (after a non-2xx status check), where we want a
small string for diagnostics. The generic name made it look reusable on
the success path, where streaming JSON decoding is the right approach.
The new name pins the intended use down.
- **Cap the read with `io.LimitReader` (8 KiB).** Defense in depth —
error diagnostics never need more than a few KB, and we shouldn't buffer
an arbitrarily large body from an upstream just to format an error
message. 8 KiB is well above any realistic GitHub API or JWKS error
response.

No behavior change on the happy path. On the unhappy path, error
messages are now bounded.

## Test plan

- [x] `go build ./...`
- [x] `go test ./internal/api/handlers/v0/auth/...`

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-05-04 07:09:57 -04:00
..
handlers/v0 refactor: rename readBody to readErrorBody and cap body size (#1246) 2026-05-04 07:09:57 -04:00
router security: fix open redirect and add small hardening (#1227) 2026-04-29 19:14:00 -04:00
cors_test.go feat: add CORS support to registry API (#711) 2025-10-27 18:07:13 +00:00
openapi_compliance_test.go Ensure tests are failing CI (#840) 2025-12-11 09:56:57 +02:00
server.go security: fix open redirect and add small hardening (#1227) 2026-04-29 19:14:00 -04:00
server_test.go security: fix open redirect and add small hardening (#1227) 2026-04-29 19:14:00 -04:00