Skip to content

Commit 73187d0

Browse files
committed
Preserve HttpOnly value when deserializing a header
The specification states that the cookie should be considered http only if and only if the flag is present. See https://www.owasp.org/index.php/HttpOnly
1 parent 48bb195 commit 73187d0

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/Symfony/Component/HttpFoundation/Cookie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static function fromString($cookie, $decode = false)
4646
'path' => '/',
4747
'domain' => null,
4848
'secure' => false,
49-
'httponly' => true,
49+
'httponly' => false,
5050
'raw' => !$decode,
5151
'samesite' => null,
5252
);

src/Symfony/Component/HttpFoundation/Tests/CookieTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ public function testFromString()
200200
$this->assertEquals(new Cookie('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true, true, true), $cookie);
201201

202202
$cookie = Cookie::fromString('foo=bar', true);
203-
$this->assertEquals(new Cookie('foo', 'bar'), $cookie);
203+
$this->assertEquals(new Cookie('foo', 'bar', 0, '/', null, false, false), $cookie);
204+
}
205+
206+
public function testFromStringWithHttpOnly()
207+
{
208+
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly');
209+
$this->assertTrue($cookie->isHttpOnly());
210+
211+
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure');
212+
$this->assertFalse($cookie->isHttpOnly());
204213
}
205214
}

src/Symfony/Component/HttpFoundation/Tests/ResponseHeaderBagTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ public function testSetCookieHeader()
241241
{
242242
$bag = new ResponseHeaderBag();
243243
$bag->set('set-cookie', 'foo=bar');
244-
$this->assertEquals(array(new Cookie('foo', 'bar', 0, '/', null, false, true, true)), $bag->getCookies());
244+
$this->assertEquals(array(new Cookie('foo', 'bar', 0, '/', null, false, false, true)), $bag->getCookies());
245245

246246
$bag->set('set-cookie', 'foo2=bar2', false);
247247
$this->assertEquals(array(
248-
new Cookie('foo', 'bar', 0, '/', null, false, true, true),
249-
new Cookie('foo2', 'bar2', 0, '/', null, false, true, true),
248+
new Cookie('foo', 'bar', 0, '/', null, false, false, true),
249+
new Cookie('foo2', 'bar2', 0, '/', null, false, false, true),
250250
), $bag->getCookies());
251251

252252
$bag->remove('set-cookie');

0 commit comments

Comments
 (0)