Review main Work in progress

98318[TASK] Resolve the sites and hosts a backend user may preview

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

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

  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 This change

  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.

Merge conflicts 4

Issues 1

Files 5

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

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

    Topic set to cross-domain-preview