Issue Bug Closed

#103085Deprecation strip_tags in stdWrap_stripHtml Passing null to parameter #1

Franz Holzinger 02/08/24, 20:15 updated 07/09/24, 15:33

Description

TYPO3 core raises a deprecation notice:

(1/1) #1476107295 TYPO3\CMS\Core\Error\Exception
*PHP Runtime Deprecation Notice: strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated* in /home/users/myuser/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php line 2033

at strip_tags()
in /home/users/myuser/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php line 2033

     * @return string The processed input value
     */
    public function stdWrap_stripHtml($content = '')
    {
        return strip_tags($content);
    }

Reviews 2

Files 1

History 1416

  1. Franz Holzinger commented 02/08/24, 20:39

    Solution:

        public function stdWrap_stripHtml($content = '')
        {
            return !empty($content) ? strip_tags($content) : '';
        }
  2. Andreas Kienast commented and changed status New Needs Feedback 02/09/24, 07:26

    Thank you. Can you by chance provide a strack trace, please?

  3. Franz Holzinger commented and changed attached fehler-103085-strip_tags.txt 02/09/24, 08:08

    See the attached file for the full backtrace.

    at TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer->stdWrap_stripHtml()
    in /home/users/myuser/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php line 1234
                        $isExecuted[$functionName] = true;
                        $isExecuted[$functionProperties] = true;
                        // Call the function with the prefix stdWrap_ to make sure nobody can execute functions just by adding their name to the TS Array
                        $functionName = 'stdWrap_' . $functionName;
                        $content = $this->{$functionName}($content, $singleConf);
                    } elseif ($functionType === 'boolean' && !($conf[$functionName] ?? null)) {
                        $isExecuted[$functionName] = true;
                        $isExecuted[$functionProperties] = true;
                    }
    at TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer->stdWrap()
    in /home/users/myuser/typo3/sysext/frontend/Classes/ContentObject/TextContentObject.php line 44
                $content = $this->cObj->stdWrap($content, $conf['value.']);
                unset($conf['value.']);
            }
            if (!empty($conf)) {
                $content = $this->cObj->stdWrap($content, $conf);
            }
            return $content;
        }
    }
  4. Andreas Kienast commented 02/09/24, 08:29

    Thanks for the strack trace. According to it, the offending method is called by ContentObjectRenderer->stdWrap(), which casts the input data to a string. Can you please provide more information how to reproduce this issue in a current v12?

  5. Franz Holzinger commented 02/09/24, 08:51

    See the complete backtrace file. There is a call from fh_debug. Maybe you can reproduce it by activating this extension.

    at TYPO3\CMS\Frontend\Http\RequestHandler->handle()
    in /home/users/myuser/typo3conf/ext/fh_debug/Classes/Middleware/Bootstrap.php line 45

    {
    $api = GeneralUtility::makeInstance(BootstrapApi::class);
    $api->init($request);
    return $handler->handle($request);
    }

    However this extension replaces one file in TYYPO3: fh_debug/Patches/TYPO3/sysext/core/Resources/PHP/GlobalDebugFunctions.php
    This must be replaced manually. And a debug line must be inserted into the PHP code. Then this should be reproducable.

  6. Benni Mack commented 02/09/24, 09:50

    Hey Franz,

    can you share your TypoScript which is executed and causes the problem?

  7. Franz Holzinger commented 02/09/24, 10:07

    I think there is no TypoScript involved.
    It is just the Middleware to initialze everything for the extension.

    class Bootstrap implements MiddlewareInterface
    {
    /** * Hook to initialze the error object * * param ServerRequestInterface $request * param RequestHandlerInterface $handler * @return ResponseInterface
    */
    <pre>
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface {
    $api = GeneralUtility::makeInstance(BootstrapApi::class);
    $api->init($request);
            return $handler->handle($request);
    }
    }

    Then the hander method is executed by TYPO3. I do not know what exactly it does there.

  8. Benni Mack commented 02/09/24, 10:08

    Hey Franz,

    Franz Holzinger wrote in #note-7:
    >
    > Then the hander method is executed by TYPO3. I do not know what exactly it does there.

    $api = GeneralUtility::makeInstance(BootstrapApi::class);
    $api->init($request);

    This code does not seem to be TYPO3 Core API?

  9. Franz Holzinger commented 02/09/24, 15:25

    This is the initialization code for the extension fh_debug.
    TYPO3 requires that no such code should be in the file ext_localconf.php any more.

  10. Stefan Bürk commented 02/10/24, 22:45

    >Benni Mack: can you share your TypoScript which is executed and causes the problem?
    >Franz Holzinger: I think there is no TypoScript involved.

    Please provide kind of TypoScript. ContentObjectRendere deals with rendering configuration, literlly `TypoScript`. So TypoScript is relevent to understand in which constellation through the call chain it ends up calling `ContentObjectRenderer::stdWrap_stripHtml()`.

    Given the call chain there must be some

    lib.someThing = TEXT
    # ....

    involved with stdWrap definitions at some point.

    Last place calling the `ContentObjectRenderer::stdWrap_stripHtml? is the L1234 in that class:

                        
    // Call the function with the prefix stdWrap_ to make sure nobody can execute functions just by adding their name to the TS Array
    $functionName = 'stdWrap_' . $functionName;
    $content = $this->{$functionName}($content, $singleConf); // <--- this is the call to stdWrap_stripHtml
    <code class="php">
    </code>

    which is prepared some lines above with null fallbacks for the method name and config

    // Get just that part of $conf that is needed for the particular function
    $singleConf = [
      $functionName => $conf[$functionName] ?? null,
      $functionProperties => $conf[$functionProperties] ?? null,
    ];

    As a loop is here involved, overriding $content with method call it may be another call beforehand to a stdWrap function returning `null` and than leading to this case.

    As this is a tricky part, getting some TypoScript to reproduce this would be nice – not ruleing out the named extension or now.

    What happens if you uninstall the extension ?

    So, at beast add a xdebug breakpoint and on a exception look into the variables provided and go up to find the “typoscript” part leading to this issue.

  11. Franz Holzinger commented 02/19/24, 13:57

    Here is the TypoScript which leads to the Runtime Exception:

    renderObj = COA
    renderObj {
    10 = TEXT
    10 {
    field = bodytext
    stripHtml = 1
    crop = 160 | … | 1
    }
    }

    The error happens when the bodytext is an empty string.

    Here is the full part:

    page = PAGE
    page {
    …
    meta {
    keywords.field = keywords
    keywords.ifEmpty = {$defaultkeywords}
    description.field = description # description.ifEmpty = {$defaultdescription}
    description.ifEmpty.stdWrap.cObject = CONTENT
    description.ifEmpty.stdWrap.cObject {
    table = tt_content
    select {
    selectFields = bodytext
    max = 1
    }
    renderObj = COA
    renderObj {
    10 = TEXT
    10 {
    field = bodytext
    stripHtml = 1
    crop = 160 | … | 1
    }
    }
    }
    robots = index,follow
    google-site-verification = xxx
    p:domain_verify = xxx
    viewport = width=device-width, initial-scale=1.0
    format-detection = telephone=no
    }
    }
  12. Gerrit Code Review pushed patch set 1 for main to change 84446 status Needs Feedback Under Review 05/29/24, 21:26

  13. Georg Ringer commented 05/29/24, 21:27

    had this also multiple times with updates and htmlSpecialChars calls

  14. Gerrit Code Review pushed patch set 1 for 12.4 to change 84458 05/31/24, 07:16

  15. Georg Ringer commented and changed status Under Review Resolved done 0 % 100 % 05/31/24, 07:20

    Applied in changeset commit:ad4c39b020b52e3a491c6c8d0bb5cecd8febf8da.

  16. Benni Mack changed status Resolved Closed 07/09/24, 15:33