Skip to content

Commit

Permalink
security #cve-2019-10913 [HttpFoundation] reject invalid method overr…
Browse files Browse the repository at this point in the history
…ide (nicolas-grekas)

This PR was merged into the 2.8 branch.

Discussion
----------

[HttpFoundation] reject invalid method override

Based on #86

Commits
-------

d7dcedbf1d [HttpFoundation] reject invalid method override
  • Loading branch information
nicolas-grekas committed Apr 16, 2019
1 parent d0ab719 commit 746f8d3
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1269,22 +1269,37 @@ public function setMethod($method)
*/
public function getMethod()
{
if (null === $this->method) {
$this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET'));

if ('POST' === $this->method) {
if ($method = $this->headers->get('X-HTTP-METHOD-OVERRIDE')) {
$this->method = strtoupper($method);
} elseif (self::$httpMethodParameterOverride) {
$method = $this->request->get('_method', $this->query->get('_method', 'POST'));
if (\is_string($method)) {
$this->method = strtoupper($method);
}
}
}
if (null !== $this->method) {
return $this->method;
}

$this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET'));

if ('POST' !== $this->method) {
return $this->method;
}

$method = $this->headers->get('X-HTTP-METHOD-OVERRIDE');

if (!$method && self::$httpMethodParameterOverride) {
$method = $this->request->get('_method', $this->query->get('_method', 'POST'));
}

if (!\is_string($method)) {
return $this->method;
}

$method = strtoupper($method);

if (\in_array($method, array('GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'), true)) {
return $this->method = $method;
}

if (!preg_match('/^[A-Z]++$/D', $method)) {
throw new \UnexpectedValueException(sprintf('Invalid method override "%s".', $method));
}

return $this->method;
return $this->method = $method;
}

/**
Expand Down

0 comments on commit 746f8d3

Please sign in to comment.