tpwd / ke_search

Search Extension for TYPO3 Content Management System, including faceting search functions.
https://extensions.typo3.org/extension/ke_search/
GNU General Public License v3.0
8 stars 34 forks source link

404 when searching (caused by cHash error due to enforceValidation) #149

Closed MrMooky closed 1 year ago

MrMooky commented 1 year ago

I have an odd issue and I'm not sure whether this is related to my (regular) setup, or ke_search.

When opening the search page, eg. domain.de/suche I see a few results and also the search bar. When I type something into the search field and submit, I get the 404 page. The url then is domain.de/suche/?tx_kesearch_pi1%5Bsword%5D=test.

TYPO3 11.5.25 PHP 8.1.13 Extension is up-to-date

Any idea what the cause might be?

MrMooky commented 1 year ago

Was caused by this setting in my local conf:

'cacheHash' => [
    'enforceValidation' => true,
],
christianbltr commented 1 year ago

Thanks for pointing to this issue. I will reopen this because ke_search should work also if the option "enforceValidation" is enabled.

This option has been introduced in 10.4.35/11.5.23/12.2 and is recommended to be enabled and is enabled by default for new installations, see https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/Configuration/Typo3ConfVars/FE.html#enforcevalidation

secured commented 1 year ago

is there a status update on this yet?

schlotzz commented 1 year ago

This behaviour also occured on my installation.

Disabling enforceValidation did the job, but as stated by @christianbltr is not an optimal solution.

Is there any information I can provide to proceed with this issue?

christianbltr commented 1 year ago

It is not possible to calculate a cHash because ke_search uses a form to send data and the form options are modified by the user.

As far as I understand the correct solution would be to use the

[FE][cHashExcludedParameters]

option to exclude the ke_search parameters from cHash calculation as described in

https://stackoverflow.com/questions/56787705/how-to-handel-the-chash-on-a-get-form

Does that work in your case?

From the ke_search point of view the only thing to do would be to add this information in the documentation, including a list of parameters which should be excluded.

schlotzz commented 1 year ago

@christianbltr Thanks a lot for pointing that out. I didn't know about this configuration option, yet.

Adding the following code to my ext_localconf.php did work for me instead of disabling enforceValidation.

$GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParameters'] = array_merge(
    $GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParameters'],
    [
        'tx_kesearch_pi1[sortByField]',
        'tx_kesearch_pi1[sortByDir]',
        'tx_kesearch_pi1[resetFilters]',
        'tx_kesearch_pi1[page]',
        'tx_kesearch_pi1[sword]', // must be changed if "plugin.tx_kesearch_pi1.searchWordParameter" has been set
        'tx_kesearch_pi1[page]',
    ]
);

Don't forget to add your custom filters.

christianbltr commented 1 year ago

Thanks for providing your solution. It's now integrated into ke_search and a new documentation page explains how to add parameters if the search word parameter has been changed or filters are used:

https://github.com/tpwd/ke_search/blob/master/Documentation/Configuration/Avoid404Error.rst

schlotzz commented 1 year ago

Thanks for integrating the solution and adding a documentation.

Hawkeye1909 commented 1 year ago

Hi @christianbltr! I have a follow-up question on this topic: how do you exclude the filters?

With the solution you added, you exclude 'tx_kesearch_pi1[filter]' among others. However, the individual filters generate parameters of the pattern 'tx_kesearchpi1[filter#uid#]' or 'tx_kesearchpi1[filter#uid#_#option#]' (where #option# depends on the filter type). So the existing solution is not enough and I added '^tx_kesearchpi1[filter' at my sitepackage. But in principle '^tx_kesearch_pi1' would actually also be sufficient to exclude all search parameters, wouldn't it?

christianbltr commented 1 year ago

Currently you will need to manually exclude the filters, each option separately, see the example in https://github.com/tpwd/ke_search/blob/master/Documentation/Configuration/Avoid404Error.rst#example

That is quite inconvenient, therefore I opened https://github.com/tpwd/ke_search/issues/187 for that.