aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2025-07-01 11:24:27 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2025-07-01 11:24:27 +0200
commit79f4e0de7620e3ed7e0c4dca0b41a7c342cd67ce (patch)
treef6b66ff61bf5e29e5adb7f193ade108623bbe0f4
parente8bc35ec0a6e8eed2208fdba3b4671771ee626f9 (diff)
downloadnextcloud-server-fix/properly-fail-on-invalid-json.tar.gz
nextcloud-server-fix/properly-fail-on-invalid-json.zip
fix: Only attempt to decode JSON input if it is not an empty stringfix/properly-fail-on-invalid-json
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r--lib/private/AppFramework/Http/Request.php11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/private/AppFramework/Http/Request.php b/lib/private/AppFramework/Http/Request.php
index 348aeb0b7c2..e662cb8679a 100644
--- a/lib/private/AppFramework/Http/Request.php
+++ b/lib/private/AppFramework/Http/Request.php
@@ -390,10 +390,13 @@ class Request implements \ArrayAccess, \Countable, IRequest {
// 'application/json' and other JSON-related content types must be decoded manually.
if (preg_match(self::JSON_CONTENT_TYPE_REGEX, $this->getHeader('Content-Type')) === 1) {
- try {
- $params = json_decode(file_get_contents($this->inputStream), true, flags:JSON_THROW_ON_ERROR);
- } catch (\JsonException $e) {
- $this->decodingException = $e;
+ $content = file_get_contents($this->inputStream);
+ if ($content !== '') {
+ try {
+ $params = json_decode($content, true, flags:JSON_THROW_ON_ERROR);
+ } catch (\JsonException $e) {
+ $this->decodingException = $e;
+ }
}
if (\is_array($params) && \count($params) > 0) {
$this->items['params'] = $params;