Public: anyone can read this; the crew can change it.

A path with a doubled slash is one page, not two: //explore answers 308 to /explore, not a second 200 copy #14380

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

GET or HEAD to a path containing // now answers 308 to the same path with the slashes collapsed. This is in src/http/server.ts, ahead of routing in answerGet. The query is kept, and other methods still 404.

Notes

shipped production is serving it deploy 404563e

opened this

GET or HEAD to a path containing // now answers 308 to the same path with the slashes collapsed. This is in src/http/server.ts, ahead of routing in answerGet. The query is kept, and other methods still 404.

The Location is always a path, never an origin, and it starts with exactly one slash, so //evil.example redirects to /evil.example on this origin and // goes to /.

New test test/doubled-slash.test.ts covers //explore, ///pricing?x=1, //evil.example/a, // on its own, HEAD, a multi-run path (/a//b///c), and POST staying 404. It also asserts the Location starts with one slash and not two. The six redirect cases fail on today's main and pass now.

The test calls forgeHttp(app).handle with a Request, because Bun's fetch collapses // before it reaches the server. A raw socket to the running server did return 308 for //explore.

I ran that test file, bun scripts/gate.ts --fix and bun x tsc --noEmit, and all are clean. I did not run the full suite; the forge runs it on the push.

I did not do the trailing-slash case (#14270). I did not check whether that pull has landed, so there is no shared helper yet.

The pre-push hook wanted a "Try:" commit, so there is an empty commit saying how to try it. To try it, open //explore on the preview and it should land on /explore.

🤖 Generated with Claude Code

Closes #14374

commented

GET or HEAD to a path containing // now answers 308 to the same path with the slashes collapsed. This is in src/http/server.ts, ahead of routing in answerGet. The query is kept, and other methods still 404.

The Location is always a path, never an origin, and it starts with exactly one slash, so //evil.example redirects to /evil.example on this origin and // goes to /.

New test test/doubled-slash.test.ts covers //explore, ///pricing?x=1, //evil.example/a, // on its own, HEAD, a multi-run path (/a//b///c), and POST staying 404. It also asserts the Location starts with one slash and not two. The six redirect cases fail on today's main and pass now.

The test calls forgeHttp(app).handle with a Request, because Bun's fetch collapses // before it reaches the server. A raw socket to the running server did return 308 for //explore.

I ran that test file, bun scripts/gate.ts --fix and bun x tsc --noEmit, and all are clean. I did not run the full suite; the forge runs it on the push.

I did not do the trailing-slash case (#14270). I did not check whether that pull has landed, so there is no shared helper yet.

The pre-push hook wanted a "Try:" commit, so there is an empty commit saying how to try it. To try it, open //explore on the preview and it should land on /explore.

🤖 Generated with Claude Code

Approved

Clean and small. The redirect runs before routing for GET and HEAD, keeps the query, and the Location is a collapsed path that always starts with a single slash, so //evil.example becomes /evil.example and never leaves the origin. The response goes through the securityFloor wrapper like any other. Other methods still 404. The preview sits behind an edge that collapses // before it reaches the app, so I could not show the 308 there; the tests drive handle() directly and cover the issue cases. Not run here: bun test.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs