Merge conflict

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

Review main Work in progress

98326[BUGFIX] Keep the preview token in navigations that scripts start

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

Commit message

A page that a preview token shows in the frame of the backend loses
the token when a script of the page starts a navigation, for example
with window.location.assign() or a form sent via HTTP GET. The site
then opens the next page without the token, and the frame shows the
live page. A link with the target _top or _parent has a second
problem: it opens the page in the window around the frame. The
backend disappears, and the site opens the page without the token.

The new middleware PreviewNavigationScript adds the module
@typo3/frontend/preview-navigation to each HTML page that a preview
token shows in the frame. A fetch or a script file of the page does
not get the module. A request without Fetch Metadata, as on a plain
HTTP site, gets it. The module does these things:

- It adds the token of the page to a navigation that a script starts.
  It uses the Navigation API for this. It does this only for an
  address on the origin of the page, because this origin is a host of
  the preview. Thus the module needs no list of hosts, and the scripts
  of the site do not learn the other hosts of the backend user.
- It does not change these navigations: an address that has a token,
  an address on another origin, a form sent via HTTP POST, a download
  and a navigation in the same document. The Navigation API cannot
  send the data of a form again.
- It opens a link with the target _top or _parent in the frame.

In a browser without the Navigation API, the module only keeps these
links in the frame.

The module must run under the Content-Security-Policy of the site.
The middleware gives the script the nonce of the request and adds the
hash of the file to script-src-elem. Where a policy of the site lists
this hash, the script also gets its integrity. Thus policies with
nonces, policies with hashes and policies with 'strict-dynamic' run
the script. The module imports nothing, because the site has no
import map of the backend and such a policy blocks a second script.

The middleware adds the script to the HTML of the answer, not through
AssetCollector. Thus the script also reaches pages that the
PageRenderer does not render. The Gerrit change 94054 "Add nonce to
JavaScript modules" is related: it adds the nonce to the modules of
AssetCollector. This patch does not need it.

The changelog entry of "Preview hidden pages across site domains"
gets the section "Navigations that scripts start". It describes the
module and how it runs under the Content-Security-Policy of the site.
The line about links, forms and redirects in the frame now also names
the navigations that scripts start. It refers to this section and to
the section of "Keep the preview token in links, forms and
redirects".

This patch does not do these things. The later patch "Follow the page
of the preview frame in the backend" adds them:

- The module does not tell the backend the address of the frame, and
  an address on another host of the preview opens without the token.
- The module does not take a renewed token from the backend.

This patch needs "[BUGFIX] Preview hidden pages across site domains",
because it changes the changelog entry of that patch. That patch
contains "[TASK] Accept preview tokens in the frontend", which adds
the preview token to the request. It is chained on top of "[BUGFIX]
Keep the preview token in links, forms and redirects", because both
patches change the same line of the changelog entry. Merge the
patches below it in the chain first, then this patch.
Show more Show less
Resolves: #TBD
Related: #110664
Releases: main, 14.3
Change-Id: I101c375afc86257d20ea2f71961093976304cfb7

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

  5. 98325[BUGFIX] Keep the preview token in links, forms and redirects This change is based on it 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 This change is based on it 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 This change is based on it 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 This change is based on it 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 This change is based on it 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 This change is based on it 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 This change is based on it 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 This change is based on it 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 is based on it 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 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.

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

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

    Topic set to cross-domain-preview