#81351The CSRF protection token for the requested module is missing or invalid
Description
In my module I have a list of all entries in Database.
$this->lebenslageRepository->findAll();
<div class="container" xmlns:f="http://www.w3.org/1999/html">
<f:widget.paginate objects="{lebenslage}" as="lebenslage" configuration="{itemsPerPage: 25, insertAbove: 0, insertBelow: 1, maximumNumberOfLinks: 10}">
<h2>Liste aller Lebenslagen</h2>
<f:link.action action="addForm" class="btn btn-primary">Neu</f:link.action>
<br/><br/>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>
Bezeichnung
</th>
<th></th>
</tr>
</thead>
<tbody>
<kk:widget.sort objects="{lebenslage}" as="lebenslage" property="bezeichnung">
<f:for each="{lebenslage}" as="lebenslage">
<tr>
<td>{lebenslage.bezeichnung}</td>
<td>
<f:link.action action="updateForm" arguments="{lebenslage:lebenslage}" class="btn btn-primary">
Bearbeiten
</f:link.action>
<f:link.action action="deleteForm" arguments="{lebenslage:lebenslage}" class="btn btn-primary">
Löschen
</f:link.action>
</td>
</tr>
</f:for>
</kk:widget.sort>
</tbody>
</table>
</f:widget.paginate>
<f:link.action action="addForm" class="btn btn-primary">Neu</f:link.action>
<f:link.action controller="Backend\Index" action="index" class="btn btn-secondary">Zurück</f:link.action>
</div>
<script>
var ajaxUrl = '<f:uri.action action="sortAjax" controller="{controllerName}" pageType="99"/>';
</script>
Next I wanted to sort all entries when I click on the
With the Sort-Widget-ViewHelper I wrote, I’m not able to insert the sort-button in my
var orderIcon = $(this).find('i.orderIcon');
if (!orderIcon.hasClass('ASC') && !orderIcon.hasClass('hide')) {
orderIcon.addClass('ASC');
} else if (orderIcon.hasClass('ASC')) {
orderIcon
.removeClass('ASC')
.addClass('hide');
} else if (orderIcon.hasClass('hide')) {
orderIcon.removeClass('hide');
}
$.ajax({
url: ajaxUrl,
method: 'POST'
...
...
});
But when I now click on my
With debugging I found the solution:
In the file TYPO3\CMS\Core\FormProtection there’s a method ‘validateToken(…)’.
My change in the else-part:
$tokenId = $_REQUEST['amp;moduleToken'];
if ((string)$tokenId === $validTokenId) {
$isValid = true;
} else {
$isValid = false;
}
In TYPO3\CMS\Backend\Http, Fct. ‘isValidModuleRequest()’ the token is searched in
$this->request->getQueryParams()['moduleToken']
but the queryParams look like:
Array
(
[M] => web_KkbaybwKkbaybw
[amp;moduleToken] => fffc6cc341becfcc9aead8b76a887f19fab988f6
[amp;tx_kkbaybw_web_kkbaybwkkbaybw] => Array
(
[action] => sortAjax
[controller] => Backend\Lebenslage
)
)
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.
History 5
-
Sylwester Szytula commented 09/07/17, 17:44
-
Oliver Hader changed Tags
csrf12/14/21, 17:28 -
Oliver Hader commented and changed status
NewIn Progress 12/14/21, 17:30Looks like regular URL parameters like
&moduleToken=is double-encoded to&moduleToken=which explains gettingamp;moduleTokenas parameter-name. I’ll look into that and most probably create test cases for URI ActionViewHelper… -
Oliver Hader changed category 12/14/21, 17:30
-
Georg Ringer commented and changed status
In ProgressClosed 10/22/26, 20:40This works as designed. The URL was HTML-escaped by Fluid, not double-encoded by the UriBuilder.
f:uri.actionreturns a string meant for HTML output and Fluid escapes it like every other ViewHelper output, so&becomes&(see the expectations inActionViewHelperTest, which assert&between the query parameters). When such a URL is put into a<script>block and used for an AJAX request, it has to be unescaped again, for example with<f:format.raw>around the ViewHelper, or better by passing the URL in adata-*attribute, which the browser decodes automatically. The suggestion from the comment of 2017-09-07 (f:format.htmlentitiesDecode) is the same workaround.The reported
moduleTokenandM=…query parameters of the legacy module URLs do not exist anymore since backend modules are registered as regular routes (#82406, TYPO3 v9), andf:widget.paginatefrom the template of the report was removed in v12.Closing this issue as works as designed.
If this is still valid for you in v14, please open a new issue and provide information how to reproduce it. Thanks!
I had the same problem. For me the solutions was to add f:format.htmlentitiesDecode, like: