Vulnerability: Invalid HTTP method overrides allow possible XSS or other attacks in Symfony In Symfony before 2.7.51, 2.8.x before 2.8.50, 3.x before 3.4.26, 4.x before 4.1.12, and 4.2.x before 4.2.7, HTTP Methods provided as verbs or using the override header may be treated as trusted input, but they are not validated, possibly causing SQL injection or XSS. This is related to symfony/http-foundation.
Vulnerability ID: GHSA-x92h-wmg2-6hp7
CWE: CWE-89
Severity score: 9.8
Project: https://github.com/symfony/symfony
Published: 2019-12-02
File: src/Symfony/Component/HttpFoundation/Request.php
Commit message: [HttpFoundation] reject invalid method override
Commit author: Nicolas Grekas

Vulnerable version (before fix):
 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);                     }                 }             }         }          return $this->method;     }      /**

Fixed version (after fix):
 public function setMethod($method)      */     public function getMethod()     {         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, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'], true)) {             return $this->method = $method;         }          if (!preg_match('/^[A-Z]++$/D', $method)) {             throw new SuspiciousOperationException(sprintf('Invalid method override "%s".', $method));         }          return $this->method = $method;     }      /**

Patch:
patch: @@ -1346,22 +1346,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, ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'PATCH', 'PURGE', 'TRACE'], true)) {
+            return $this->method = $method;
+        }
+
+        if (!preg_match('/^[A-Z]++$/D', $method)) {
+            throw new SuspiciousOperationException(sprintf('Invalid method override "%s".', $method));
         }
 
-        return $this->method;
+        return $this->method = $method;
     }
 
     /**
path: src/Symfony/Component/HttpFoundation/Request.php