1

I'm trying to set a secure session for a login interface and I'm checking if some hashed value saved on the $_COOKIE and in $_SESSION matches in both arrays. I need to change the value of the cookie via javascript to simulate an attack and check if my secure session works (if that is even possible, of course). Deleting the cookie wont work because I have a different validation for when the cookies doesnt exist.

Is it possible to modify a cookie's value via javascript and if so, how to?

Raptor
  • 53,206
  • 45
  • 230
  • 366
Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206

2 Answers2

2

Is it possible to modify a cookie's value via javascript and if so, how to?

Yes. Provided it lives under the same domain and path, you can ready, modify, create, or destroy cookies either by JavaScript (document.cookie) or PHP ($_COOKIE and set_cookie()).

As noted, you could also manipulate cookies via the developer tools of most modern browsers.

Community
  • 1
  • 1
Jason McCreary
  • 71,546
  • 23
  • 135
  • 174
  • 1
    *sidenote:* requires to be in same domain path if cookie domain path is specified – Raptor Jul 30 '13 at 03:07
  • @Shivan Raptor, added. Thanks. For more on how domains work, check out - http://stackoverflow.com/questions/1062963/how-do-browser-cookie-domains-work – Jason McCreary Jul 30 '13 at 03:09
0

Since cookies are actually stored within the browser, it is definitely possible :)

https://developer.mozilla.org/en-US/docs/Web/API/document.cookie

Ken
  • 548
  • 6
  • 19