Menu

#23 double urlencoding breaks redirect WITH FIX!

closed-fixed
None
5
2004-10-16
2003-12-03
Gene Wood
No

There is a bug at line 771 of Snoopy 1.01 that will
cause redirects containing cookies with data that must
be urlencoded to fail.

This is what happens
Snoopy pulls the first page and recieves the cookies.
It then follows the redirect and runs the "setcookies"
function to pass the cookies returned from the first
page, into the cookies array to be sent to the second
page. The problem is that the cookies that snoopy pulls
from the first page are already urlencoded (for example
"test this" would look like "test%20this"). Setcookies
passes this string into the cookies array, and then on
line 771, when snoopy is building the headers to be
sent when getting the second page, it urlencodes, the
already urlencoded data. This would cause "test%20this"
to become "test%2520this".

A real easy fix for this is to modify the Setcookies
function as follows :
Here is the original :

function setcookies()
{
for($x=0; $x<count($this->headers); $x++)
{
if(preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i',
$this->headers[$x],$match))
$this->cookies[$match[1]] = $match[2];
}
}

Just change it to this :

function setcookies()
{
for($x=0; $x<count($this->headers); $x++)
{
if(preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i',
$this->headers[$x],$match))
$this->cookies[$match[1]] = urldecode($match[2]);
}
}

This way setcookies passes a non urlencoded string into
the array, which then gets re-urlencoded when its sent
to the next page.

Discussion

  • Gene Wood

    Gene Wood - 2003-12-03
    • summary: double urlencoding breaks redirect --> double urlencoding breaks redirect WITH FIX!
     
  • Gene Wood

    Gene Wood - 2004-07-24

    Logged In: YES
    user_id=547273

    This has been fixed and added to the CVS tree.

     
  • Gene Wood

    Gene Wood - 2004-07-24
    • status: open --> closed-fixed
     
  • Gene Wood

    Gene Wood - 2004-10-16
    • assigned_to: nobody --> gene_wood
     

Log in to post a comment.