Merge conflict

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

Review main Work in progress

98321[TASK] Issue preview tokens in the backend

Matthias Vogel CR 0 V 0 Hard +880 −1 updated 12/04/26, 10:25

Commit message

This adds an internal API that issues a preview token in the backend.
The classes are marked @internal. No core code uses them yet. Its
user is the later patch "Preview hidden pages across site domains"
(change 97235): `ViewModuleController` of the module Content > Preview
calls `PreviewTokenIssuer::issue()` and opens the address with the
token in the preview frame.

`IssuedPreview` contains the token, the address with the token and
the hosts of the preview. Change 97235 uses the address and the
hosts. The first code that reads `IssuedPreview::$token` comes in the
later patch "Follow the page of the preview frame in the backend":
`PreviewFrameFactory` sends the expiry time of the token to the
frame.

The backend must decide whether a backend user may get a preview
token for a page. `PreviewTokenIssuer::issue()` asks a set of rules,
issues the token with `PreviewTokenService::issue()`, and adds the
token to the frontend address with `QueryParameterReplacer`:

- The token simulates the current workspace of the backend user.
  Hosts in another workspace come in a later patch.
- The address loses `ADMCMD_prev` and an older token.
- `ADMCMD_simTime` and `ADMCMD_simUser` stay in the address. The site
  applies them as before. A later patch moves them into the token.
- A relative address is resolved against the backend, because a site
  without a host in its base runs on the backend host.

Each rule implements `PreviewTokenIssueRuleInterface` and returns a
`PreviewDecision`. The issuer asks the rules in the order of their
priority and stops at the first denial:

1. `WorkspaceRule`: the backend user has access to the current
   workspace.
2. `PageRule`: the page id names a page, and the backend user may
   show this page.
3. `AddressRule`: the backend user may preview a site, and the
   address is on a host of the preview (`PreviewHosts::isEmpty()`,
   `PreviewHosts::allowsUri()`).
4. `BackendSessionRule`: the backend user has a stored backend
   session. The token contains the ID of this session, and the site
   revokes the token when the session ends.

One place converts a denial into an exception. An address on no host
of the preview gives `AddressOutsidePreviewException`. The caller
then opens the address as it is, without a token. Each other denial
gives `PreviewTokenIssueDeniedException`. Both exceptions contain the
`PreviewDenialReason`. This patch adds the six reasons of the rules.

The rules use an own interface and not the security voters of change
98203. The series goes to main and 14.3, and 14.3 has no security
voter infrastructure.

This patch needs these patches:

- "Sign and verify preview tokens": `PreviewTokenService::issue()`
  and `PreviewTokenService::PARAMETER`. It needs "Add typed claims
  for preview tokens" for `PreviewSimulation` and `PreviewDecision`.
- "Resolve the sites and hosts a backend user may preview":
  `PreviewHostsResolver` and `PreviewHosts`.
- "Handle query parameters of links in one place":
  `QueryParameterReplacer`.

It is chained on top of "Check where a request with a preview token
comes from". 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: Ic9485120cc4f834f3d9ef3551ccdac6d6fe99126

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/21/98321/1 && git checkout FETCH_HEAD
Cherry-pick onto main
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/21/98321/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 Based on this change Matthias Vogel → main, 14.3 Expert +1994 −4 CR 0 V 0 Work in progress Merge conflict
  10. 98321 [TASK] Issue preview tokens in the backend This change

  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 13

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:30 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/116305

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

    Topic set to cross-domain-preview