Skip to content

Commit a6fecac

Browse files
committed
Prohibit headers to contain newlines
1 parent bba5e60 commit a6fecac

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

META.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@
4040
}
4141
},
4242
"release_status" : "stable",
43-
"version" : "1.99996",
43+
"version" : "1.99998",
4444
"x_serialization_backend" : "JSON::PP version 4.06"
4545
}

META.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ requires:
2222
Digest::SHA1: '2'
2323
HTTP::Easy: '0.02'
2424
JSON::XS: '3'
25-
version: '1.99996'
25+
version: '1.99998'
2626
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'

Makefile.PL

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ WriteMakefile(
1010
'Digest::SHA1' => 2,
1111
'JSON::XS' => 3,
1212
'HTTP::Easy' => 0.04,
13+
'Class::XSAccessor' => 0,
1314
},
1415
ABSTRACT_FROM => 'lib/AnyEvent/HTTP/Server.pm', # retrieve abstract from module
1516
AUTHOR => 'Mons Anderson <[email protected]>',

lib/AnyEvent/HTTP/Server.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ AnyEvent::HTTP::Server - AnyEvent HTTP/1.1 Server
88

99
our $VERSION;
1010
BEGIN{
11-
$VERSION = '1.99997';
11+
$VERSION = '1.99998';
1212
}
1313

1414
use AnyEvent::HTTP::Server::Kit;

lib/AnyEvent/HTTP/Server/Req.pm

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,15 @@ BEGIN {
273273
$h->{'content-type'} = 'application/octet-stream';
274274
}
275275
for (keys %$h) {
276-
if (exists $hdr{lc $_}) { $good[ $hdri{lc $_} ] = $hdr{ lc $_ }.": ".$h->{$_}.$LF; }
277-
else { push @bad, "\u\L$_\E: ".$h->{$_}.$LF; }
276+
if (exists $hdr{lc $_}) { $good[ $hdri{lc $_} ] = $hdr{ lc $_ }.": ".$h->{$_}; }
277+
else { push @bad, "\u\L$_\E: ".$h->{$_}; }
278+
}
279+
for (@good,@bad) {
280+
if (defined()) {
281+
s/[\r\n]+/ /g;
282+
$reply .= $_ . $LF;
283+
}
278284
}
279-
defined() and $reply .= $_ for @good,@bad;
280285
$reply .= $LF;
281286
if( $self->{writer} ) {
282287
$self->{writer}->( \$reply );
@@ -360,7 +365,7 @@ BEGIN {
360365
}
361366

362367
for (keys %$h) {
363-
if (exists $hdr{lc $_}) { $good[ $hdri{lc $_} ] = $hdr{ lc $_ }.": ".$h->{$_}.$LF; }
368+
if (exists $hdr{lc $_}) { $good[ $hdri{lc $_} ] = $hdr{ lc $_ }.": ".$h->{$_}; }
364369
else {
365370
if (lc $_ eq 'set-cookie' ) {
366371
my $cookies = HTTP::Easy::Cookies->decode($h->{$_});
@@ -376,16 +381,21 @@ BEGIN {
376381
push @c, "Secure" if $o->{secure};
377382
push @c, "HttpOnly" if $o->{httponly};
378383
push @c, "SameSite=" . $o->{samesite} if $o->{samesite};
379-
push @bad, "\u\Lset-cookie\E: ". join('; ',@c) .$LF;
384+
push @bad, "\u\Lset-cookie\E: ". join('; ',@c);
380385
}
381386
}
382387
}
383388
} else {
384-
push @bad, "\u\L$_\E: ".$h->{$_}.$LF;
389+
push @bad, "\u\L$_\E: ".$h->{$_};
385390
}
386391
}
387392
}
388-
defined() and $reply .= $_ for @good,@bad;
393+
for (@good,@bad) {
394+
if (defined()) {
395+
s/[\r\n]+/ /g;
396+
$reply .= $_ . $LF;
397+
}
398+
}
389399
# 2 is size of LF
390400
$self->attrs->{head_size} = length($reply) + 2;
391401
$self->attrs->{body_size} = length $content;

0 commit comments

Comments
 (0)