-
-
Notifications
You must be signed in to change notification settings - Fork 950
Open
Labels
enhancementNew feature or request.New feature or request.
Description
What version of Hono are you using?
4.11.9
What runtime/platform is your app running on? (with version if possible)
Node 20.19.4 (but not important)
What steps can reproduce the bug?
- Set up a Hono app with authentication middleware
- Add some routes with authentication
- Make requests to non-existent paths
import { Hono } from 'hono'
import { jwt } from 'hono/jwt'
const app = new Hono()
// Authentication middleware
app.use('*', jwt({ secret: 'my-secret' }))
// Actual route
app.get('/protected', (c) => c.text('Protected content'))
// Request to non-existent path still triggers JWT validation
// GET /non-existent-routeWhat is the expected behavior?
When accessing non-existent routes:
- The server should first check if the route exists
- If route doesn't exist, return 404 immediately
- Authentication middleware should only run for valid routes
What do you see instead?
- Authentication middleware runs for ALL requests, even to non-existent routes
- This causes unnecessary CPU-intensive authentication processing
- Only after authentication does the framework return 404 for invalid routes
Additional information
Security Impact:
-
Creates a potential DoS vulnerability where attackers can spam random URLs to trigger expensive auth checks
-
Particularly problematic for JWT/OAuth/other crypto-heavy authentication
Performance Impact:
-
Wastes server resources validating authentication for invalid routes
-
Can significantly impact performance under high traffic
Suggested Solutions:
- Add global config option:
new Hono({ checkRouteBeforeAuth: true })- Provide route validation middleware:
app.use(routeValidator()) // Checks route existence
app.use(authMiddleware) // Then authenticates- Expose routing inspection API for custom solutions
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request.New feature or request.