98319[BUGFIX] Handle query parameters of links in one place
Commit message
Three places in the core add, replace or remove one parameter in the
query of an address. Each place has its own code for this task:
* WorkspacePreview builds the links in the info box of a workspace
preview: to the page without the preview and to the live version
of the page. It also builds the link back to the page in the
logout message. It parses the query and builds it again.
* AbstractContentSecurityPolicyReporter::anonymizeUri() removes the
parameter "token" from the addresses in a CSP report. It also
parses the query and builds it again.
* EditDocumentController appends "columnsOnly=" as a string to the
query of the link of the button "Edit whole record".
A parsed and rebuilt query loses data. In the links of the workspace
preview, a repeated name ("tag=1&tag=2") lost all values but the
last one, "tag[]=1&tag[]=2" lost one value, and "+" (a space) became
"%2B" (a plus sign). The page then got other parameters, for example
a search page showed other results.
The new internal class QueryParameterReplacer (TYPO3\CMS\Core\Http)
is now the one place for this task. It adds, replaces or removes one
parameter and keeps every other byte of the query. A pair counts by
the name that PHP reads from it, because the site reads the query in
the same way. The three places above use this class now. Thus the
links of the workspace preview keep the query of the page address.
The CSP report now keeps the query of an address as the browser sent
it. Before, "a.b=1" became "a_b=1", "flag" became "flag=", and a
repeated name ("tag=1&tag=2") kept only the last value. This change
is visible in the backend module "Content Security Policy". The
summary of a report is calculated from the blocked address. Thus a
new report for a blocked address with such a query can get a
different summary, and the module shows it apart from older reports
for the same address. The token is removed as before, also with a
name like "token[]", " token" or "tok%65n".
The link of the button "Edit whole record" had the list of fields
("columnsOnly[tt_content][0]=header") and an empty "columnsOnly" after
it. PHP read only the last one. The link now has only the empty
parameter.
GuzzleHttp\Psr7\Uri::withoutQueryValue() is not used. It compares
the decoded names only. Thus a parameter like "ADMCMD_prev[]" or
"ADMCMD.prev" stays in the address, although the site reads it as
"ADMCMD_prev". It also needs a URI object, which changes the bytes
of an address as it is written in a link, a form or a redirect.
HttpUtility::buildQueryString() builds a query from an array. Thus
it loses the same data as a parsed and rebuilt query.
Three later patches of the preview token series use the class:
* "Issue preview tokens in the backend" removes "ADMCMD_prev" and an
older token from the preview address and adds the new token
(withoutParameter(), withParameter()).
* "Accept preview tokens in the frontend" removes the token from an
address as it is written (removeFromUrl()). It does this in a
redirect to an address outside the preview, and in the redirect
that takes the token out of the address bar. Its test adds a
token to an address with replaceInUrl().
* "Keep the preview token in links, forms and redirects" is the first
code that uses replaceInUrl(). PreviewTokenKeeper::keepInUrl() puts
the token into the links, forms and redirects of a preview.
The test of the logout link leaves out a list in brackets
("tag[]=1&tag[]=2") until change 98199 (#111661) is merged, which
can happen before or after this change.
Show more Show less
Resolves: #TBD Related: #110664 Related: #111661 Releases: main, 14.3 Change-Id: I1eb9007e2a458e7e381df65a75853a5df0952407
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/19/98319/1 && git checkout FETCH_HEAD
- Cherry-pick onto main
-
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/19/98319/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 This change
- 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
-
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 15
- 98322[TASK] Accept preview tokens in the frontend
- 96159[TASK] Use short translation domain syntax in EXT:workspaces
- 96543[WIP][POC][TASK] Write and read records by the same rules and rights
- 94845[FEATURE] Emit CSP report-to with Reporting API headers
- 98199[BUGFIX] Format the workspace preview logout message only once
- 97304[WIP][BUGFIX] Render the record form from unsaved values
- 97616[BUGFIX] Count references and translations per pid in the backend
- 95741[BUGFIX] Offer localization only where it is permitted
- 96348[FEATURE] Add identifiers for DocHeader buttons
- 95145[TASK] Migrate LanguageService->sL() labels to new domain syntax
- 95278[FEATURE] Add event to render content around record edit form
- 94653[WIP] Record Identity
- 92943[WIP][TASK] Deprecate inline language labels (TYPO3.lang)
- 92959[WIP][TASK] Use ICU message format for pluralization
- 80380[WIP][TASK] Sync navigation component context
Show 10 more changes Show less
Issues 2
Files 9
- typo3/sysext/backend/Classes/Controller/EditDocumentController.php+3 −3
- typo3/sysext/backend/Tests/Functional/Controller/EditDocumentControllerTest.php+22 −0
- typo3/sysext/core/Classes/Http/QueryParameterReplacer.phpnew+108 −0
- typo3/sysext/core/Classes/Middleware/AbstractContentSecurityPolicyReporter.php+3 −3
- typo3/sysext/core/Tests/Functional/Security/ContentSecurityPolicy/Reporting/BeforePersistingReportEventTest.php+49 −2
- typo3/sysext/core/Tests/Unit/Http/QueryParameterReplacerTest.phpnew+161 −0
- typo3/sysext/workspaces/Classes/Middleware/WorkspacePreview.php+7 −12
- typo3/sysext/workspaces/Tests/Functional/Middleware/Fixtures/WorkspacePreview.csv+3 −0
- typo3/sysext/workspaces/Tests/Functional/Middleware/WorkspacePreviewTest.php+79 −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:19 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/116303
-
Matthias Vogel wrote 12/04/26, 10:25
Topic set to cross-domain-preview