0

So I have a phonegap app that accesses my webview, basically like

window.load("URLTOMYAPPGOESHERE");

Inside the webview, once people login, I save cookies of userid. When the app is loaded, if the userid cookie exists already, it will show the account details.

This morning, when I opened the app, the cookie was for another user's ID! Is it at all possible for a javascript cookie to be saved to a webview/url or app (thinking the webview is local), and when other people access that webview from their phone, they get the same cookie that was last set by another user? I thought JS cookies were local to the device, but this is the only reason I can think of. This is how I set cookies.

function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}


function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') {
        c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
        return c.substring(name.length, c.length);
    }
}
return "";
}
Trey Tyler
  • 273
  • 2
  • 10

1 Answers1

1

You are correct that cookies are local to the device and browser that they are set from. That means your code that sets the cookie had to have the incorrect information when it stored it in the cookie.

Herohtar
  • 5,347
  • 4
  • 31
  • 41