You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[ISSUE]: CSRF Token Cookie Parsing Logic Bug in security.js #396
Description:
In getCSRFToken() function in frontend/js/security.js, the cookie parsing logic has a subtle bug. The loop uses indexOf() incorrectly - it checks if the cookie string CONTAINS the search term anywhere but doesn't properly match cookie boundaries:
// In getCSRFToken (lines 159-167):for(leti=0;i<cookieArray.length;i++){letcookie=cookieArray[i].trim()if(cookie.indexOf(name)===0){// BUG: indexOf returns position, not boolean!returncookie.substring(name.length)}}
The issue is that cookie.indexOf(name) === 0 is incorrect because:
It should use cookie.startsWith(name) or compare with === 0
More critically, the code should also check for = after the cookie name to properly parse cookie values
Steps to fix:
Open frontend/js/security.js
Find the getCSRFToken() function
Replace the cookie parsing loop with:
for(leti=0;i<cookieArray.length;i++){letcookie=cookieArray[i].trim();// Properly check if this cookie starts with the name and has = separatorif(cookie.startsWith(name)||cookie.indexOf(name+'=')===0){// Handle both "name=value" and "name = value" formatsletprefix=name+'=';if(cookie.startsWith(prefix)){returncookie.substring(prefix.length);}// Handle without = sign (edge case)returncookie.substring(name.length);}}
Activity
Aditya8369 commentedon May 1, 2026
@devanshi14malhotra please assign me