fix: guard encoded example routes by matched route ID - #21
Conversation
The example protectedRoutesHandle hook guarded on event.url.pathname, which preserves percent-encoding per the WHATWG URL spec. SvelteKit decodes the pathname before matching routes, so a request to /%61ccount skipped the guard yet still dispatched the protected /account route (same for /%61pi/... vs the /api/ guard). Guard on event.route.id (the resolved route) instead, which reflects the matched route and is immune to encoding tricks.
Original prompt from Linear User
|
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
Recovered this branch onto current main and added tests against the actual example route guard. Coverage includes canonical and encoded account/API paths, authenticated access, public routes, and unmatched routes. Enabled the test/coverage step in CI. Verification: 39 tests passed with coverage, plus root typecheck, formatting, library build, and example build. The example typecheck passes with placeholder environment configuration. The standalone lint script still fails because of its pre-existing ESLint configuration, reproduced on current main; lint was already disabled in CI and remains unchanged. A fresh independent code review found no code blocker. Not merged or released. |
|
❌ Cannot revive Devin session - the session is too old. Please start a new session instead. |
Summary
The example app's
protectedRoutesHandle(example/src/hooks.server.ts) matched request paths without normalizing percent-encoded segments, so encoded variants could miss the guard's prefix checks. This change normalizes the path before matching.Please review before merging.