Skip to content

Commit 5ff0944

Browse files
security #cve-2019-10913 [HttpFoundation] reject invalid method override (nicolas-grekas)
This PR was merged into the 4.1 branch. Discussion ---------- [HttpFoundation] reject invalid method override Based on #86 Commits ------- 742cd66 [HttpFoundation] reject invalid method override
2 parents a57ce22 + 742cd66 commit 5ff0944

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,22 +1211,37 @@ public function setMethod($method)
12111211
*/
12121212
public function getMethod()
12131213
{
1214-
if (null === $this->method) {
1215-
$this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET'));
1216-
1217-
if ('POST' === $this->method) {
1218-
if ($method = $this->headers->get('X-HTTP-METHOD-OVERRIDE')) {
1219-
$this->method = strtoupper($method);
1220-
} elseif (self::$httpMethodParameterOverride) {
1221-
$method = $this->request->get('_method', $this->query->get('_method', 'POST'));
1222-
if (\is_string($method)) {
1223-
$this->method = strtoupper($method);
1224-
}
1225-
}
1226-
}
1214+
if (null !== $this->method) {
1215+
return $this->method;
1216+
}
1217+
1218+
$this->method = strtoupper($this->server->get('REQUEST_METHOD', 'GET'));
1219+
1220+
if ('POST' !== $this->method) {
1221+
return $this->method;
1222+
}
1223+
1224+
$method = $this->headers->get('X-HTTP-METHOD-OVERRIDE');
1225+
1226+
if (!$method && self::$httpMethodParameterOverride) {
1227+
$method = $this->request->get('_method', $this->query->get('_method', 'POST'));
1228+
}
1229+
1230+
if (!\is_string($method)) {
1231+
return $this->method;
1232+
}
1233+
1234+
$method = strtoupper($method);
1235+
1236+
if (\in_array($method, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'], true)) {
1237+
return $this->method = $method;
1238+
}
1239+
1240+
if (!preg_match('/^[A-Z]++$/D', $method)) {
1241+
throw new SuspiciousOperationException(sprintf('Invalid method override "%s".', $method));
12271242
}
12281243

1229-
return $this->method;
1244+
return $this->method = $method;
12301245
}
12311246

12321247
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy