#107026ViewHelper f:link.action / UriBuilder does not properly encode specified entities in URL parameter
Description
When using the following value as a parameter, e.g., from the current request URL or as an additional parameter of the f:link.action ViewHelper
https://git.uni-paderborn.de/api/v4/projects/3852/repository/files/METS_MODS%2Fmets_M0002.xml/raw
an encoding is performed by the UriBuilder in the ViewHelper, which generates the value as follows:
https%3A%2F%2Fgit.uni-paderborn.de%2Fapi%2Fv4%2Fprojects%2F3852%2Frepository%2Ffiles%2FMETS_MODS%2Fmets_M0002.xml%2Fraw
The problem is that the original %2F would need to be encoded as %252F , but it is ignored while the rest is encoded.
Therefore, the value we expect for the parameter here would be:
https%3A%2F%2Fgit.uni-paderborn.de%2Fapi%2Fv4%2Fprojects%2F3852%2Frepository%2Ffiles%2FMETS_MODS%252Fmets_M0002.xml%2Fraw
Example:
<f:link.action addQueryString="untrusted"
additionalParams="{'url':'https://git.uni-paderborn.de/api/v4/projects/3852/repository/files/METS_MODS%2Fmets_M0002.xml/raw'}">
View Product
</f:link.action>Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
History 6
-
Markus Weigelt commented <span data-processor="relativetime" data-value="2025-07-03T14:11:05+00:00" > 07/03/25, 14:11 </span>
-
Garvin Hicking commented and changed subject
ViewHelper f:link.action ignores encoded slash in URL ParameterViewHelper f:link.action / UriBuilder does not properly encode specified entities in URL parameter category statusNewNeeds Feedback <span data-processor="relativetime" data-value="2025-07-03T15:01:58+00:00" > 07/03/25, 15:01 </span>Adjusted category+title; thanks for the good example. I could verify this behaviour on v14/main, too.
I took a very deep rabbit hole dive to this as the URI routing is quite complex.
The ViewHelper result is routed through this beast:
TYPO3\CMS\Fluid\ViewHelpers\Link\ActionViewHelper->renderWithExtbaseContext() -> TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder->uriFor() -> TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder->build() -> TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder->buildFrontendUri() -> TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer->createUrl() -> TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer->createLink() -> TYPO3\CMS\Frontend\Typolink\LinkFactory->create() -> TYPO3\CMS\Frontend\Typolink\LinkFactory->buildLinkResult() -> TYPO3\CMS\Frontend\Typolink\PageLinkBuilder->build() -> TYPO3\CMS\Frontend\Typolink\PageLinkBuilder->generateUrlForPageWithSiteConfiguration() -> TYPO3\CMS\Core\Routing\PageRouter->generateUri() -> Symfony\Component\Routing\Generator\UrlGenerator->generate() -> TYPO3\CMS\Core\Routing\UrlGenerator->doGenerate() -> Symfony\Component\Routing\Generator\UrlGenerator->doGenerate()
Now, the Symfony UrlGenerator routing does this:
if ($extra && $query = http_build_query($extra, '', '&', \PHP_QUERY_RFC3986)) { $url .= '?'.strtr($query, self::QUERY_FRAGMENT_DECODED); }Note the
strtrwhich accesses this:private const QUERY_FRAGMENT_DECODED = [ // RFC 3986 explicitly allows those in the query/fragment to reference other URIs unencoded '%2F' => '/', '%252F' => '%2F', '%3F' => '?', // reserved chars that have no special meaning for HTTP URIs in a query or fragment // this excludes esp. "&", "=" and also "+" because PHP would treat it as a space (form-encoded) '%40' => '@', '%3A' => ':', '%21' => '!', '%3B' => ';', '%2C' => ',', '%2A' => '*', ];If you remove this entry:
'%252F' => '%2F',
from that array, the replacement of %252F to %2F is no longer performed, and this in the end leads to the final URI that you want to have.
My RFC-3986 skills are a bit rusty, so I don’t know half of what’s going on in that. But patching the array above has two major problems:
1.) It would need to be done from within Symfony, otherwise TYPO3 might completely maintain the class on its own. That private property is not meant to be configurable. So the way to go would be to report/discuss this on the
symfony/routingissue tracker (maybe there’s even issues about this, I did not check yet)2.) Changing it to remove the option will very likely break other integrations and lead to other issues.
So I do think this is a bit of an edge cases with full URIs passed as arguments. I have some ideas to maybe circumvent the issues:
a.) Use a link shortening service, and link to that URI (maybe even self-hosted)
b.) Use base64encode/decode on the URI input and output (so the extbase action where you evaluate the URI, you could decode it properly, which would prevent any special characters)
c.) Do NOT pass a URI as an argument at all, but instead pass identificators. Let your extbase action then map IDs to real URIs, and perform actions only on that. This could also increase security to not receive arbitrary URIs in your extbase action.
d.) Use a middleware to replace the wrongly generated links to real ones (with some kind of regular expression on your specific URIs)
e.) Try to configure the application on the other end to not generate these %2F special characters and maybe use less problematic separators
f.) Create your own ViewHelper that does post-processing on the generated URI to fixup the generated URI
Hope something sparks a possible way for you. I have little hope this is something we can easily address.
-
Garvin Hicking commented <span data-processor="relativetime" data-value="2025-07-03T15:03:28+00:00" > 07/03/25, 15:03 </span>
> Checked this more deeply and found the problem. The PHP parse_str function in the PageRouter class replaces ‘%2F’ with ‘/’.
Yes; note though that the problem at this point has already occured in the Symfony/router component, because it replaces ‘%252F’ with ‘%2F’. parse_str replacing
%2Fwith/is actually the right way to handle the input arguments. -
Markus Weigelt commented <span data-processor="relativetime" data-value="2025-07-04T13:39:40+00:00" > 07/04/25, 13:39 </span>
Garvin Hicking wrote in #note-3:
> > Checked this more deeply and found the problem. The PHP parse_str function in the PageRouter class replaces ‘%2F’ with ‘/’.
>
> Yes; note though that the problem at this point has already occured in the Symfony/router component, because it replaces ‘%252F’ with ‘%2F’. parse_str replacing%2Fwith/is actually the right way to handle the input arguments.Thank you for your quick feedback and all the great hints to work around this.
From my perspective, removing ‘%2F’ is incorrect because the URL itself is not encoded. This approach limits the possibility of nesting URLs (which probably won’t be needed often).
Another option would be to allow the ViewHelper to determine whether the parameters should be encoded. That way, we could pass the encoded parameter directly without further processing.
-
Garvin Hicking commented <span data-processor="relativetime" data-value="2025-07-04T15:17:33+00:00" > 07/04/25, 15:17 </span>
> From my perspective, removing ‘%2F’ is incorrect because the URL itself is not encoded. This approach limits the possibility of nesting URLs (which probably won’t be needed often).
I can understand that; but there might be other usage scenarios, given the broad usage of symfony/router…
> Another option would be to allow the ViewHelper to determine whether the parameters should be encoded. That way, we could pass the encoded parameter directly without further processing.
I’m afraid that’s not an easy option. The linkbuilding is so deeply nested (as you can see from the backtrace) that passing through another option/argument will be quite a lot of work. Most of these methods convert the arguments back and forth again.
I do think that trying to pass this “untrusted” query argument is something that should be avoided at the root. It could also open up all sorts of “open redirect proxy” or other security issues with it…
-
Georg Ringer commented and changed status
Needs FeedbackClosed <span data-processor="relativetime" data-value="2026-10-23T07:37:10+00:00" > 10/23/26, 07:37 </span>The encoding is lost in the Symfony Routing component, not in TYPO3:
Symfony\Component\Routing\Generator\UrlGeneratorpost-processes the generated query string with its privateQUERY_FRAGMENT_DECODEDmap, which contains'%252F' => '%2F'. TYPO3 cannot change that without replacing or patching the vendor class.Symfony treats this as intended behavior. It was introduced in symfony/symfony#39732 and a report asking to revert it (#48656, “No longer possible to generate URLs containing %252F”) was answered by a Symfony maintainer with “you need to figure out a way to make this work on your side”. A related discussion about the slash handling in query parameters is #45114.
A new ViewHelper argument to skip encoding is not feasible either, as the option would have to be passed through the whole link building chain (
ActionViewHelper→UriBuilder→ContentObjectRenderer→LinkFactory→PageLinkBuilder→PageRouter→ SymfonyUrlGenerator), which converts the arguments back and forth on the way.Workarounds as mentioned in the discussion: pass an identifier and resolve it to the URL in the action, base64-encode the URL (note that
/in the base64 alphabet is affected as well, so use the URL-safe variant), or post-process the generated link in a custom ViewHelper. Passing arbitrary URLs as query arguments should be avoided anyway because of open-redirect risks.
Checked this more deeply and found the problem. The PHP parse_str function in the PageRouter class replaces ‘%2F’ with ‘/’.
https://github.com/TYPO3/typo3/blob/83ec7d5add968537bf7af529a418d5481f241155/typo3/sysext/core/Classes/Routing/PageRouter.php#L364C46-L364C70