Repository navigation
🐛 bug: return 400 for invalid request method tokens - #4916
wozhenbang2004 wants to merge 2 commits into
Conversation
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins. |
|
No actionable comments were generated in the recent review. WalkthroughThe error handler no longer maps ChangesHTTP method error mapping
Estimated code review effort: 2 (Simple) | ~8 minutes Change: Bug fix Possibly related issues
Possibly related PRs
Merge Risk:
|
-| A method token the parser rejects, such as `GE(T` | `501 Not Implemented` |The paragraph below the table ( Checked: read the diff; applied the row removal on 2329668 and ran Generated by Claude Code |
|
The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins. |
|
Thanks for catching the stale row. I removed it so malformed methods are covered by the 400 row. The 501 example for a valid but unsupported method still applies. The focused error-handler test passed. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4916 +/- ##
==========================================
- Coverage 96.29% 96.29% -0.01%
==========================================
Files 160 160
Lines 21511 21509 -2
==========================================
- Hits 20715 20713 -2
Misses 483 483
Partials 313 313
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| c.Set(HeaderAllow, getOnlyAllow) | ||
| case errors.Is(err, fasthttp.ErrUnsupportedRequestMethod): | ||
| err = ErrNotImplemented | ||
| case hasMessagePrefix(err, unsupportedTransferCodingMarker): |
There was a problem hiding this comment.
Nit (optional): with the ErrUnsupportedRequestMethod case gone, a request such as GE(T / HTTP/1.1 now falls to the default branch, which answers with err.Error(). fasthttp builds that message as unsupported http request method %q in %q over the whole header buffer it has read, so the 400 body now echoes the request line and every header after it (Cookie, Authorization, ...) back to the client. Before this change the 501 body was just Not Implemented, and the transfer-coding 501 was deliberately changed so "the body no longer repeats the start of the request" (whats_new.md). The status change to 400 is right (fasthttp v1.80.0 only raises this sentinel for a method that is not a token), but consider keeping the generic body, e.g.
case errors.Is(err, fasthttp.ErrUnsupportedRequestMethod):
// A method that is not a token is a malformed request line (RFC 9112 §3): 400, without the quoted request bytes.
err = ErrBadRequestand asserting the body in the rejected method token rows of Test_App_serverErrorHandler_RawRequestStatus.
Generated by Claude Code
| status: StatusBadRequest, | ||
| }, | ||
|
|
||
| // The status follows what the parser reported, never request bytes its error quotes. |
There was a problem hiding this comment.
Nit (optional): this comment, and the rows under it, no longer test what they describe. They guarded the removed errors.Is(err, fasthttp.ErrUnsupportedRequestMethod) case against request bytes that quote the method wording; with that case gone, rejected method token, its secure message twin and trailer quoting the method wording (line 3302) all just expect the default 400 and would pass whatever the parser reported. Either drop them or reword the comment and give the rows something to tell apart, such as a body check on the method rows (secure vs. non-secure messages differ in what the body carries).
Generated by Claude Code
| | A method token the parser rejects, such as `GE(T` | `501 Not Implemented` | | ||
| | A `Transfer-Encoding` naming a coding the server cannot decode | `501 Not Implemented` | | ||
| | A timeout while reading the request, or another network error | `408 Request Timeout`, or `502 Bad Gateway` | | ||
| | Any other malformed request | `400 Bad Request`, with the parser's message | |
There was a problem hiding this comment.
Nit (optional): the 501 for a rejected method token is already in a tag (git tag --contains puts the mapping in v3.7.0), and this row was its documented behavior. Removing the row folds GE(T into "Any other malformed request", which is right, but nothing in docs/whats_new.md tells users the status moved from 501 to 400 (and that the body is now the parser message rather than Not Implemented). A one-line note next to the "Status from the parser's error" bullet would cover anyone who matched on the 501.
Generated by Claude Code
Description
Fasthttp 1.80 accepts valid method tokens, including unknown methods, and only reports
ErrUnsupportedRequestMethodfor an invalid token. Remove its old 501 mapping so malformed request lines receive 400. A valid but unsupported method such asFOOstill receives 501 from the router.Addresses the request-method case in #4915. The q-value question remains open.
Type of change
Checklist
make audit,make generate,make betteralign,make format,make lint, andmake testpass on Linux for the exact proposed commit (CI run).The full race-enabled suite also passes on Go 1.27.4. The isolated CI workflow checks out
2329668b8aed678d7723735e0787d7936a4e65d5; it is outside this PR.🤖 Maintainers:
/generatere-runs the code generators on this branch