Issue Bug Resolved

#109912Exception in frontend when sys_redirect target is database record

Philipp Schlosser 05/29/26, 09:34 updated 10/15/26, 16:15

Description

Bug #103937 seems to be back in version 14.

Creating custom linkhandler and redirecting to db record leads to Exception:

Call to a member function getId() on null

because there is no

$request->getAttribute('frontend.page.information')

in TYPO3\CMS\Frontend\Typolink\DatabaseRecordLinkBuilder

Steps to reproduce can be found in related issue #105648

Reviews 2

History 1114

  1. Felix Nagel commented <span data-processor="relativetime" data-value="2026-05-31T14:59:17+00:00" > 05/31/26, 14:59 </span>

    I can confirm this in TYPO3 14.3.2 with PHP 8.4 ad that the issue only appears for redirects with records as target.

  2. S P commented <span data-processor="relativetime" data-value="2026-06-17T06:30:30+00:00" > 06/17/26, 06:30 </span>

    I confirm this. v14. Wanted to check whether #101156 is still relevant on v14, and got this exception.

    Redirects and record links just don’t want to seem to play nicely together.

  3. S P commented <span data-processor="relativetime" data-value="2026-06-17T07:04:10+00:00" > 06/17/26, 07:04 </span>

    Did some analysis:

    RedirectService->bootFrontendController() actually does create this request attribute before the DatabaseRecordLinkBuilder gets called. This enriched ServerRequest is only passed into the ContentObjectRenderer. The DatabaseRecordLinkBuilder which will later be called seems to get the unaltered original request object.

    If I exchange, in DatabaseRecordLinkBuilder

    $pageInformation = $request->getAttribute(‘frontend.page.information’);

    with

    /** @var ContentObjectRenderer $cObj */
    $cObj = $request->getAttribute(‘currentContentObject’);
    $pageInformation = $cObj->getRequest()->getAttribute(‘frontend.page.information’);

    It works. The exception is then gone.

    This comes at the very end from the fact that TYPO3’s ServerRequest implementation does a clone when setting attributes.

    public function withAttribute(string $name, $value): static
    {
    $clonedObject = clone $this;

    So, if you never pass this cloned object back then you have multiple versions of the request object floating around. Which is highly dangerous. Why does it clone itself? That does not make any sense. A request is basically a global singleton object. Even if it does not implement these architectural properties, it is from a semantical POV a global singleton, because you only ever get a single HTTP request to the whole application.

  4. S P commented <span data-processor="relativetime" data-value="2026-06-17T07:13:18+00:00" > 06/17/26, 07:13 </span>

    I just saw this in ServerRequest->withAttribute(), which probably someone misunderstood:

    * This method MUST be implemented in such a way as to retain the
    * immutability of the message, and MUST return an instance that has the
    * updated attribute.

    This “immutability of the message” does not mean you have to clone the request object. This only means that withAttribute must not change anything else of the request object besides the one attribute in question. There’s no need for a clone. In fact cloning the request object can even cause a lot of harm and unneded assignments…

    From PSR:
    > The various interfaces have been written with verbiage indicating that immutability MUST be preserved, but only indicate that “an instance” must be returned containing the new state. Since instances that represent the same value are considered equal, returning $this is functionally equivalent, and thus allowed.

    This certainly is true for withAttribute and thus no cloning is ever needed when adding a new attribute to the request.

  5. Garvin Hicking commented <span data-processor="relativetime" data-value="2026-06-18T07:36:12+00:00" > 06/18/26, 07:36 </span>

    The cloning here is actually needed because otherwise followup calls to a request object would make it mutable…

    If you remove the `clone` in the class and execute the functional tests you will see a few scenarios that fail then:

    1) TYPO3\CMS\Extbase\Tests\Functional\Mvc\Validation\ActionControllerValidationTest::argumentsOfOriginalRequestRemainOnValidationErrors
    Failed asserting that two arrays are equal.
    --- Expected
    +++ Actual
    @@ @@
     Array (
    -    'blog' => [...]
    -    'blogPost' => [...]
     )
    
    9) TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest::samePathWithSameDomainT3Target with data set "flat keep_query_parameters" ('https://acme.com/flat-samehost-2', 'https://acme.com/', 200, null, null)
    Failed asserting that 404 matches expected 200.
    
    /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/typo3/sysext/redirects/Tests/Functional/Service/RedirectServiceTest.php:550
    
    10) TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest::samePathWithSameDomainT3Target with data set "flat keep_query_parameters - with query parameters" ('https://acme.com/flat-samehos...f7dca0', 'https://acme.com/', 200, null, null)
    Failed asserting that 404 matches expected 200.
    
    /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/typo3/sysext/redirects/Tests/Functional/Service/RedirectServiceTest.php:550
    
    11) TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest::samePathWithSameDomainT3Target with data set "regexp" ('https://acme.com/regexp-samehost-1', 'https://acme.com/', 200, null, null)
    Failed asserting that 404 matches expected 200.
    
    /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/typo3/sysext/redirects/Tests/Functional/Service/RedirectServiceTest.php:550
    
    12) TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest::samePathWithSameDomainT3Target with data set "regexp keep_query_parameters" ('https://acme.com/regexp-samehost-2', 'https://acme.com/', 200, null, null)
    Failed asserting that 404 matches expected 200.
    
    /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/typo3/sysext/redirects/Tests/Functional/Service/RedirectServiceTest.php:550
    
    13) TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest::samePathWithSameDomainT3Target with data set "regexp keep_query_parameters - with query parameters" ('https://acme.com/regexp-sameh...e51f1a', 'https://acme.com/', 200, null, null)
    Failed asserting that 404 matches expected 200.
    
    /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/typo3/sysext/redirects/Tests/Functional/Service/RedirectServiceTest.php:550
    
    14) TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest::samePathWithSameDomainT3Target with data set "regexp respect_query_parameters" ('https://acme.com/regexp-samehost-3', 'https://acme.com/', 200, null, null)
    Failed asserting that 404 matches expected 200.
    
    /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/typo3/sysext/redirects/Tests/Functional/Service/RedirectServiceTest.php:550
    
    15) TYPO3\CMS\Redirects\Tests\Functional\Service\RedirectServiceTest::samePathWithSameDomainT3Target with data set "same host as external target with fragment should pass instead of redirect" ('https://acme.com/sanatize-samehost-4', 'https://acme.com/', 200, null, null)
    Failed asserting that 404 matches expected 200.
    
    /Users/garvin/TYPO3/typo3-core-bugreproduce-base/typo3-core/typo3/sysext/redirects/Tests/Functional/Service/RedirectServiceTest.php:550
  6. S P commented <span data-processor="relativetime" data-value="2026-06-18T07:48:04+00:00" > 06/18/26, 07:48 </span>

    These are very likely different (but similar to this one here) architectural bugs at these places then, not inherently due the clone (the clone just “hides” them).

    But yeah, it’s super unlikely that the clone will go (it’s not only TYPO3 who got this messed up, but basically every bigger project since PSR-7 back in 2015, everyone just copy-pasted this cloning-misbehaviour and got used to it).

    So, a realistic solution is to write back the cloned but attribute-enriched request object back to all places, not just passing it into the ContentObjectRenderer.

  7. Georg Ringer commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-10-15T16:15:15+00:00" > 10/15/26, 16:15 </span>

    Applied in changeset commit:0a7bf7581517395dd7a4636a438c005709b2a6aa.