98316[TASK] Add typed claims for preview tokens
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
- 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
- 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 This change
-
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.
Merge conflicts 6
- 98329[BUGFIX] Use preview tokens in the frames of the workspace preview
- 98328[TASK] Add a live view kind of preview token
- 98324[BUGFIX] Renew the preview token of the frame
- 98322[TASK] Accept preview tokens in the frontend
- 98321[TASK] Issue preview tokens in the backend
Show 1 more change Show less
Issues 1
Files 8
- typo3/sysext/core/Classes/Preview/PreviewDecision.phpnew+36 −0
- typo3/sysext/core/Classes/Preview/PreviewDenialReason.phpnew+31 −0
- typo3/sysext/core/Classes/Preview/PreviewSimulation.phpnew+45 −0
- typo3/sysext/core/Classes/Preview/PreviewToken.phpnew+39 −0
- typo3/sysext/core/Classes/Preview/PreviewTokenClaims.phpnew+129 −0
- typo3/sysext/core/Classes/Preview/PreviewTokenDeniedException.phpnew+43 −0
- typo3/sysext/core/Tests/Unit/Preview/PreviewDecisionTest.phpnew+44 −0
- typo3/sysext/core/Tests/Unit/Preview/PreviewTokenClaimsTest.phpnew+163 −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:44 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/116300
-
Matthias Vogel wrote 12/04/26, 10:25
Topic set to cross-domain-preview