How to prevent foreign GET parameters in TYPO3's canonical tag?

Viewed 633

If an uncached page is called in the frontend with a GET parameter that is not foreseen and has been appended to the URL from a link of an external source, like a tracking parameter or something worse e.g. …

https://www.example.com/?note=any-value

… then this foreign parameter is passed on in the automatically generated canonical tag, created by TYPO3's core extension ext:seo. It looks like this:

<link rel="canonical" href="https://www.example.com/?note=any-value&amp;cHash=f2c206f6f14a424fdbf82f683e8bf383"/>

In addition, the page is saved in the cache with this parameter. This means that subsequent visitors will also receive this incorrect canonical tag, even if they call up the page https://www.example.com/ without the parameter.

Is this a bug (tested on TYPO3 10.4.15) or can it be disabled for all unknown parameters by configuration?

If you know the parameter, you can exclude it in the configuration:

[FE][cacheHash][excludedParameters] = L,pk_campaign,pk_kwd,utm_source,utm_medium,…

I am only concerned with parameters that were not expected. It might make sense to turn the concept around and basically exclude all parameters except for a few self-defined allowed parameters, but I don't know if that is possible so far.

2 Answers

Got it. Actually, TYPO3 handles these already for other common tracking and additional params, like L, utm_campaign, fbclid etc. The whole list of excluded params can be found in the source code.

To add your own, just add/modify the typo3conf/AdditionalConfiguration.php file i.e. just like:

<?php

$GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParameters'][] = 'note';
$GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParameters'][] = 'foo';
$GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParameters'][] = 'bar';

or

<?php

$GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParameters'] = array_merge(
    $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParameters'],
    ['note', 'foo', 'bar'],
);

Don't forget to clear caches after all :D (that should be a TYPO3's slogan)

It's a bug. The extension urlguard2 solves this issue.

Related