From 2d06ea5cfc46f12c89dc50a7b73f87de350f8c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= <jus@bitgrid.net> Date: Tue, 18 Jun 2019 13:09:38 +0200 Subject: [PATCH] Properly redirect if accessing invalid file though /f/ entrypoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl <jus@bitgrid.net> --- apps/files/lib/Controller/ViewController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 9f9cd0b33c1..cf1b4374da4 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -31,6 +31,7 @@ namespace OCA\Files\Controller; use OCA\Files\Activity\Helper; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\ContentSecurityPolicy; +use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\TemplateResponse; @@ -138,7 +139,11 @@ class ViewController extends Controller { */ public function showFile(string $fileid = null): Response { // This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server. - return $this->redirectToFile($fileid); + try { + return $this->redirectToFile($fileid); + } catch (NotFoundException $e) { + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); + } } /** -- GitLab