Merge conflict

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

Review main Work in progress

98317[TASK] Sign and verify preview tokens

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

Commit message

This patch adds an internal API: `PreviewTokenService` issues and
verifies short-lived preview tokens. The class is marked @internal.
No code in the core uses it yet. Later patches of #110664 use it:

- "Check where a request with a preview token comes from" reads the
  backend session of the verified token and checks that the session
  is still active.
- "Accept preview tokens in the frontend" calls `verify()` in the
  frontend middleware and reads the token from the query parameter
  `PreviewTokenService::PARAMETER`.
- "Issue preview tokens in the backend" calls `issue()` when a
  backend user opens a preview and adds the token to the URI with the
  query parameter `PreviewTokenService::PARAMETER`.

The backend must give the browser a short-lived proof that a backend
user opened a preview. A site on another domain must check this proof
without a shared session, because the backend session cookie does not
reach it.

The service signs a JWT with a key that it derives from the
encryption key of the installation. `verify()` denies a token in
these cases:

- The token is malformed, or its signature is not valid.
- One of its claims does not fit (`PreviewTokenClaims`).
- The backend clock is more than 60 seconds ahead of the site clock.
- The token expired more than 60 seconds ago. The lifetime is 15
  minutes.
- The browser is not the browser for which the backend issued the
  token. The token contains a hash of the user agent.

The token also contains the backend session id. The site uses it to
revoke the token when the backend session ends. The backend session
id is the secret of the backend session cookie, and everybody who
sees the URI can read the claims. Thus the service encrypts the id
with `CipherService`. The backend user id is the additional data of
the cipher. Thus the cipher is valid only for this backend user.

The JWT library reads its clock and its leeway from public static
properties that any code can set. The service sets its own clock and
leeway for each check and restores the old values after the check.

An expired token stays in the exception when its signature and its
claims are valid. The later patch "Renew the preview token of the
frame" uses the backend origin of this token to ask the backend for a
fresh token.

`PreviewDenialReason` gets the reasons "expired" and "otherBrowser".

This patch needs "Add typed claims for preview tokens": `issue()` and
`verify()` use `PreviewSimulation` and `PreviewToken`, and `verify()`
checks the claims with `PreviewTokenClaims`. Merge that patch first,
then this patch.
Show more Show less
Resolves: #TBD
Related: #110664
Releases: main, 14.3
Change-Id: Ie5d5112e823f4cea0853cba377afbc3f17272041

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/17/98317/1 && git checkout FETCH_HEAD
Cherry-pick onto main
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/17/98317/1 && git cherry-pick FETCH_HEAD

Review

  • Code review CR 0 Needs a vote
  • Verified V -1 Blocked
    • 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 Based on this change 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 Based on this change 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 Based on this change 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 Based on this change 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

  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 3

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

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

    Topic set to cross-domain-preview