Problem/Motivation
Reads from InputBag (e.g., $request->query->get('_wrapper_format', $request->getRequestFormat())) throw BadRequest if the value is non-scalar, but that's used in a few places that don't handle it. For example, HttpExceptionSubscriberBase, where that can actually turn a BadRequestHttpException into a server error because it hits the BadRequest while trying to read _wrapper_format.
This should actually be a client error, not a server error, and it can mislead operators when these requests appear to be problems (i.e., 500 errors in logs), and are not detected as bad client behavior (400 responses).
Steps to reproduce
% curl -v 'https://drupal.ddev.site?_wrapper_format%5B0%5D=foo'
...
< HTTP/2 500
...
The website encountered an unexpected error. Try again later.<br /><details class="error-with-backtrace"><summary><em class="placeholder">Symfony\Component\HttpFoundation\Exception\BadRequestException</em>: Input value "_wrapper_format" contains a non-scalar value. in <em class="placeholder">Symfony\Component\HttpFoundation\InputBag->get()</em> (line <em class="placeholder">46</em> of <em class="placeholder">vendor/symfony/http-foundation/InputBag.php</em>).</summary><pre class="backtrace">Symfony\Component\HttpFoundation\InputBag->get() (Line: 97)
Drupal\Core\EventSubscriber\HttpExceptionSubscriberBase->onException() (Line: 254)
Symfony\Component\EventDispatcher\EventDispatcher::{closure:Symfony\Component\EventDispatcher\EventDispatcher::optimizeListeners():249}() (Line: 206)
Symfony\Component\EventDispatcher\EventDispatcher->callListeners() (Line: 56)
Symfony\Component\EventDispatcher\EventDispatcher->dispatch() (Line: 248)
Symfony\Component\HttpKernel\HttpKernel->handleThrowable() (Line: 94)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 30)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 199)
Drupal\page_cache\StackMiddleware\PageCache->fetch() (Line: 136)
Drupal\page_cache\StackMiddleware\PageCache->lookup() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 71)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 54)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 750)
Drupal\Core\DrupalKernel->handle() (Line: 34)
Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run() (Line: 32)
require() (Line: 20)
require_once() (Line: 13)
</pre></details>
curl -v 'https://drupal.ddev.site?_format%5B0%5D=foo'
curl -v 'https://drupal.ddev.site?destination%5B0%5D=foo'
Proposed resolution
Generally, throw BadRequestHttpException in these cases, except in HttpExceptionSubscriberBase, which needs to handle it, not throw. In that one, use the default wrapper format.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3631357
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
travis-bradbury commentedComment #4
travis-bradbury commented