Skip to content

Commit

Permalink
CR escaping for P3P header
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryo Anazawa committed Nov 14, 2012
1 parent 49d5bf5 commit 7bb474c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/CGI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,8 @@ sub header {
'EXPIRES','NPH','CHARSET',
'ATTACHMENT','P3P'],@p);
$p3p = join ' ',@$p3p if ref($p3p) eq 'ARRAY';
# CR escaping for values, per RFC 822
for my $header ($type,$status,$cookie,$target,$expires,$nph,$charset,$attachment,$p3p,@other) {
if (defined $header) {
Expand Down Expand Up @@ -1542,10 +1544,7 @@ sub header {
push(@header,"Status: $status") if $status;
push(@header,"Window-Target: $target") if $target;
if ($p3p) {
$p3p = join ' ',@$p3p if ref($p3p) eq 'ARRAY';
push(@header,qq(P3P: policyref="/w3c/p3p.xml", CP="$p3p"));
}
push(@header,"P3P: policyref=\"/w3c/p3p.xml\", CP=\"$p3p\"") if $p3p;
# push all the cookies -- there may be several
if ($cookie) {
my(@cookie) = ref($cookie) && ref($cookie) eq 'ARRAY' ? @{$cookie} : $cookie;
Expand Down
3 changes: 3 additions & 0 deletions t/headers.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ like($@,qr/contains a newline/,'invalid header blows up');
like $cgi->header( -type => "text/html".$CGI::CRLF." evil: stuff " ),
qr#Content-Type: text/html evil: stuff#, 'known header, with leading and trailing whitespace on the continuation line';

eval { $cgi->header( -p3p => ["foo".$CGI::CRLF."bar"] ) };
like($@,qr/contains a newline/,'P3P header with CRLF embedded blows up');

eval { $cgi->header( -foobar => "text/html".$CGI::CRLF."evil: stuff" ) };
like($@,qr/contains a newline/,'unknown header with CRLF embedded blows up');

Expand Down

0 comments on commit 7bb474c

Please sign in to comment.