Skip to content

Commit

Permalink
[BUGFIX] No CORS Error in WS preview
Browse files Browse the repository at this point in the history
We should not manipulate document.domain in workspace preview as we need
to communicate with our parent master window.

Releases: master, 8.7
Resolves: #78401
Change-Id: Id3f581545a5547ca4ab8c46ee204b1c947ff6e56
Reviewed-on: https://review.typo3.org/56843
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
  • Loading branch information
opi99 authored and bmack committed May 11, 2018
1 parent 37ece89 commit 9f1e154
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 23 deletions.
Expand Up @@ -160,15 +160,11 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac
}
$this->moduleTemplate->getPageRenderer()->addInlineSetting('Workspaces', 'SplitPreviewModes', $splitPreviewModes);

$backendDomain = $request->getAttribute('normalizedParams')->getRequestHostOnly();
$this->getBackendUser()->setAndSaveSessionData('workspaces.backend_domain', $backendDomain);

$this->view->assignMultiple([
'logoLink' => TYPO3_URL_GENERAL,
'liveUrl' => $liveUrl ?? false,
'wsUrl' => $wsUrl,
'wsSettingsUrl' => $wsSettingsUrl,
'backendDomain' => $backendDomain,
'activeWorkspace' => $availableWorkspaces[$activeWorkspace],
'splitPreviewModes' => $splitPreviewModes,
'firstPreviewMode' => current($splitPreviewModes),
Expand Down
Expand Up @@ -242,21 +242,12 @@ public function singleIndexAction()
$activeWorkspace = $this->getBackendUser()->workspace;
$wsCur = [$activeWorkspace => true];
$wsList = array_intersect_key($wsList, $wsCur);
$backendDomain = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY');
$this->view->assignMultiple([
'pageUid' => (int)GeneralUtility::_GP('id'),
'showGrid' => true,
'workspaceList' => $this->prepareWorkspaceTabs($wsList, (int)$activeWorkspace, false),
'activeWorkspaceUid' => $activeWorkspace,
'backendDomain' => $backendDomain
]);
// Setting the document.domain early before JavScript
// libraries are loaded, try to access top frame reference
// and possibly run into some CORS issue
$this->pageRenderer->setMetaCharsetTag(
$this->pageRenderer->getMetaCharsetTag() . LF
. GeneralUtility::wrapJS('document.domain = ' . GeneralUtility::quoteJSvalue($backendDomain) . ';')
);
$this->pageRenderer->addInlineSetting('Workspaces', 'singleView', '1');
}

Expand Down
Expand Up @@ -268,13 +268,6 @@ protected function getPreviewData(string $keyword)
*/
protected function renderPreviewInfo(TypoScriptFrontendController $tsfe, NormalizedParams $normalizedParams): string
{
$backendDomain = $GLOBALS['BE_USER']->getSessionData('workspaces.backend_domain') ?: $normalizedParams->getRequestHostOnly();

$content = '<script type="text/javascript">
// having this is very important, otherwise the parent.resize call will fail
document.domain = ' . GeneralUtility::quoteJSvalue($backendDomain) . ';
</script>';

if (!isset($tsfe->config['config']['disablePreviewNotification']) || (int)$tsfe->config['config']['disablePreviewNotification'] !== 1) {
// get the title of the current workspace
$currentWorkspaceId = $tsfe->whichWorkspace();
Expand Down
Expand Up @@ -70,7 +70,4 @@
</div>
</div>
</div>
<script type="text/javascript">
document.domain = '{backendDomain}';
</script>
</html>

0 comments on commit 9f1e154

Please sign in to comment.