8000 🐛 bug: return 400 for invalid request method tokens by wozhenbang2004 · Pull Request #4916 · gofiber/fiber · GitHub
[go: up one dir, main page]

Skip to content

🐛 bug: return 400 for invalid request method tokens - #4916

Open
wozhenbang2004 wants to merge 2 commits into
gofiber:mainfrom
wozhenbang2004:fix-invalid-method-token-status
Open

wozhenbang2004 wants to merge 2 commits into
gofiber:mainfrom
wozhenbang2004:fix-invalid-method-token-status

Conversation

@wozhenbang2004
@wozhenbang2004 wozhenbang2004 commented Nov 23, 2026 •
Copy link
Copy Markdown

Description

Fasthttp 1.80 accepts valid method tokens, including unknown methods, and only reports ErrUnsupportedRequestMethod for an invalid token. Remove its old 501 mapping so malformed request lines receive 400. A valid but unsupported method such as FOO still receives 501 from the router.

Addresses the request-method case in #4915. The q-value question remains open.

Type of change

  • Bug fix

Checklist

  • Reviewed the change and updated the existing error-handler tests.
  • Added a raw-request case with a control byte in the method; retained the unknown-method counterexample.
  • Confirmed the regression tests fail before the fix and pass after it.
  • make audit, make generate, make betteralign, make format, make lint, and make test pass 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: /generate re-runs the code generators on this branch

@chatgpt-codex-connector
chatgpt-codex-connector Bot commented Nov 23, 2026 •
Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ❌ Failed 2026-11-24T00:47:16.403309Z
We couldn’t complete this review. Comment @codex security review to try again.
ae2ea5b New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector
Copy link
Copy Markdown

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.

@coderabbitai
coderabbitai Bot commented Nov 23, 2026 •
Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The error handler no longer maps fasthttp.ErrUnsupportedRequestMethod to 501. Tests expect 400 for malformed method tokens and retain 501 coverage for unsupported methods. The error-handling guide no longer documents the removed mapping.

Changes

HTTP method error mapping

Layer / File(s) Summary
Error mapping and status tests
app.go, app_test.go, docs/guide/error-handling.md
The handler lets ErrUnsupportedRequestMethod reach the default 400 mapping. Tests cover malformed method tokens, including a control byte and secure-mode rejection, while retaining 501 coverage for unsupported methods. The guide no longer lists the removed mapping. The unknown transfer coding mapping remains unchanged.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Possibly related issues

  • gofiber/fiber#4915: The issue describes removing the ErrUnsupportedRequestMethod mapping to 501. Its separate q-value question is not addressed by this change.

Possibly related PRs

  • gofiber/fiber#4914: Both changes update error handling for ErrUnsupportedRequestMethod and related tests.
Merge Risk: Minimal · up to ae2ea

Malformed HTTP method tokens now receive 400 Bad Request instead of 501, while valid but unsupported methods still receive 501 from the router. The pinned fasthttp version supports this behavior, and the tests and docs are updated. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "🐛 bug: return 400 for invalid request method tokens" matches the main change: the handler no longer maps ErrUnsupportedRequestMethod to 501, so malformed method tokens now receive 400 Bad R…
Description check Passed The description follows the template's main sections: it explains the problem and fix, marks the change as a bug fix, and lists checklist items. It references #4915 and includes a CI run. It omits the…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "🐛 bug: return 400 for invalid request method tokens" matches the main change: the handler no longer maps ErrUnsupportedRequestMethod to 501, so malformed method tokens now receive 400 Bad Request. The emoji prefix is noise but does not change the meaning.

Full details: Description check

Explanation

The description follows the template's main sections: it explains the problem and fix, marks the change as a bug fix, and lists checklist items. It references #4915 and includes a CI run. It omits the template's optional-but-listed Changes introduced details (documentation update, changelog, migration guide) and does not explicitly tick the documentation checkbox, even though the objectives state docs/guide/error-handling.md was updated. The Fixes # (issue) line is not filled in; it only says it addresses #4915 and leaves the q-value question open.

Resolution

Optional: state the documentation change to docs/guide/error-handling.md in the Changes introduced section, and replace the "Addresses" wording with an explicit "Fixes #4915" line if that issue is closed by this change.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the method line,
Malformed tokens now return four-oh-oh.
Unsupported routes still answer five-oh-one,
The guide records the mapping change.
I hop along, with tests in tow.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c884ca72-4e89-4116-8c49-0532bde6d1e9
Commits

Reviewing files that changed from the base of the PR and between 2329668 and ae2ea5b.

Files selected for processing: 1

  • docs/guide/error-handling.md
Files with no reviewable changes: 1

  • docs/guide/error-handling.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@ReneWerner87 ReneWerner87 added this to v3 Nov 23, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone Nov 23, 2026
Copy link
Copy Markdown
Member
  1. docs/guide/error-handling.md:152 still documents the old status. The table of errors before a handler runs lists "A method token the parser rejects, such as GE(T" → 501 Not Implemented. With the mapping removed in app.go, that request is answered by the "Any other malformed request" row (400 Bad Request, with the parser's message), which is what Test_App_serverErrorHandler_RawRequestStatus now pins. Fix: drop the row.
-| A method token the parser rejects, such as `GE(T`                        | `501 Not Implemented`                                |

The paragraph below the table (FOO and get get 501 from Fiber itself) stays correct.

Checked: read the diff; applied the row removal on 2329668 and ran make betteralign, make format, make markdown, make lint (0 issues) and make test (13778 tests, all pass); go test -run Test_App_serverErrorHandler -count=1 . passes.


Generated by Claude Code

@chatgpt-codex-connector
Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Author

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
codecov Bot commented Nov 26, 2026
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.29%. Comparing base (6d03df9) to head (ae2ea5b).
⚠️ Report is 13 commits behind head on main.

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              
Flag Coverage Δ
unittests 96.29% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread app.go
c.Set(HeaderAllow, getOnlyAllow)
case errors.Is(err, fasthttp.ErrUnsupportedRequestMethod):
err = ErrNotImplemented
case hasMessagePrefix(err, unsupportedTransferCodingMarker):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = ErrBadRequest

and asserting the body in the rejected method token rows of Test_App_serverErrorHandler_RawRequestStatus.


Generated by Claude Code

Comment thread app_test.go
status: StatusBadRequest,
},

// The status follows what the parser reported, never request bytes its error quotes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 |
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants

0