98318[TASK] Resolve the sites and hosts a backend user may preview
Commit message
This adds an internal API that resolves the sites and hosts that a backend user may preview. The classes PreviewHosts and PreviewHostsResolver are marked @internal. No core code uses them yet. These later patches for #110664 use them: - "Check where a request with a preview token comes from" adds rules that check with includesHostOf() and includesSite() that a request with a preview token comes to a host and a site of the preview. - "Issue preview tokens in the backend" resolves the hosts with resolve() when the backend issues a preview token. It refuses a token when isEmpty() is true, or when allowsUri() does not allow the address. - "Accept preview tokens in the frontend" resolves the hosts with resolve() on each request with a preview token. It removes the token from a Location header whose address allowsUrl() does not allow. - "Preview hidden pages across site domains" (change 97235) allows the preview frame of the backend to load the origins from getFrameSources(). A preview shows only pages of the sites that the backend user has access to, in the languages that the backend user has access to. The backend issues a preview token and the site accepts it. Both must get the same list of sites and hosts, so one class resolves this list. PreviewHostsResolver gets the sites from WebMountSiteFinder and the languages from Site::getAvailableLanguages(). It resolves each base of a site language against the address of the backend. Thus a site without a host in its base is previewed on the backend host. Bases on other schemes than HTTP and HTTPS are left out. PreviewHosts holds the result, for each base the site identifier, the host and the origin: - A host is in lower case and in its ASCII form, with the port if the base has one. Browsers send this form of an internationalized domain name, and the site matching compares it. - allowsUri() allows an address on HTTP or HTTPS without user information. It refuses plain HTTP to a host whose sites use HTTPS only, because the browser sends such an address in the clear before the site redirects to HTTPS. - allowsUrl() checks an address as it is written in a link, a form or a redirect. It refuses an address that browsers read differently from a URI parser: with a tab or a line break, with a control character or a space at either end, or with a backslash before the query. - getFrameSources() returns the origins. Above 50 origins it returns only their schemes, because a longer frame-src header is too large for common header buffers of web servers. The redirects extension has SourceHostProvider, which also combines WebMountSiteFinder with Site::getAvailableLanguages(). It is not reused, for these reasons: - It is internal to the redirects extension. - It adds the wildcard host and the hosts of all base variants. A preview needs only the bases of the current context. - It reads the backend user from $GLOBALS['BE_USER']. A preview resolves the hosts for a given backend user, also in the workspace of a preview token. - It returns host names without port, scheme and site identifier.
Show more Show less
Resolves: #TBD Related: #110664 Releases: main, 14.3 Change-Id: I1c9b834176f3c7f1c610ff6f4cd62c99797aff6a
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/18/98318/1 && git checkout FETCH_HEAD
- Cherry-pick onto main
-
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/18/98318/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
- 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 This change
- 98317[TASK] Sign and verify preview tokens
- 98316[TASK] Add typed claims for preview tokens
-
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 4
Issues 1
Files 5
- typo3/sysext/core/Classes/Preview/PreviewHosts.phpnew+224 −0
- typo3/sysext/core/Classes/Preview/PreviewHostsResolver.phpnew+54 −0
- typo3/sysext/core/Tests/Functional/Preview/Fixtures/PreviewHostsResolverTestImport.csvnew+11 −0
- typo3/sysext/core/Tests/Functional/Preview/PreviewHostsResolverTest.phpnew+156 −0
- typo3/sysext/core/Tests/Unit/Preview/PreviewHostsTest.phpnew+255 −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:18 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/116302
-
Matthias Vogel wrote 12/04/26, 10:25
Topic set to cross-domain-preview