Subject: | bad parsing: some cookies are not parsed |
Hello,
Sometimes the cookies are not properly parsed, see the attached script
for an example.
It happened to me using Catalyst and the HTTP::Prefork Engine: sometimes
the session cookie could not be parsed, so it was impossible to login.
The bug was in Cookie::XS and I checked that it is also in CGI::Cookie::XS
Switching to CGI::Simple::Cookie fixed the problem.
Best,
Karl
%perl -v
This is perl, v5.8.9 built for x86_64-linux
%uname -a
Linux chge1x0039 2.6.16.60-0.54.5-smp #1 SMP Fri Sep 4 01:28:03 UTC 2009
x86_64 x86_64 x86_64 GNU/Linux
Subject: | cookies_bug.pl |
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
use Cookie::XS;
use CGI::Simple::Cookie;
my $header = 'ys-Study_Steps_[11]=o%3Acolumns%3Da%253Ao%25253Aid%25253Ds%2525253Anumberer%25255Ewidth%25253Dn%2525253A23%255Eo%25253Aid%25253Ds%2525253AStudyStep%25255Ewidth%25253Dn%2525253A50%255Eo%25253Aid%25253Ds%2525253AType%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AStudy%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253ALeader%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AStatus%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AForecast_start%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AForecast_end%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AActual_start%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AActual_end%25255Ewidth%25253Dn%2525253A100%5Esort%3Do%253Afield%253Ds%25253AStudyStep%255Edirection%253Ds%25253AASC%5Esize%3Do%253Awidth%253Dn%25253A809%255Eheight%253Dn%25253A600; ys-Study_Steps_[12]=o%3Acolumns%3Da%253Ao%25253Aid%25253Ds%2525253Anumberer%25255Ewidth%25253Dn%2525253A23%255Eo%25253Aid%25253Ds%2525253AStudyStep%25255Ewidth%25253Dn%2525253A50%255Eo%25253Aid%25253Ds%2525253AType%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AStudy%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253ALeader%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AStatus%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AForecast_start%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AForecast_end%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AActual_start%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AActual_end%25255Ewidth%25253Dn%2525253A100%5Esort%3Do%253Afield%253Ds%25253AStudyStep%255Edirection%253Ds%25253AASC%5Esize%3Do%253Awidth%253Dn%25253A830%255Eheight%253Dn%25253A600; ys-Study_Steps_[13]=o%3Acolumns%3Da%253Ao%25253Aid%25253Ds%2525253Anumberer%25255Ewidth%25253Dn%2525253A23%255Eo%25253Aid%25253Ds%2525253AStudyStep%25255Ewidth%25253Dn%2525253A50%255Eo%25253Aid%25253Ds%2525253AType%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AStudy%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253ALeader%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AStatus%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AForecast_start%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AForecast_end%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AActual_start%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AActual_end%25255Ewidth%25253Dn%2525253A100%5Esort%3Do%253Afield%253Ds%25253AStudyStep%255Edirection%253Ds%25253AASC%5Esize%3Do%253Awidth%253Dn%25253A818%255Eheight%253Dn%25253A600; ys-Study_Steps_[14]=o%3Acolumns%3Da%253Ao%25253Aid%25253Ds%2525253Anumberer%25255Ewidth%25253Dn%2525253A23%255Eo%25253Aid%25253Ds%2525253AStudyStep%25255Ewidth%25253Dn%2525253A50%255Eo%25253Aid%25253Ds%2525253AType%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AStudy%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253ALeader%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AStatus%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AForecast_start%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AForecast_end%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AActual_start%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AActual_end%25255Ewidth%25253Dn%2525253A100%5Esort%3Do%253Afield%253Ds%25253AStudyStep%255Edirection%253Ds%25253AASC%5Esize%3Do%253Awidth%253Dn%25253A830%255Eheight%253Dn%25253A600; ys-Study_Steps_[11]=toto; ys-Ongoing_Studies_[102]=o%3Acolumns%3Da%253Ao%25253Aid%25253Ds%2525253Anumberer%25255Ewidth%25253Dn%2525253A23%255Eo%25253Aid%25253Ds%2525253AStudy%25255Ewidth%25253Dn%2525253A746%255Eo%25253Aid%25253Ds%2525253ANumber%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253AProduct%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253ABMT_Representative%25255Ewidth%25253Dn%2525253A100%255Eo%25253Aid%25253Ds%2525253ABM_Coordinator%25255Ewidth%25253Dn%2525253A100%5Esort%3Do%253Afield%253Ds%25253AStudy%255Edirection%253Ds%25253AASC%5Esize%3Do%253Awidth%253Dn%25253A1202%255Eheight%253Dn%25253A600; erMJUKNJRXSYEE7L43GD27Z3N2AM1=PWD=&HMS=CHGE1APPL054&LGN=NNQXE3BOMZXXE3TFOJAG2ZLSMNVXGZLSN5XG6LTOMV2A&CLX=Thin; gecko_session_ch7li053_20001=4346406a87f4f5c545ef2f13494b078b25bd3548';
my $cookies = Cookie::XS->parse($header);
print "Cookie::XS found ", scalar(keys %$cookies), " cookies:\n";
print join(", ", sort keys %$cookies),"\n";
my $actual_cookies = CGI::Simple::Cookie->parse($header);
print "CGI::Simple::Cookie found ", scalar(keys %$actual_cookies), " cookies:\n";
print join(", ", sort keys %$actual_cookies),"\n";
use CGI::Cookie::XS;
my $new_cookies = CGI::Cookie::XS->parse($header);
print "CGI::Cookie::XS found ", scalar(keys %$new_cookies), " cookies:\n";
print join(", ", sort keys %$new_cookies),"\n";