Merge conflict
Gerrit cannot merge this change. It needs a rebase onto main.
98322[TASK] Accept preview tokens in the frontend
Commit message
This adds an internal function: sites accept the preview tokens that the backend issues. All new classes are marked @internal. No core code issues a token yet. The bug fix "Preview hidden pages across site domains" for #110664 uses this function: the module Content > Preview issues a token, and the site of the page accepts it. The module cannot show a hidden page on a site whose host the backend login cookie does not reach. A preview token takes the backend user to such a site. The patches below add the parts. This patch connects them in the frontend. The new middleware PreviewTokenAuthenticator runs before BackendUserAuthenticator. It handles a request with the query parameter PreviewTokenService::PARAMETER in this order: - A navigation of a whole window gets a redirect to the address without the token. The site does not read the token. - PreviewTokenService verifies the token. - PreviewBackendUserInitializer builds the backend user of the token from the database, on each request. It is a ReadOnlyBackendUserAuthentication in the workspace of the token. The initializer makes the checks of BackendUserAuthenticator: BE/IPmaskList, BE/lockSSL, BE/adminOnly and isUserAllowedToLogin(). As there, the value "0" of BE/IPmaskList switches the check of the IP address off. The token does not know the original backend user of the "switch user" mode. Thus BE/adminOnly applies to the backend user of the token. - PreviewHostsResolver resolves the hosts of the backend user, and PreviewRequestCheck asks the rules where the request comes from and where it goes. - The backend user has access to the language of the request. - The read-only backend user becomes the backend user of the request. The new middleware PreviewTokenPagePermissions runs after the routing. It checks that the backend user of the token may show the page, with doesUserHaveAccess() and Permission::PAGE_SHOW, in the workspace of the token. It reads the workspace version of the page without the checks of the start time, the end time, the hidden flag and the frontend user groups. PreviewSimulator applies the simulated date and groups only after this check, so a scheduled or restricted version is part of the preview. A denial gives a denial page with the status 403 and the reason. The site never falls back to the live page. Each answer of the preview has these properties: - No page cache, "Cache-Control: private, no-store", "X-Robots-Tag: noindex" and "Referrer-Policy: no-referrer". - Only the site and the backend can frame it (frame-ancestors). - A redirect to an address outside the preview loses the token. BackendUserAuthenticator and WorkspacePreview skip a request with a token. Thus the backend login cookie or a keyword of the workspace preview, also "LIVE", cannot replace the backend user or the workspace of the token. CacheHashCalculator excludes the token from the cHash. The feature toggle "backend.previewToken" is enabled by default. While it is disabled, sites ignore the parameter. The port to 14.3 sets the toggle to false by default. This patch does not do these things: - It applies only the workspace of the simulation. The date and the frontend user groups come from ADMCMD_simTime and ADMCMD_simUser, as for a backend login. The later patch "Apply the date and the frontend groups of a preview token" reads them from the token. - It checks the backend access itself. The later patch "Check the backend access of a preview through BackendAccessCheck" changes this to BackendAccessCheck::check(). - Links, forms and redirects in the preview do not keep the token yet. The denial page sends no message to the backend yet. This patch needs these patches: - [TASK] Add a read-only backend user for one workspace - [TASK] Sign and verify preview tokens (after "[TASK] Add typed claims for preview tokens") - [TASK] Resolve the sites and hosts a backend user may preview - [BUGFIX] Handle query parameters of links in one place - [TASK] Check where a request with a preview token comes from It is chained on top of "[TASK] Issue preview tokens in the backend" and does not use code of that patch. Merge the patches below it in the chain first, then this patch.
Show more Show less
Resolves: #TBD Related: #110664 Releases: main, 14.3 Change-Id: I05fd322782120eb752a171f061c85658ebe5850c
Test this change
Run a command in your clone of the TYPO3 Core. Then try what the change does and vote on Verified in Gerrit. How to review a patch
- Check out patch set 1
-
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/22/98322/1 && git checkout FETCH_HEAD
- Cherry-pick onto main
-
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/22/98322/1 && git cherry-pick FETCH_HEAD
Review
-
Code review CR 0 Needs a vote
-
Verified V 0 Needs a vote
- core-ci +1 CI
Relation chain 16
- 98329[BUGFIX] Use preview tokens in the frames of the workspace preview
- 98328[TASK] Add a live view kind of preview token
- 98327[BUGFIX] Follow the page of the preview frame in the backend
- 98326[BUGFIX] Keep the preview token in navigations that scripts start
- 98325[BUGFIX] Keep the preview token in links, forms and redirects
- 98324[BUGFIX] Renew the preview token of the frame
- 98323[TASK] Add one frame component for the preview frames of the backend
- 97235[BUGFIX] Preview hidden pages across site domains
-
98322 [TASK] Accept preview tokens in the frontend This change
- 98321[TASK] Issue preview tokens in the backend
- 98320[TASK] Check where a request with a preview token comes from
- 98319[BUGFIX] Handle query parameters of links in one place
- 98318[TASK] Resolve the sites and hosts a backend user may preview
- 98317[TASK] Sign and verify preview tokens
- 98316[TASK] Add typed claims for preview tokens
-
98315[TASK] Add a read-only backend user for one workspace
The chain has patch set 1 of 2, the changes above it need a rebase.
Issues 1
Files 15
- typo3/sysext/core/Classes/Preview/PreviewDenialReason.php+13 −2
- typo3/sysext/core/Classes/Preview/PreviewToken.php+5 −0
- typo3/sysext/core/Configuration/DefaultConfiguration.php+1 −0
- typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml+3 −0
- typo3/sysext/frontend/Classes/Authentication/PreviewBackendUserInitializer.phpnew+122 −0
- typo3/sysext/frontend/Classes/Middleware/BackendUserAuthenticator.php+6 −0
- typo3/sysext/frontend/Classes/Middleware/PreviewTokenAuthenticator.phpnew+284 −0
- typo3/sysext/frontend/Classes/Middleware/PreviewTokenPagePermissions.phpnew+118 −0
- typo3/sysext/frontend/Classes/Page/CacheHashCalculator.php+3 −2
- typo3/sysext/frontend/Configuration/RequestMiddlewares.php+23 −0
- typo3/sysext/frontend/Resources/Private/Language/preview.xlfnew+35 −0
- typo3/sysext/frontend/Tests/Functional/Middleware/PreviewTokenAuthenticatorCacheHashTest.phpnew+134 −0
- typo3/sysext/frontend/Tests/Functional/Middleware/PreviewTokenAuthenticatorTest.phpnew+1225 −0
- typo3/sysext/frontend/Tests/Unit/Page/CacheHashCalculatorTest.php+17 −0
- typo3/sysext/workspaces/Classes/Middleware/WorkspacePreview.php+5 −0
Review log 23
-
Matthias Vogel uploaded patch set 1 12/04/26, 09:02
-
core-ci voted on patch set 1 V +1 12/04/26, 09:21 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/116304
-
Matthias Vogel wrote 12/04/26, 10:25
Topic set to cross-domain-preview