From 222a9523b518940e3011d70a78884fc24d42eb18 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Fri, 8 Jul 2022 19:14:05 +0200 Subject: Fix 404 handling of requested JSON/XML If front-end or an application requests JSON/XML, there is no point in redirecting to the default page if that response doesn't exist. In the worst case that would just cause another request, therefore server load, traffic and a response that is meaningless to the requester. Signed-off-by: Christoph Wurst --- lib/base.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/base.php b/lib/base.php index 814f30b5af3..26ad684a81a 100644 --- a/lib/base.php +++ b/lib/base.php @@ -1048,6 +1048,13 @@ class OC { return; } + // Handle requests for JSON or XML + $acceptHeader = $request->getHeader('Accept'); + if (in_array($acceptHeader, ['application/json', 'application/xml'], true)) { + http_response_code(404); + return; + } + // Someone is logged in if (\OC::$server->getUserSession()->isLoggedIn()) { OC_App::loadApps(); -- cgit v1.2.3