CSRFGuard - request token does not match session token

蹲街弑〆低调 提交于 2019-12-04 19:33:09

In case anyone stumbles across a similar issue:

Turned out that accessing the app using IE wasn't passing a token to an AJAX call, this would in turn result in the tokens being refreshed but the links in the already rendered page remained, causing the mismatch when clicked.

Found out the issue by building CSRFGuard myself from source and adding extra logging.

The primefaces commandlink and commandbutton seem to cause the csrfguard javascript to malfunction, if you have use these two component with ajax set to true (which is the default), it can prevent the token being injected after the ajax call

One of the possible fixes is to change the following 2 lines in Owasp.CsrfGuard.js file.

Change

 function injectTokenForm(form, tokenName, tokenValue, pageTokens) {
    var action = form.attribute("action");

To

 function injectTokenForm(form, tokenName, tokenValue, pageTokens) {
    var action = form.attributes["action"].value;

AND

Change

 function injectTokenAttribute(element, attr, tokenName, tokenValue, pageTokens) {

    location = element.getAttribute(attr);

To

 function injectTokenAttribute(element, attr, tokenName, tokenValue, pageTokens) {
    var location = null;
    if (attr == "action") {
        location = element.attributes[attr].value;

    } else {
        location = element.getAttribute(attr);
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!