Merge conflict

Gerrit cannot merge this change. It needs a rebase onto main.

Review main Work in progress

98322[TASK] Accept preview tokens in the frontend

Matthias Vogel CR 0 V 0 Expert +1994 −4 updated 12/04/26, 10:25

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

  1. 98329[BUGFIX] Use preview tokens in the frames of the workspace preview Based on this change Matthias Vogel → main, 14.3 Hard +580 −55 CR 0 V 0 Work in progress Merge conflict
  2. 98328[TASK] Add a live view kind of preview token Based on this change Matthias Vogel → main, 14.3 Hard +771 −73 CR 0 V 0 Work in progress Merge conflict
  3. 98327[BUGFIX] Follow the page of the preview frame in the backend Based on this change Matthias Vogel → main, 14.3 Expert +1225 −114 CR 0 V -1 Work in progress Merge conflict
  4. 98326[BUGFIX] Keep the preview token in navigations that scripts start Based on this change Matthias Vogel → main, 14.3 Hard +922 −4 CR 0 V 0 Work in progress Merge conflict
  5. 98325[BUGFIX] Keep the preview token in links, forms and redirects Based on this change Matthias Vogel → main, 14.3 Hard +828 −38 CR 0 V 0 Work in progress Merge conflict
  6. 98324[BUGFIX] Renew the preview token of the frame Based on this change Matthias Vogel → main, 14.3 Expert +1634 −63 CR 0 V 0 Work in progress Merge conflict
  7. 98323[TASK] Add one frame component for the preview frames of the backend Based on this change Matthias Vogel → main, 14.3 Hard +544 −68 CR 0 V 0 Work in progress Merge conflict
  8. 97235[BUGFIX] Preview hidden pages across site domains Based on this change Matthias Vogel → main, 14.3 Hard +467 −10 CR 0 V 0 Work in progress Merge conflict 19 unresolved
  9. 98322 [TASK] Accept preview tokens in the frontend This change

  10. 98321[TASK] Issue preview tokens in the backend This change is based on it Matthias Vogel → main, 14.3 Hard +880 −1 CR 0 V 0 Work in progress Merge conflict
  11. 98320[TASK] Check where a request with a preview token comes from This change is based on it Matthias Vogel → main, 14.3 Hard +934 −1 CR 0 V 0 Work in progress Merge conflict
  12. 98319[BUGFIX] Handle query parameters of links in one place This change is based on it Matthias Vogel → main, 14.3 Hard +435 −20 CR 0 V 0 Work in progress
  13. 98318[TASK] Resolve the sites and hosts a backend user may preview This change is based on it Matthias Vogel → main, 14.3 Hard +700 −0 CR 0 V 0 Work in progress
  14. 98317[TASK] Sign and verify preview tokens This change is based on it Matthias Vogel → main, 14.3 Hard +625 −0 CR 0 V -1 Work in progress Merge conflict
  15. 98316[TASK] Add typed claims for preview tokens This change is based on it Matthias Vogel → main, 14.3 Hard +530 −0 CR 0 V -1 Work in progress
  16. 98315[TASK] Add a read-only backend user for one workspace This change is based on it Matthias Vogel → main, 14.3 Expert +1719 −2 CR 0 V 0 Work in progress

    The chain has patch set 1 of 2, the changes above it need a rebase.

Issues 1

Files 15

Review log 23

  1. Matthias Vogel uploaded patch set 1 12/04/26, 09:02

  2. 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

  3. Matthias Vogel wrote 12/04/26, 10:25

    Topic set to cross-domain-preview