#106002PathUtility::stripPathSitePrefix generates invalid paths for symlinked document root
Description
The static method PathUtility::stripPathSitePrefix removes the public path from the passed $path variable regardless whether the variable starts with the public path or not.
*Prerequisites*
The document root must contain a symbolic link somewhere in the hierarchy.
(!) The real path and the link path must have different lengths.
e.g.
Real path: /kunden/A/B/document_root
Environment Public path / Document Root via Apache: /www/A/B/document_root
*Steps to reproduce the problem*
In PHP call PathUtility::stripPathSitePrefix('/kunden/A/B/document_root/image.png');
Expected result: image.png
Actual result: ot/image.png
Our actual use case uses the GifBuilder to create grayscale images.
The GifBuilder creates an ImageInfo object that uses realpath values.
The public url for the image resource ends up with additional characters at the beginning (ot/typo3temp… instead of typo3temp…).
$imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $fullFileName);
$imageResource = ImageResource::createFromImageInfo($imageInfo);
// calls PathUtility::stripPathSitePrefix($imageInfo->getRealPath())
$imageResource->getPublicUrl();
*Solution*
From my limited core knowledge ;), I would suggest two changes to the function:
1. Use realpath to resolve symbolic links
2. Check if the path actually starts with the public path before using substring.
A possible implementation could be
/**
* Strip first part of a path, equal to the length of public web path including trailing slash
*
* @internal
*/
public static function stripPathSitePrefix(string $path): string
{
$realPath = realpath($path) ?: $path;
$realPublicPath = realpath(Environment::getPublicPath()) ?: Environment::getPublicPath();
if (str_starts_with($realPath, $realPublicPath)) {
return substr($realPath, strlen($realPublicPath . '/'));
}
return $path;
}Reviews 6
- 13.4 91353[BUGFIX] Prevent CLI cleanup:localprocessedfiles cleaning all files
- main 91316[BUGFIX] Prevent CLI cleanup:localprocessedfiles cleaning all files
- 13.4 91164[BUGFIX] Do not prefix URL in ImageResource
- main 91152[BUGFIX] Do not prefix URL in ImageResource
- 13.4 90854[BUGFIX] Do not strip public path from given realpath of a file
- main 90805[BUGFIX] Do not strip public path from given realpath of a file
Related issues 2
Files 1
History 1419
-
Kai Lochbaum changed subject
PathUtility::stripPathSitePrefix generats invalid paths for symlinked document rootPathUtility::stripPathSitePrefix generates invalid paths for symlinked document root <span data-processor="relativetime" data-value="2025-01-28T15:06:56+00:00" > 01/28/25, 15:06 </span> -
Garvin Hicking commented and changed status
NewNeeds Feedback <span data-processor="relativetime" data-value="2025-01-28T20:59:10+00:00" > 01/28/25, 20:59 </span> -
Jo Hasenau commented <span data-processor="relativetime" data-value="2025-03-15T00:33:36+00:00" > 03/15/25, 00:33 </span>
Can confirm this behaviour. In our case the path gets stripped too far:
/typo3temp/assets/images/1.0037_csm_werkstoffbild_b_535_7fb89db9f0_5a80befb89b8166f2912674d974051e4.jpg
becomes
/emp/assets/images/1.0037_csm_werkstoffbild_b_535_7fb89db9f0_5a80befb89b8166f2912674d974051e4.jpgand the image will of course not be found, because it was generated in the correct path.
Installation is in composer mode and deployed via deployer using symlinks for current and releases
-
Jo Hasenau changed status
Needs FeedbackAccepted priorityShould haveMust have <span data-processor="relativetime" data-value="2025-03-15T00:33:53+00:00" > 03/15/25, 00:33 </span> -
Claus Harup commented <span data-processor="relativetime" data-value="2025-08-28T10:26:37+00:00" > 08/28/25, 10:26 </span>
Any news on this issue?
-
Garvin Hicking commented <span data-processor="relativetime" data-value="2025-08-28T10:32:21+00:00" > 08/28/25, 10:32 </span>
No, no activity/contributions yet to my knowledge.
-
Claus Harup commented and changed attached gifbuilder.patch <span data-processor="relativetime" data-value="2025-09-02T09:49:22+00:00" > 09/02/25, 09:49 </span>
I have fixed it using the attached patch :-)
-
Garvin Hicking commented <span data-processor="relativetime" data-value="2025-09-02T17:31:28+00:00" > 09/02/25, 17:31 </span>
That looks quite good, would you like to add this as a patch to be properly attributed and so we can review?
(Else I could do that)
-
Ralph Brugger commented <span data-processor="relativetime" data-value="2025-09-25T15:29:50+00:00" > 09/25/25, 15:29 </span>
We were searching for hours through the code with this problem.
GIFBUILDER creates image-urls like this:
temp/assets/images/_830d1ab8316873169bf75578f01cb17c.png
correct would be:
typo3temp/assets/images/_830d1ab8316873169bf75578f01cb17c.png
The absolute filename is:
/srv/www/bst-update1/website/shared/public/typo3temp/assets/images/_830d1ab8316873169bf75578f01cb17c.png
and because the PathUtility::stripPathSitePrefix removes “the base” /srv/www/bst-update1/website/shared/public/typo3 the result becomes:
1) absolute filename: /srv/www/bst-update1/website/shared/public/typo3temp/assets/images/_830d1ab8316873169bf75578f01cb17c.png 2) remove /srv/www/bst-update1/website/shared/public/typo3 3) becomes temp/assets/images/_830d1ab8316873169bf75578f01cb17c.png
The above gifbuilder.patch works fine for us.
-
Helmut Hummel commented <span data-processor="relativetime" data-value="2025-09-25T20:52:49+00:00" > 09/25/25, 20:52 </span>
Kai Lochbaum wrote:
> The GifBuilder creates an ImageInfo object that uses realpath values.
This is the bug and what needs to be changed. Under no circumstances, the realpath can be used. We must always work with paths calculated and are provided in the Environment class
-
Gerrit Code Review pushed patch set 1 for main to change 90805 status
AcceptedUnder Review <span data-processor="relativetime" data-value="2025-09-25T21:33:55+00:00" > 09/25/25, 21:33 </span> -
Gerrit Code Review pushed patch set 2 for main to change 90805 <span data-processor="relativetime" data-value="2025-09-26T06:50:31+00:00" > 09/26/25, 06:50 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 90805 <span data-processor="relativetime" data-value="2025-09-26T07:27:27+00:00" > 09/26/25, 07:27 </span>
-
Gerrit Code Review pushed patch set 4 for main to change 90805 <span data-processor="relativetime" data-value="2025-09-26T07:29:29+00:00" > 09/26/25, 07:29 </span>
-
Gerrit Code Review pushed patch set 1 for 13.4 to change 90854 <span data-processor="relativetime" data-value="2025-10-01T09:14:38+00:00" > 10/01/25, 09:14 </span>
-
Helmut Hummel commented and changed status
Under ReviewResolved done0 %100 % <span data-processor="relativetime" data-value="2025-10-01T09:20:09+00:00" > 10/01/25, 09:20 </span>Applied in changeset commit:7d0c5e88d5f9d3ba2a2b15240b70c5c61add0a5d.
-
Helmut Hummel changed Related to #107758 <span data-processor="relativetime" data-value="2025-10-18T12:18:23+00:00" > 10/18/25, 12:18 </span>
-
Česlav Przywara changed Related to #107864 <span data-processor="relativetime" data-value="2025-10-27T17:23:34+00:00" > 10/27/25, 17:23 </span>
-
Benni Mack changed status
ResolvedClosed <span data-processor="relativetime" data-value="2025-12-02T14:27:34+00:00" > 12/02/25, 14:27 </span>
Could you add whether you’re using composer or classic mode?