From 2348992f8e3045610636666af096911436fa1c89 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Fri, 16 Feb 2018 20:38:44 +0100 Subject: [PATCH] [BUGFIX] Use correct content types in backend ajax and eID responses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Due to the recent changes in the commit: e487cf526980570aa8f7a92d170bf439637c5972 [TASK] Create own response instance in controller actions ..ajax routes and eID handlers that used a *pre-generated* Response object (from the RequestHandler) now return different Content-Type headers than before. For backend ajax request applicaton/json was set by default, for eID scripts no Content-Type was set (by default). Change these controllers to use JsonResponse or a plain Response to reflect the previous state.. The changes in this commit were intended to be squashed into the mentioned commit – but this commit was too late. Therefore other (a bit) unrelated optimizations to changes that patch made are included. Change-Id: Icfdcd02d353dfaf48ad959c50be4802349eaaacd Releases: master Resolves: #83946 Related: #83939 Reviewed-on: https://review.typo3.org/55766 Tested-by: TYPO3com Reviewed-by: Anja Leichsenring Tested-by: Anja Leichsenring Reviewed-by: Christian Kuhn Tested-by: Christian Kuhn --- .../Backend/ToolbarItems/ShortcutToolbarItem.php | 5 +---- .../ToolbarItems/SystemInformationToolbarItem.php | 3 +-- .../Classes/Controller/ContextHelpAjaxController.php | 2 +- .../Classes/Controller/File/FileController.php | 2 +- .../FileSystemNavigationFrameController.php | 2 +- .../Classes/Controller/OnlineMediaController.php | 3 +-- .../Controller/Page/LocalizationController.php | 11 ++++++----- .../Classes/Form/Wizard/ImageManipulationWizard.php | 6 +++--- .../core/Classes/Controller/FileDumpController.php | 4 ++-- .../Classes/Controller/ShowImageController.php | 10 ++++++---- .../Controller/RsaPublicKeyGenerationController.php | 10 +++++++--- typo3/sysext/rsaauth/Classes/RsaEncryptionEncoder.php | 6 +++++- typo3/sysext/taskcenter/Classes/TaskStatus.php | 6 +++--- 13 files changed, 38 insertions(+), 32 deletions(-) diff --git a/typo3/sysext/backend/Classes/Backend/ToolbarItems/ShortcutToolbarItem.php b/typo3/sysext/backend/Classes/Backend/ToolbarItems/ShortcutToolbarItem.php index 6c3332d01134..178163cb112c 100644 --- a/typo3/sysext/backend/Classes/Backend/ToolbarItems/ShortcutToolbarItem.php +++ b/typo3/sysext/backend/Classes/Backend/ToolbarItems/ShortcutToolbarItem.php @@ -714,10 +714,7 @@ public function saveFormAction(ServerRequestInterface $request): ResponseInterfa } } - if ($queryBuilder->execute() === 1) { - return new HtmlResponse($shortcutName); - } - return new HtmlResponse('failed'); + return new HtmlResponse($queryBuilder->execute() === 1 ? $shortcutName : 'failed'); } /** diff --git a/typo3/sysext/backend/Classes/Backend/ToolbarItems/SystemInformationToolbarItem.php b/typo3/sysext/backend/Classes/Backend/ToolbarItems/SystemInformationToolbarItem.php index c4eed8bef763..3669eb8f7679 100644 --- a/typo3/sysext/backend/Classes/Backend/ToolbarItems/SystemInformationToolbarItem.php +++ b/typo3/sysext/backend/Classes/Backend/ToolbarItems/SystemInformationToolbarItem.php @@ -415,8 +415,7 @@ protected function getPageRenderer() protected function getSignalSlotDispatcher() { if (!isset($this->signalSlotDispatcher)) { - $this->signalSlotDispatcher = GeneralUtility::makeInstance(ObjectManager::class) - ->get(Dispatcher::class); + $this->signalSlotDispatcher = GeneralUtility::makeInstance(ObjectManager::class)->get(Dispatcher::class); } return $this->signalSlotDispatcher; } diff --git a/typo3/sysext/backend/Classes/Controller/ContextHelpAjaxController.php b/typo3/sysext/backend/Classes/Controller/ContextHelpAjaxController.php index e1af5cdf5007..5114c7ae29da 100644 --- a/typo3/sysext/backend/Classes/Controller/ContextHelpAjaxController.php +++ b/typo3/sysext/backend/Classes/Controller/ContextHelpAjaxController.php @@ -37,7 +37,7 @@ class ContextHelpAjaxController public function getHelpAction(ServerRequestInterface $request): ResponseInterface { $params = $request->getParsedBody()['params'] ?? $request->getQueryParams()['params']; - if ($params['action'] !== 'getContextHelp') { + if (($params['action'] ?? '') !== 'getContextHelp') { throw new \RuntimeException('Action must be set to "getContextHelp"', 1518787887); } $result = $this->getContextHelp($params['table'], $params['field']); diff --git a/typo3/sysext/backend/Classes/Controller/File/FileController.php b/typo3/sysext/backend/Classes/Controller/File/FileController.php index 372ff4238908..d62f3d1926ab 100644 --- a/typo3/sysext/backend/Classes/Controller/File/FileController.php +++ b/typo3/sysext/backend/Classes/Controller/File/FileController.php @@ -176,7 +176,7 @@ public function mainAction(ServerRequestInterface $request): ResponseInterface BackendUtility::setUpdateSignal('updateFolderTree'); // go and edit the new created file - if ($request->getParsedBody()['edit']) { + if ($request->getParsedBody()['edit'] ?? '') { /** @var \TYPO3\CMS\Core\Resource\File $file */ $file = $this->fileData['newfile'][0]; $properties = $file->getProperties(); diff --git a/typo3/sysext/backend/Classes/Controller/FileSystemNavigationFrameController.php b/typo3/sysext/backend/Classes/Controller/FileSystemNavigationFrameController.php index 785fee5fc2cf..905dad7781d4 100644 --- a/typo3/sysext/backend/Classes/Controller/FileSystemNavigationFrameController.php +++ b/typo3/sysext/backend/Classes/Controller/FileSystemNavigationFrameController.php @@ -231,7 +231,7 @@ public function ajaxExpandCollapse(ServerRequestInterface $request): ResponseInt $this->init(); $tree = $this->foldertree->getBrowsableTree(); if ($this->foldertree->getAjaxStatus() === false) { - return new HtmlResponse('', 500); + return new JsonResponse(null, 500); } return new JsonResponse([$tree]); } diff --git a/typo3/sysext/backend/Classes/Controller/OnlineMediaController.php b/typo3/sysext/backend/Classes/Controller/OnlineMediaController.php index a61cd120da69..02a6421b4c92 100644 --- a/typo3/sysext/backend/Classes/Controller/OnlineMediaController.php +++ b/typo3/sysext/backend/Classes/Controller/OnlineMediaController.php @@ -16,7 +16,6 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use TYPO3\CMS\Core\Http\HtmlResponse; use TYPO3\CMS\Core\Http\JsonResponse; use TYPO3\CMS\Core\Http\RedirectResponse; use TYPO3\CMS\Core\Localization\LanguageService; @@ -53,7 +52,7 @@ public function createAction(ServerRequestInterface $request): ResponseInterface } return new JsonResponse($data); } - return new HtmlResponse(''); + return new JsonResponse(); } /** diff --git a/typo3/sysext/backend/Classes/Controller/Page/LocalizationController.php b/typo3/sysext/backend/Classes/Controller/Page/LocalizationController.php index 8650faaadd33..bc86f0a615a7 100644 --- a/typo3/sysext/backend/Classes/Controller/Page/LocalizationController.php +++ b/typo3/sysext/backend/Classes/Controller/Page/LocalizationController.php @@ -20,7 +20,6 @@ use TYPO3\CMS\Backend\Domain\Repository\Localization\LocalizationRepository; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\DataHandling\DataHandler; -use TYPO3\CMS\Core\Http\HtmlResponse; use TYPO3\CMS\Core\Http\JsonResponse; use TYPO3\CMS\Core\Imaging\Icon; use TYPO3\CMS\Core\Imaging\IconFactory; @@ -71,7 +70,7 @@ public function getUsedLanguagesInPageAndColumn(ServerRequestInterface $request) { $params = $request->getQueryParams(); if (!isset($params['pageId'], $params['colPos'], $params['languageId'])) { - return new HtmlResponse('', 400); + return new JsonResponse(null, 400); } $pageId = (int)$params['pageId']; @@ -123,7 +122,7 @@ public function getRecordLocalizeSummary(ServerRequestInterface $request): Respo { $params = $request->getQueryParams(); if (!isset($params['pageId'], $params['colPos'], $params['destLanguageId'], $params['languageId'])) { - return new HtmlResponse('', 400); + return new JsonResponse(null, 400); } $records = []; @@ -158,11 +157,13 @@ public function localizeRecords(ServerRequestInterface $request): ResponseInterf { $params = $request->getQueryParams(); if (!isset($params['pageId'], $params['srcLanguageId'], $params['destLanguageId'], $params['action'], $params['uidList'])) { - return new HtmlResponse('', 400); + return new JsonResponse(null, 400); } if ($params['action'] !== static::ACTION_COPY && $params['action'] !== static::ACTION_LOCALIZE) { - return new HtmlResponse('Invalid action "' . $params['action'] . '" called.', 400); + $response = new Response('php://temp', 400, ['Content-Type' => 'application/json; charset=utf-8']); + $response->getBody()->write('Invalid action "' . $params['action'] . '" called.'); + return $response; } // Filter transmitted but invalid uids diff --git a/typo3/sysext/backend/Classes/Form/Wizard/ImageManipulationWizard.php b/typo3/sysext/backend/Classes/Form/Wizard/ImageManipulationWizard.php index 69ce4d190b80..f4637fa68a1e 100644 --- a/typo3/sysext/backend/Classes/Form/Wizard/ImageManipulationWizard.php +++ b/typo3/sysext/backend/Classes/Form/Wizard/ImageManipulationWizard.php @@ -17,7 +17,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use TYPO3\CMS\Core\Http\HtmlResponse; +use TYPO3\CMS\Core\Http\JsonResponse; use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException; use TYPO3\CMS\Core\Resource\ResourceFactory; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -71,9 +71,9 @@ public function getWizardAction(ServerRequestInterface $request): ResponseInterf 'cropVariants' => $queryParams['cropVariants'] ]; $content = $this->templateView->renderSection('Main', $viewData); - return new HtmlResponse($content); + return new JsonResponse($content); } - return new HtmlResponse('', 403); + return new JsonResponse(null, 403); } /** diff --git a/typo3/sysext/core/Classes/Controller/FileDumpController.php b/typo3/sysext/core/Classes/Controller/FileDumpController.php index f80f97c480f3..cb60a1984a17 100644 --- a/typo3/sysext/core/Classes/Controller/FileDumpController.php +++ b/typo3/sysext/core/Classes/Controller/FileDumpController.php @@ -16,7 +16,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use TYPO3\CMS\Core\Http\HtmlResponse; +use TYPO3\CMS\Core\Http\Response; use TYPO3\CMS\Core\Resource\Hook\FileDumpEIDHookInterface; use TYPO3\CMS\Core\Resource\ProcessedFileRepository; use TYPO3\CMS\Core\Resource\ResourceFactory; @@ -88,7 +88,7 @@ public function dumpAction(ServerRequestInterface $request) // @todo Refactor FAL to not echo directly, but to implement a stream for output here and use response return null; } - return new HtmlResponse('', 403); + return (new Response)->withStatus(403); } /** diff --git a/typo3/sysext/frontend/Classes/Controller/ShowImageController.php b/typo3/sysext/frontend/Classes/Controller/ShowImageController.php index 370988af5025..143f286c52c3 100644 --- a/typo3/sysext/frontend/Classes/Controller/ShowImageController.php +++ b/typo3/sysext/frontend/Classes/Controller/ShowImageController.php @@ -17,7 +17,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\Exception; -use TYPO3\CMS\Core\Http\HtmlResponse; +use TYPO3\CMS\Core\Http\Response; use TYPO3\CMS\Core\Resource\ProcessedFile; use TYPO3\CMS\Core\Resource\ResourceFactory; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -200,12 +200,14 @@ public function processRequest(ServerRequestInterface $request): ResponseInterfa try { $this->initialize(); $this->main(); - return new HtmlResponse($this->content); + $response = new Response(); + $response->getBody()->write($this->content); + return $response; } catch (\InvalidArgumentException $e) { // add a 410 "gone" if invalid parameters given - return new HtmlResponse('', 410); + return (new Response)->withStatus(410); } catch (Exception $e) { - return new HtmlResponse('', 404); + return (new Response)->withStatus(404); } } } diff --git a/typo3/sysext/rsaauth/Classes/Controller/RsaPublicKeyGenerationController.php b/typo3/sysext/rsaauth/Classes/Controller/RsaPublicKeyGenerationController.php index 2fa83acac94b..3bb91ea365f5 100644 --- a/typo3/sysext/rsaauth/Classes/Controller/RsaPublicKeyGenerationController.php +++ b/typo3/sysext/rsaauth/Classes/Controller/RsaPublicKeyGenerationController.php @@ -16,7 +16,8 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use TYPO3\CMS\Core\Http\HtmlResponse; +use TYPO3\CMS\Core\Http\JsonResponse; +use TYPO3\CMS\Core\Http\Response; use TYPO3\CMS\Rsaauth\Backend\BackendFactory; use TYPO3\CMS\Rsaauth\Storage\StorageFactory; @@ -35,7 +36,7 @@ public function processRequest(ServerRequestInterface $request): ResponseInterfa $backend = BackendFactory::getBackend(); if ($backend === null) { // add a HTTP 500 error code, if an error occurred - return new HtmlResponse('', 500); + return new JsonResponse(null, 500); } $keyPair = $backend->createNewKeyPair(); @@ -43,6 +44,9 @@ public function processRequest(ServerRequestInterface $request): ResponseInterfa $storage->put($keyPair->getPrivateKey()); session_commit(); $content = $keyPair->getPublicKeyModulus() . ':' . sprintf('%x', $keyPair->getExponent()) . ':'; - return new HtmlResponse($content); + + $response = new Response('php://temp', 200, ['Content-Type' => 'application/json; charset=utf-8']); + $response->getBody()->write($content); + return $response; } } diff --git a/typo3/sysext/rsaauth/Classes/RsaEncryptionEncoder.php b/typo3/sysext/rsaauth/Classes/RsaEncryptionEncoder.php index 5bb6dda07404..001ba3c4def0 100644 --- a/typo3/sysext/rsaauth/Classes/RsaEncryptionEncoder.php +++ b/typo3/sysext/rsaauth/Classes/RsaEncryptionEncoder.php @@ -16,6 +16,7 @@ use Psr\Http\Message\ResponseInterface; use TYPO3\CMS\Core\Http\HtmlResponse; +use TYPO3\CMS\Core\Http\Response; use TYPO3\CMS\Core\Page\PageRenderer; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -120,6 +121,9 @@ public function getRsaPublicKeyAjaxHandler(): ResponseInterface ]) ); } - return new HtmlResponse('No OpenSSL backend could be obtained for rsaauth.', 500); + + $response = new Response('php://temp', 500, ['Content-Type' => 'application/json; charset=utf-8']); + $response->getBody()->write('No OpenSSL backend could be obtained for rsaauth.'); + return $response; } } diff --git a/typo3/sysext/taskcenter/Classes/TaskStatus.php b/typo3/sysext/taskcenter/Classes/TaskStatus.php index 20aa6878f909..d67297ea20cd 100644 --- a/typo3/sysext/taskcenter/Classes/TaskStatus.php +++ b/typo3/sysext/taskcenter/Classes/TaskStatus.php @@ -16,7 +16,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use TYPO3\CMS\Core\Http\HtmlResponse; +use TYPO3\CMS\Core\Http\JsonResponse; /** * Status of tasks @@ -39,7 +39,7 @@ public function saveCollapseState(ServerRequestInterface $request): ResponseInte $this->getBackendUserAuthentication()->uc['taskcenter']['states'][$item] = $state; $this->getBackendUserAuthentication()->writeUC(); - return new HtmlResponse(''); + return new JsonResponse(null); } /** @@ -60,7 +60,7 @@ public function saveSortingState(ServerRequestInterface $request): ResponseInter $this->getBackendUserAuthentication()->uc['taskcenter']['sorting'] = serialize($sort); $this->getBackendUserAuthentication()->writeUC(); - return new HtmlResponse(''); + return new JsonResponse(null); } /**