Prefix pages answer 500 for a malformed prefix and 404 for a prefix written in another valid form #71

Closed
opened 2026-10-14 14:50:33 +02:00 by clawbot · 0 comments
Collaborator

handlePrefixDetail and handlePrefixDetailJSON in internal/server/handlers.go join the two path parts and pass the result to GetPrefixDetailsContext unchecked.

  • A malformed prefix, such as /api/v1/prefix/foo/24, makes GetPrefixDetailsContext fail with a parse error that is not ErrNoRoute, so both pages answer 500 and log it as a server error.
  • A valid prefix in any text form other than the one the tables store (the form Go's net/netip prints, see #48) is looked up as typed and answers 404 although the route exists: /api/v1/prefix/2001:DB8:0:0::/32 for a stored 2001:db8::/32, or /prefix/192.0.2.1/24 for 192.0.2.0/24.

Failure scenario: a client that writes IPv6 prefixes in full or in capitals gets "not found" for every route.

Severity: low

Definition of done

  • A test, failing before the fix: /api/v1/prefix/foo/24 answers 400; /api/v1/prefix/2001:DB8:0:0::/32 and /prefix/2001:DB8:0:0::/32 find a stored 2001:db8::/32; /api/v1/prefix/192.0.2.1/24 finds 192.0.2.0/24.
  • Both handlers parse the prefix with net/netip, mask it, and look up the text form it prints; a prefix that does not parse answers 400.
  • make check passes.

Model: opus-5-5

`handlePrefixDetail` and `handlePrefixDetailJSON` in `internal/server/handlers.go` join the two path parts and pass the result to `GetPrefixDetailsContext` unchecked. - A malformed prefix, such as `/api/v1/prefix/foo/24`, makes `GetPrefixDetailsContext` fail with a parse error that is not `ErrNoRoute`, so both pages answer 500 and log it as a server error. - A valid prefix in any text form other than the one the tables store (the form Go's `net/netip` prints, see https://git.eeqj.de/sneak/routewatch/issues/48) is looked up as typed and answers 404 although the route exists: `/api/v1/prefix/2001:DB8:0:0::/32` for a stored `2001:db8::/32`, or `/prefix/192.0.2.1/24` for `192.0.2.0/24`. Failure scenario: a client that writes IPv6 prefixes in full or in capitals gets "not found" for every route. Severity: low ## Definition of done - A test, failing before the fix: `/api/v1/prefix/foo/24` answers 400; `/api/v1/prefix/2001:DB8:0:0::/32` and `/prefix/2001:DB8:0:0::/32` find a stored `2001:db8::/32`; `/api/v1/prefix/192.0.2.1/24` finds `192.0.2.0/24`. - Both handlers parse the prefix with `net/netip`, mask it, and look up the text form it prints; a prefix that does not parse answers 400. - `make check` passes. Model: opus-5-5
clawbot self-assigned this 2026-10-14 14:50:33 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/routewatch#71