Review main Work in progress

98316[TASK] Add typed claims for preview tokens

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

Commit message

This patch adds an internal API: typed objects for the content of a
preview token, the check of each claim and the decision of a preview
rule. The classes are marked @internal. No code in the core uses them
yet. The next patch "Sign and verify preview tokens" builds a
`PreviewToken` from `PreviewTokenClaims` in `PreviewTokenService`.
Later patches of #110664 use the objects:

- "Check where a request with a preview token comes from" reads the
  backend user and the backend session of a `PreviewToken`. Each of
  its request rules returns a `PreviewDecision`.
- "Accept preview tokens in the frontend" applies the workspace of
  the `PreviewSimulation` and denies a request with a
  `PreviewTokenDeniedException`.
- "Apply the date and the frontend groups of a preview token" is the
  first user of the date, the frontend login and the frontend user
  groups of the `PreviewSimulation`.
- "Issue preview tokens in the backend" creates the
  `PreviewSimulation` of a new token. Each of its backend rules
  returns a `PreviewDecision`.
- "Renew the preview token of the frame" copies the
  `PreviewSimulation` of the previous token into the fresh token.
- "Follow the page of the preview frame in the backend" is the first
  code that reads `PreviewToken::$expires`. It tells the frame when
  its token expires.

A preview token travels in the URI of a preview. Everybody who sees
the URI can read the claims of the token. A token from another source
can contain any value. Thus the site must check the type and the
range of each claim before it uses the claim.

The patch adds these classes:

- `PreviewSimulation` contains what a preview simulates: the
  workspace, the date, the frontend login and the frontend user
  groups. A simulation of groups always simulates the login too.
- `PreviewTokenClaims` reads the claims of a decoded token and checks
  each of them: "typ", "exp", "uah", "bk", "prf" with its fields and
  "sub". It ignores claims that it does not know. The message of a
  denial names the first claim that does not fit. Thus an
  administrator can find the cause of a denial.
- `PreviewToken` contains a verified token.
- `PreviewTokenDeniedException` tells with a `PreviewDenialReason`
  why the site denies a token.
- `PreviewDecision` contains the result of a preview rule: allowed,
  or denied with a `PreviewDenialReason`. It follows
  `BackendAccessDecision` of "Check backend access of a user in one
  place", but it does not need that patch. The constructor takes the
  reason, null for an allowed preview, so the class has no static
  constructor.

`PreviewTokenClaims` does not check the claim "ses". This claim
contains the backend session encrypted, and only the token service
has the key. The patch "Sign and verify preview tokens" checks it.

`PreviewDenialReason` is a backed enum, not a set of string constants
like `BackendAccessRules::REASON_*`. The reasons of
`BackendAccessRules` are messages for an administrator. The value of
a denial reason is an identifier. "Accept preview tokens in the
frontend" uses it in a label key of the denial page. "Renew the
preview token of the frame" uses it in the message to the backend
frame. The message of the exception contains the text for an
administrator. The
enum contains only the reason that this patch uses. Each later patch
adds the reasons that it uses.

This patch is chained on top of "Add a read-only backend user for
one workspace" (change 98315). It does not use code of that patch.
Merge that patch first, then this patch. "Sign and verify preview
tokens" is chained on top of this patch.
Show more Show less
Resolves: #TBD
Related: #110664
Releases: main, 14.3
Change-Id: I5deea51f8827a524e5e2347b9ddb2ca524b6c569

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/16/98316/1 && git checkout FETCH_HEAD
Cherry-pick onto main
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/16/98316/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 Based on this change 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

  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.

Merge conflicts 6

Show 1 more change Show less

Issues 1

Files 8

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/116300

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

    Topic set to cross-domain-preview