Repository navigation
Bug 2059957 - Reject truncated request bodies before native endpoint dispatch #2767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dklawren
merged 2 commits into
mozilla:master
from
loganrosen:loganrosen-fix-bug-2059957
Oct 6, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| # file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| # | ||
| # This Source Code Form is "Incompatible With Secondary Licenses", as | ||
| # defined by the Mozilla Public License, v. 2.0. | ||
|
|
||
| package Bugzilla::App::Plugin::RequestLimit; | ||
| use 5.10.1; | ||
| use Mojo::Base 'Mojolicious::Plugin'; | ||
|
|
||
| use Bugzilla::Constants qw( | ||
| USAGE_MODE_MOJO | ||
| USAGE_MODE_MOJO_REST | ||
| ); | ||
| use Bugzilla::Logging; | ||
|
|
||
| use constant REQUEST_TOO_LARGE_ERROR => 'request_too_large'; | ||
| use constant REQUEST_TOO_LARGE_MESSAGE => 'The request is too large.'; | ||
|
|
||
| my %BODY_LIMIT_REASONS = map { $_ => 1 } ( | ||
| 'Maximum message size exceeded', | ||
| 'Maximum buffer size exceeded', | ||
| ); | ||
|
|
||
| my %KNOWN_NON_BODY_LIMIT_REASONS = map { $_ => 1 } ( | ||
| 'Maximum start-line size exceeded', | ||
| 'Maximum header size exceeded', | ||
| ); | ||
|
|
||
| sub register { | ||
| my ($self, $app, $conf) = @_; | ||
| $app->hook(around_action => \&_around_action); | ||
| } | ||
|
|
||
| sub _around_action { | ||
| my ($next, $c, $action, $is_endpoint) = @_; | ||
| return $next->() unless $is_endpoint; | ||
| return $next->() if $c->isa('Bugzilla::App::Controller::CGI'); | ||
|
|
||
| my $format = $c->stash->{request_limit_format} // 'html'; | ||
| my $reason = request_limit_reason($c->req, $format eq 'rest'); | ||
| return $next->() unless defined $reason; | ||
|
|
||
| my $route = $c->match->endpoint->to_string; | ||
| WARN("Rejected oversized request for $route: $reason"); | ||
|
|
||
| if ($format eq 'rest') { | ||
| Bugzilla->usage_mode(USAGE_MODE_MOJO_REST); | ||
| return $c->user_error(REQUEST_TOO_LARGE_ERROR); | ||
| } | ||
| elsif ($format eq 'json') { | ||
| return $c->render( | ||
| json => {error => REQUEST_TOO_LARGE_MESSAGE}, | ||
| status => 413 | ||
| ); | ||
| } | ||
| elsif ($format eq 'empty') { | ||
| return $c->render(data => '', status => 413); | ||
| } | ||
|
|
||
| Bugzilla->usage_mode(USAGE_MODE_MOJO); | ||
| return $c->user_error( | ||
| REQUEST_TOO_LARGE_ERROR, | ||
| {}, | ||
| {status => 413, skip_exception_page => 1} | ||
| ); | ||
| } | ||
|
|
||
| sub request_limit_reason { | ||
| my ($request, $is_rest) = @_; | ||
| return undef unless $request->is_limit_exceeded; | ||
|
|
||
| my $error = $request->error; | ||
| return 'Unrecognized parser limit' unless ref $error eq 'HASH'; | ||
|
|
||
| my $reason = $error->{message} // ''; | ||
| return undef if $KNOWN_NON_BODY_LIMIT_REASONS{$reason} && !$is_rest; | ||
| return $reason if $KNOWN_NON_BODY_LIMIT_REASONS{$reason}; | ||
| return $BODY_LIMIT_REASONS{$reason} ? $reason : 'Unrecognized parser limit'; | ||
| } | ||
|
|
||
| 1; |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this drops the old 413 for REST requests that hit the header or start-line limit, so
/restendpoints now run with half-parsed headers (e.g. api key cut off) and no body. maybe keep failing closed for anyis_limit_exceededwhen the format isrestand add a test for itThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this. REST routes now continue to reject header and start-line parser limits with the existing 413 response; non-REST handling remains unchanged. I added an HTTP regression test covering the REST header-limit case, including the 413 response, error envelope, and CORS header.