From a4b1cfb14de42bed6a9bb82c32f91c3aa5d2c487 Mon Sep 17 00:00:00 2001 From: peng-ni <8901577+peng-ni@users.noreply.github.com> Date: Wed, 25 May 2022 11:49:04 +0200 Subject: [PATCH] Fix regex to find token in cookie In the case when the CSRFP token is not at the beginning of the cookie header, the current regex will fail to detect the token correctly because of wrong slash escape in expression. --- js/csrfprotector.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/csrfprotector.js b/js/csrfprotector.js index ac58c55..5d1920c 100644 --- a/js/csrfprotector.js +++ b/js/csrfprotector.js @@ -44,7 +44,7 @@ var CSRFP = { * @return {String} auth key from cookie. */ _getAuthKey: function () { - var regex = new RegExp(`(?:^|;\s*)${CSRFP.CSRFP_TOKEN}=([^;]+)(;|$)`); + var regex = new RegExp(`(?:^|;\\s*)${CSRFP.CSRFP_TOKEN}=([^;]+)(;|$)`); var regexResult = regex.exec(document.cookie); if (regexResult === null) { return null;