mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 18:48:51 +02:00
N°8910 - Upgrade Symfony packages
This commit is contained in:
@@ -351,16 +351,21 @@ class Request
|
||||
$server['PATH_INFO'] = '';
|
||||
$server['REQUEST_METHOD'] = strtoupper($method);
|
||||
|
||||
if (false === ($components = parse_url($uri)) && '/' === ($uri[0] ?? '')) {
|
||||
trigger_deprecation('symfony/http-foundation', '6.3', 'Calling "%s()" with an invalid URI is deprecated.', __METHOD__);
|
||||
$components = parse_url($uri.'#');
|
||||
unset($components['fragment']);
|
||||
if (($i = strcspn($uri, ':/?#')) && ':' === ($uri[$i] ?? null) && (strspn($uri, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.') !== $i || strcspn($uri, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'))) {
|
||||
throw new BadRequestException('Invalid URI: Scheme is malformed.');
|
||||
}
|
||||
|
||||
if (false === $components) {
|
||||
if (false === $components = parse_url(\strlen($uri) !== strcspn($uri, '?#') ? $uri : $uri.'#')) {
|
||||
throw new BadRequestException('Invalid URI.');
|
||||
}
|
||||
|
||||
$part = ($components['user'] ?? '').':'.($components['pass'] ?? '');
|
||||
|
||||
if (':' !== $part && \strlen($part) !== strcspn($part, '[]')) {
|
||||
throw new BadRequestException('Invalid URI: Userinfo is malformed.');
|
||||
}
|
||||
if (($part = $components['host'] ?? '') && !self::isHostValid($part)) {
|
||||
throw new BadRequestException('Invalid URI: Host is malformed.');
|
||||
}
|
||||
if (false !== ($i = strpos($uri, '\\')) && $i < strcspn($uri, '?#')) {
|
||||
throw new BadRequestException('Invalid URI: A URI cannot contain a backslash.');
|
||||
}
|
||||
@@ -543,7 +548,7 @@ class Request
|
||||
}
|
||||
|
||||
return
|
||||
sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n".
|
||||
\sprintf('%s %s %s', $this->getMethod(), $this->getRequestUri(), $this->server->get('SERVER_PROTOCOL'))."\r\n".
|
||||
$this->headers.
|
||||
$cookieHeader."\r\n".
|
||||
$content;
|
||||
@@ -644,7 +649,7 @@ class Request
|
||||
*/
|
||||
public static function setTrustedHosts(array $hostPatterns)
|
||||
{
|
||||
self::$trustedHostPatterns = array_map(fn ($hostPattern) => sprintf('{%s}i', $hostPattern), $hostPatterns);
|
||||
self::$trustedHostPatterns = array_map(fn ($hostPattern) => \sprintf('{%s}i', $hostPattern), $hostPatterns);
|
||||
// we need to reset trusted hosts on trusted host patterns change
|
||||
self::$trustedHosts = [];
|
||||
}
|
||||
@@ -1157,16 +1162,14 @@ class Request
|
||||
// host is lowercase as per RFC 952/2181
|
||||
$host = strtolower(preg_replace('/:\d+$/', '', trim($host)));
|
||||
|
||||
// as the host can come from the user (HTTP_HOST and depending on the configuration, SERVER_NAME too can come from the user)
|
||||
// check that it does not contain forbidden characters (see RFC 952 and RFC 2181)
|
||||
// use preg_replace() instead of preg_match() to prevent DoS attacks with long host names
|
||||
if ($host && '' !== preg_replace('/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/', '', $host)) {
|
||||
// the host can come from the user (HTTP_HOST and depending on the configuration, SERVER_NAME too can come from the user)
|
||||
if ($host && !self::isHostValid($host)) {
|
||||
if (!$this->isHostValid) {
|
||||
return '';
|
||||
}
|
||||
$this->isHostValid = false;
|
||||
|
||||
throw new SuspiciousOperationException(sprintf('Invalid Host "%s".', $host));
|
||||
throw new SuspiciousOperationException(\sprintf('Invalid Host "%s".', $host));
|
||||
}
|
||||
|
||||
if (\count(self::$trustedHostPatterns) > 0) {
|
||||
@@ -1189,7 +1192,7 @@ class Request
|
||||
}
|
||||
$this->isHostValid = false;
|
||||
|
||||
throw new SuspiciousOperationException(sprintf('Untrusted Host "%s".', $host));
|
||||
throw new SuspiciousOperationException(\sprintf('Untrusted Host "%s".', $host));
|
||||
}
|
||||
|
||||
return $host;
|
||||
@@ -1304,15 +1307,22 @@ class Request
|
||||
static::initializeFormats();
|
||||
}
|
||||
|
||||
$exactFormat = null;
|
||||
$canonicalFormat = null;
|
||||
|
||||
foreach (static::$formats as $format => $mimeTypes) {
|
||||
if (\in_array($mimeType, (array) $mimeTypes)) {
|
||||
return $format;
|
||||
if (\in_array($mimeType, $mimeTypes, true)) {
|
||||
$exactFormat = $format;
|
||||
}
|
||||
if (null !== $canonicalMimeType && \in_array($canonicalMimeType, (array) $mimeTypes)) {
|
||||
return $format;
|
||||
if (null !== $canonicalMimeType && \in_array($canonicalMimeType, $mimeTypes, true)) {
|
||||
$canonicalFormat = $format;
|
||||
}
|
||||
}
|
||||
|
||||
if ($format = $exactFormat ?? $canonicalFormat) {
|
||||
return $format;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1329,7 +1339,7 @@ class Request
|
||||
static::initializeFormats();
|
||||
}
|
||||
|
||||
static::$formats[$format] = \is_array($mimeTypes) ? $mimeTypes : [$mimeTypes];
|
||||
static::$formats[$format ?? ''] = (array) $mimeTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1472,7 +1482,7 @@ class Request
|
||||
public function getProtocolVersion(): ?string
|
||||
{
|
||||
if ($this->isFromTrustedProxy()) {
|
||||
preg_match('~^(HTTP/)?([1-9]\.[0-9]) ~', $this->headers->get('Via') ?? '', $matches);
|
||||
preg_match('~^(HTTP/)?([1-9]\.[0-9])\b~', $this->headers->get('Via') ?? '', $matches);
|
||||
|
||||
if ($matches) {
|
||||
return 'HTTP/'.$matches[2];
|
||||
@@ -1551,7 +1561,7 @@ class Request
|
||||
}
|
||||
|
||||
if (!\is_array($content)) {
|
||||
throw new JsonException(sprintf('JSON content was expected to decode to an array, "%s" returned.', get_debug_type($content)));
|
||||
throw new JsonException(\sprintf('JSON content was expected to decode to an array, "%s" returned.', get_debug_type($content)));
|
||||
}
|
||||
|
||||
return new InputBag($content);
|
||||
@@ -1577,7 +1587,7 @@ class Request
|
||||
}
|
||||
|
||||
if (!\is_array($content)) {
|
||||
throw new JsonException(sprintf('JSON content was expected to decode to an array, "%s" returned.', get_debug_type($content)));
|
||||
throw new JsonException(\sprintf('JSON content was expected to decode to an array, "%s" returned.', get_debug_type($content)));
|
||||
}
|
||||
|
||||
return $content;
|
||||
@@ -1923,9 +1933,8 @@ class Request
|
||||
}
|
||||
|
||||
$pathInfo = substr($requestUri, \strlen($baseUrl));
|
||||
if (false === $pathInfo || '' === $pathInfo) {
|
||||
// If substr() returns false then PATH_INFO is set to an empty string
|
||||
return '/';
|
||||
if (false === $pathInfo || '' === $pathInfo || '/' !== $pathInfo[0]) {
|
||||
return '/'.$pathInfo;
|
||||
}
|
||||
|
||||
return $pathInfo;
|
||||
@@ -1984,7 +1993,7 @@ class Request
|
||||
|
||||
$len = \strlen($prefix);
|
||||
|
||||
if (preg_match(sprintf('#^(%%[[:xdigit:]]{2}|.){%d}#', $len), $string, $match)) {
|
||||
if (preg_match(\sprintf('#^(%%[[:xdigit:]]{2}|.){%d}#', $len), $string, $match)) {
|
||||
return $match[0];
|
||||
}
|
||||
|
||||
@@ -2076,7 +2085,7 @@ class Request
|
||||
}
|
||||
$this->isForwardedValid = false;
|
||||
|
||||
throw new ConflictingHeadersException(sprintf('The request has both a trusted "%s" header and a trusted "%s" header, conflicting with each other. You should either configure your proxy to remove one of them, or configure your project to distrust the offending one.', self::TRUSTED_HEADERS[self::HEADER_FORWARDED], self::TRUSTED_HEADERS[$type]));
|
||||
throw new ConflictingHeadersException(\sprintf('The request has both a trusted "%s" header and a trusted "%s" header, conflicting with each other. You should either configure your proxy to remove one of them, or configure your project to distrust the offending one.', self::TRUSTED_HEADERS[self::HEADER_FORWARDED], self::TRUSTED_HEADERS[$type]));
|
||||
}
|
||||
|
||||
private function normalizeAndFilterClientIps(array $clientIps, string $ip): array
|
||||
@@ -2134,4 +2143,21 @@ class Request
|
||||
|
||||
return $this->isIisRewrite;
|
||||
}
|
||||
|
||||
/**
|
||||
* See https://url.spec.whatwg.org/.
|
||||
*/
|
||||
private static function isHostValid(string $host): bool
|
||||
{
|
||||
if ('[' === $host[0]) {
|
||||
return ']' === $host[-1] && filter_var(substr($host, 1, -1), \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6);
|
||||
}
|
||||
|
||||
if (preg_match('/\.[0-9]++\.?$/D', $host)) {
|
||||
return null !== filter_var($host, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4 | \FILTER_NULL_ON_FAILURE);
|
||||
}
|
||||
|
||||
// use preg_replace() instead of preg_match() to prevent DoS attacks with long host names
|
||||
return '' === preg_replace('/[-a-zA-Z0-9_]++\.?/', '', $host);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user