fix: handle non-standard HTTP methods in router#3808
Merged
Conversation
The router's static and dynamic match branches assumed `byMethod[method]` was either `T` or `null`, but the type's key set only covers the seven standard HTTP verbs. A request with a non-standard method (e.g. PROPFIND from WebDAV scanners) caused `byMethod[method]` to be `undefined`, which slipped past the `item !== null` check and surfaced as `methodMatch: true` with `item: undefined`, crashing the handler with `TypeError: handler2 is not a function`. Normalize the lookup with `?? null` in both branches so unknown verbs route through the existing `DEFAULT_NOT_ALLOWED_METHOD` path and return a 405 instead of throwing. Fixes #3804
Contributor
Author
|
The canary CI failures are unrelated to this PR — they're a Deno canary regression around All 9 failing tests are in The same canary failures appear on unrelated PR #3807 (no router changes). This PR's v2.x suite passes on all three platforms, and the new router tests ( This PR only touches |
3 tasks
bartlomieju
approved these changes
May 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3804.
Production apps crashed with
TypeError: handler2 is not a functionwhen a request arrived with a non-standard HTTP method such asPROPFIND(common from WebDAV scanners hitting public Fresh sites).The router's
match()method indexedbyMethodwith the request method and treated the result withitem !== null.RouteByMethod<T>only declares entries for the seven known methods (GET/POST/PATCH/PUT/DELETE/HEAD/OPTIONS), so for any other verbbyMethod[method]wasundefined— which slipped past the!== nullcheck and surfaced asmethodMatch: truewithitem: undefined, crashing the request pipeline.Normalize the lookup with
?? nullin both the static and dynamic branches so unknown verbs route through the existingDEFAULT_NOT_ALLOWED_METHODpath and return a 405.Tests
router_test.tsforPROPFINDagainst static and dynamic routes — assertmethodMatch: false,item: null.app_test.tsxexercising the full app handler withPROPFINDon both a static and a dynamic route — asserts a 405 response and that nothing throws.deno task okpasses locally (fmt, lint, type check, full test suite, docs check).Test plan
deno task okpasses locallyCloses bartlomieju/orchid-inbox#63