Skip to content

Commit f6764eb

Browse files
committed
Fix parsing of httponly cookies
Parse cookies with #HttpOnly_ prefix according to the Netscape cookie file format specification. Previously, all lines starting with # were treated as comments, but lines starting with #HttpOnly_ indicate cookies with the HttpOnly attribute set. The fix: - Detects #HttpOnly_ prefix and strips it before parsing - Adds httponly attribute to the cookie string - Continues to treat regular # lines as comments See: https://curl.se/docs/http-cookies.html Fixes #133
1 parent 61c2033 commit f6764eb

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

lib/Adapter/Artax/NetscapeCookieFileJar.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,14 @@ private function parse(string $line): ?ResponseCookie
6969
return null;
7070
}
7171

72-
if ($line[0] === '#') {
72+
// Handle httponly cookies - lines starting with #HttpOnly_ should be parsed
73+
// See: https://curl.se/docs/http-cookies.html
74+
$isHttpOnly = false;
75+
if (str_starts_with($line, '#HttpOnly_')) {
76+
$line = substr($line, 10); // Remove the '#HttpOnly_' prefix
77+
$isHttpOnly = true;
78+
} elseif ($line[0] === '#') {
79+
// Regular comment line, skip it
7380
return null;
7481
}
7582

@@ -104,6 +111,10 @@ private function parse(string $line): ?ResponseCookie
104111
$string .= '; secure';
105112
}
106113

114+
if ($isHttpOnly) {
115+
$string .= '; httponly';
116+
}
117+
107118
return ResponseCookie::fromHeader($string);
108119
}
109120
}

0 commit comments

Comments
 (0)