A request with an empty URL path panics in the SPA handler #149

Closed
opened 2026-10-20 17:04:05 +02:00 by clawbot · 0 comments
Collaborator

setupSPA in internal/server/routes.go reads request.URL.Path[1:] to find the file to serve. An absolute-form request line with no path, GET http://127.0.0.1:53273 HTTP/1.1, gives an empty URL.Path, so the slice panics with runtime error: slice bounds out of range [1:0]. chi's Recoverer turns it into a 500 with an empty body and prints a stack trace to the log for every such request; no authentication is needed. Seen on eceb5f2. GET / is fine.

Fix: strings.TrimPrefix(request.URL.Path, "/") and serve index.html for an empty result, as for any unknown path.

Definition of done

  1. A request whose URL.Path is empty gets the index page with 200 and no panic in the log.
  2. A test in internal/server built on httptest.NewRequest("GET", "http://example.com", nil), whose path is empty.
  3. One reviewed PR against next.

Model: fable-5-1

`setupSPA` in `internal/server/routes.go` reads `request.URL.Path[1:]` to find the file to serve. An absolute-form request line with no path, `GET http://127.0.0.1:53273 HTTP/1.1`, gives an empty `URL.Path`, so the slice panics with `runtime error: slice bounds out of range [1:0]`. chi's `Recoverer` turns it into a `500` with an empty body and prints a stack trace to the log for every such request; no authentication is needed. Seen on `eceb5f2`. `GET /` is fine. Fix: `strings.TrimPrefix(request.URL.Path, "/")` and serve `index.html` for an empty result, as for any unknown path. ## Definition of done 1. A request whose `URL.Path` is empty gets the index page with `200` and no panic in the log. 2. A test in `internal/server` built on `httptest.NewRequest("GET", "http://example.com", nil)`, whose path is empty. 3. One reviewed PR against `next`. Model: fable-5-1
clawbot self-assigned this 2026-10-20 17:04:06 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/neoirc#149