Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cookie::fromString() HeaderUtils::split() - Symfony's HttpFoundation #33667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
carlino3 opened this issue Sep 23, 2019 · 6 comments
Closed

Cookie::fromString() HeaderUtils::split() - Symfony's HttpFoundation #33667

carlino3 opened this issue Sep 23, 2019 · 6 comments

Comments

@carlino3
Copy link

carlino3 commented Sep 23, 2019

Description
Issue was identified when adding a Set-Cookie header with a query string value to a Response object, and was traced back to HeaderUtils::split() called from Cookie::fromString().

This function fails to parse cookie values with '=' symbols on it, which is perfectly fine according the RFC 6265.

A string like "foo_cookie=foo=1&bar=2&baz=3" ends up being just "foo" in the Cookie object.

https://tools.ietf.org/html/rfc6265#section-4.1.1

cookie-value = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE )
cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E
; US-ASCII characters excluding CTLs,
; whitespace DQUOTE, comma, semicolon,
; and backslash

How to reproduce

	use Symfony\Component\HttpFoundation\Cookie;
    
	$header = "Set-Cookie: bjt_track=firstVisit=2019-09-23 06:18:41&sessionsCount=14&previousVisit=2019-09-23 06:26:37&lastVisit=2019-09-23 06:27:09; expires=Tue, 22-Sep-2020 06:27:09 GMT; path=/";

	$parts = explode(": ", $header, 2); 

	var_dump(Cookie::fromString($parts[1]));

/* OUTPUT: 

object(Symfony\Component\HttpFoundation\Cookie)#3 (10) {
  ["name":protected]=>
  string(9) "bjt_track"
  ["value":protected]=>
  string(10) "firstVisit"    <--- Note the broken value here
  ["domain":protected]=>
  NULL
  ["expire":protected]=>
  int(1600756029)
  ["path":protected]=>
  string(1) "/"
  ["secure":protected]=>
  bool(false)
  ["httpOnly":protected]=>
  bool(false)
  ["raw":"Symfony\Component\HttpFoundation\Cookie":private]=>
  bool(true)
  ["sameSite":"Symfony\Component\HttpFoundation\Cookie":private]=>
  NULL
  ["secureDefault":"Symfony\Component\HttpFoundation\Cookie":private]=>
  bool(false)
}
*/
@nicolas-grekas
Copy link
Member

Would you be able to submit a fix for this issue? (with a test case of course)

@carlino3
Copy link
Author

Would you be able to submit a fix for this issue? (with a test case of course)

Sure, let me work on it.

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Friendly ping? Should this still be open? I will close if I don't hear anything.

@alehaa
Copy link

alehaa commented Jan 1, 2021

Afaik this is still relevant.

@xabbuh
Copy link
Member

xabbuh commented Jan 2, 2021

Status: Reviewed

see #39681

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants