Skip to content

Commit 52b814b

Browse files
chigleyoalders
authored andcommitted
Netscape: allow HttpOnly cookies to be loaded
Fixes #63. curl generates cookie jars where HttpOnly cookies have hostnames prepended with #HttpOnly_ (see [0]). Until now, HTTP::Cookies::Netscape was discarding such cookies as comments. This commit strips the magic #HttpOnly_ prefix such that the cookies are loaded. The HttpOnly state isn't kept in memory: the cookies essentially lose the property when loaded. If the cookie jar is written back out to a file, hostnames will not have the #HttpOnly_ prefix, even if they had the prefix originally. See [1] for a PerlMonks thread where someone else hit the same issue as me. [0] https://curl.se/libcurl/c/CURLOPT_COOKIELIST.html [1] https://www.perlmonks.org/?node_id=1187917
1 parent c9c9759 commit 52b814b

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Revision history for HTTP-Cookies. The HTTP::Cookies module used to be bundled
22
with the libwww-perl distribution.
33

44
{{$NEXT}}
5+
- Allow HttpOnly cookies to be loaded by HTTP::Cookies::Netscape (GH#63) (Charlie Hothersall-Thomas)
56

67
6.08 2019-12-02 15:58:32Z
78
- allow different "ignore_discard" value at save() time (GH#2) (Alex Peters)

lib/HTTP/Cookies/Netscape.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ sub load
2424
my $now = time() - $HTTP::Cookies::EPOCH_OFFSET;
2525
while (my $line = <$fh>) {
2626
chomp($line);
27+
$line =~ s/\s*\#HttpOnly_//;
2728
next if $line =~ /^\s*\#/;
2829
next if $line =~ /^\s*$/;
2930
$line =~ tr/\n\r//d;

t/cookies.t

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!perl -w
22

33
use Test;
4-
plan tests => 79;
4+
plan tests => 80;
55

66
use HTTP::Cookies;
77
use HTTP::Request;
@@ -417,6 +417,10 @@ ok($c->as_string =~ /foo1=bar/);
417417
undef($c);
418418
unlink($file);
419419

420+
# Expect a HttpOnly cookie to be loaded, rather than treated as a comment
421+
$c = HTTP::Cookies::Netscape->new(file => 't/data/netscape-httponly.txt');
422+
ok(count_cookies($c), 2);
423+
undef($c);
420424

421425
#
422426
# Some additional Netscape cookies test

t/data/netscape-httponly.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Netscape HTTP Cookie File
2+
# http://www.netscape.com/newsref/std/cookie_spec.html
3+
# This is a generated file! Do not edit.
4+
5+
www.acme.com FALSE / FALSE 2147483647 foo1 bar
6+
#HttpOnly_www.acme.com FALSE / FALSE 2147483647 foo2 bar

0 commit comments

Comments
 (0)