3

I'm debugging a site that sets cookies via javascript, and I'd like to know exactly which lines are setting cookies as I run the page. Simply combing through the script is not an option because its so convoluted.. (it's not my script if you're wondering)

How can I easily find out which lines are setting cookies? I'm new to this, so if you can explain the exact steps in doing this I'd be very thankful.

I presume that document.cookie is the only way to set cookies with javascript, but if there's another way(s) that'd definitely be helpful to know, as I might've ignored said lines in reading through the script..

Background: I'm on Windows XP

Ben G
  • 26,091
  • 34
  • 103
  • 170
  • Related question: [Breaking JavaScript execution always when cookie is set - Stack Overflow](https://stackoverflow.com/questions/41245885/breaking-javascript-execution-always-when-cookie-is-set). – Sergey Vyacheslavovich Brunov Aug 25 '21 at 22:57

2 Answers2

4

Yes, document.cookie is how JS sets cookies. But remember:

  1. Other parts of the page can set cookies. Cookies are primarily set in the HTTP response headers. Plugins, like Flash, set tons of cookies too.

  2. The actual JS code that sets the cookie may be buried in a library.

  3. It is possible that some programmers obfuscate the JS code, so that a search for "cookie" will fail.

Things to do:

  1. Install the Web Developer add-on. This will allow you to easily see, edit, or delete cookies, for a given page -- including 3rd party cookies.

    It also allows you to View the response headers -- to easily see if the cookies are being set that way. (clear cookies, reload the page, click: Information --> View Response Headers.)

  2. Install the Firebug add-on and then the Firecookie plugin for Firebug.

    Firecookie can show cookie events as they are happening. This, coupled with observation and use of JS breakpoints (Firebug feature) can help you narrow down where cookies are being manipulated.

Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
0

Use firebug & firecookie to find the cookie's name. then search that name through the JS files using your IDE search feature.

bchhun
  • 18,116
  • 8
  • 28
  • 31
  • 1
    I know the cookie names but can't find them in any of the code.. I think that their names are generated dynamically rather than appearing in quotes in the code – Ben G Jan 29 '11 at 20:02