Skip to content

Firefly III: a personal finances manager

Fix #7140 by better validating header content.

James Coledad738ae4250
diff --git a/app/Http/Middleware/AcceptHeaders.php b/app/Http/Middleware/AcceptHeaders.php
index 7905d004b6..19c243e8e9 100644
--- a/app/Http/Middleware/AcceptHeaders.php
+++ b/app/Http/Middleware/AcceptHeaders.php
@@ -56,11 +56,11 @@ class AcceptHeaders
}
// if bad 'Content-Type' header, refuse service.
if (('POST' === $method || 'PUT' === $method) && !$request->hasHeader('Content-Type')) {
- $error = new BadHttpHeaderException('Content-Type header cannot be empty');
+ $error = new BadHttpHeaderException('Content-Type header cannot be empty.');
$error->statusCode = 415;
throw $error;
}
- if (('POST' === $method || 'PUT' === $method) && !in_array($submitted, $contentTypes, true)) {
+ if (('POST' === $method || 'PUT' === $method) && !$this->acceptsHeader($submitted, $contentTypes)) {
$error = new BadHttpHeaderException(sprintf('Content-Type cannot be "%s"', $submitted));
$error->statusCode = 415;
throw $error;
@@ -74,4 +74,17 @@ class AcceptHeaders
return $next($request);
}
+
+ /**
+ * @param string $content
+ * @param array $accepted
+ * @return bool
+ */
+ private function acceptsHeader(string $content, array $accepted): bool
+ {
+ if (str_contains($content, ';')) {
+ $content = trim(explode(';', $content)[0]);
+ }
+ return in_array($content, $accepted, true);
+ }
}