Seitenanfang

Cookie __atrfs and CGI::PSGI problems

Some websites stopped working today or at least some cookie-based functions ran out-of-order. Deleting all cookies helps - but is no solution. A cookie called __atrfs set by the famous AddThis! service is responsible for this.

First: The problem has been reported to and answered by the AddThis support.

1335361530_CookiesThe cookie violated the specifications by containing invalid chars. They tried to fix it by setting the Cookie to an empty value - which is usually ok, but results in unexpected problems with CGI::PSGI (and maybe also the plain CGI module).

The CGI module returns a list of the cookie names using the ->cookies() method. I used to build a cookie hash by using the following code snipped:

$self->{cookies} = { map { $_, $q->cookie($_); } ( $q->cookie() ) };

The fixed __atrfs cookie has no value at all (which also violates the specs, I think, because an empty cookie should be deleted) and the ->cookie($_) method returns neither undef nor am empty value for empty cookies - but an empty list (in array context). My map call returns just the cookie name __atrfs but no second argument breaking the hash, because the next cookie name would be used as the value for __atrfs.

The bugfix was very easy:

$self->{cookies} = { map { $_, scalar($q->cookie($_)); } ( $q->cookie() ) };

The scalar function always returns one item (which may be undef, but that's perfectly ok).

 

Noch keine Kommentare. Schreib was dazu

Schreib was dazu

Die folgenden HTML-Tags sind erlaubt:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>