leptos_router panics on invalid UTF-8 in URL path (DoS via bot traffic)
**Describe the bug**
`leptos_router` panics at `location/mod.rs:144` when processing URLs with invalid UTF-8 percent-encoded sequences. The `unwrap()` on URL percent-decoding crashes the entire Axum server process. These URLs are routinely sent by automated security scanners and bots, making any internet-facing Leptos SSR application vulnerable to denial-of-service.
## Panic Output
PANIC: panicked at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/leptos_router-0.8.12/src/location/mod.rs:144:18:
called Result::unwrap() on an Err value: Utf8Error { valid_up_to: 0, error_len: Some(1) }
**Leptos Dependencies**
```toml
leptos = { version = "0.8.17", features = ["islands"] }
leptos_axum = { version = "0.8.17" }
leptos_meta = { version = "0.8.17" }
leptos_router = { version = "0.8.17" }
```
**To Reproduce**
1. Deploy any Leptos SSR application with Axum
2. Send a request with invalid percent-encoded UTF-8:
`curl 'https://your-app.com/%C0%AE%C0%AE/etc/passwd'`
3. Server panics at `leptos_router-0.8.12/src/location/mod.rs:144:18`
**Screenshots**
N/A — server-side panic, no UI.
**Next Steps**
- [ ] I will make a PR
- [ ] I would like to make a PR, but need help getting started
- [x] I want someone else to take the time to fix this
- [ ] This is a low priority for me and is just shared for your information
**Additional context**
- Affects all SSR modes (Async, OutOfOrder, PartiallyBlocked, Static)
- Islands mode with `hydrate_islands()`
- Observed in production within hours of deployment from regular bot/scanner traffic
- Common scanner patterns that trigger this: `%C0%AE` (overlong encoding for `.`), `%FE%FF`, and similar invalid UTF-8 sequences
- Workaround: Reverse proxy (Caddy/nginx) middleware that rejects URLs with invalid UTF-8 before they reach Leptos
- Fix suggestion: Replace `unwrap()` at `location/mod.rs:144` with `decode_utf8_lossy()` or return 400 Bad Request
关闭于 2026-03-26 0 条评论