[issue41945] http.cookies.SimpleCookie.parse error after [keys] or some JSON data values

2022-01-04 Thread Jan Novak


Jan Novak  added the comment:

New examples with the structured data.

Problems are with quotes and spaces inside { or [

cookie-script.com set those cookie data:
CookieScriptConsent={"action":"accept","categories":"[\\"performance\\"]"}

Python loads only cookies before that JSON structure

>>> from http.cookies import SimpleCookie
>>> ck = SimpleCookie()
>>> ck.load('id=12345; 
>>> CookieScriptConsent={"action":"accept","categories":"[\\"performance\\"]"}; 
>>> something="not loaded"')
>>> print(ck)
Set-Cookie: id=12345

This works:
>>> ck.load('id=12345; complex_data={1:[1,2]}; something="loaded"')
>>> print(ck)
Set-Cookie: complex_data={1:[1,2]}
Set-Cookie: id=12345
Set-Cookie: something="loaded"

This not works:
>>> ck.load('id=12345; complex_data={1:[1, 2]}; something="not loaded"')
>>> print(ck)
Set-Cookie: complex_data={1:[1,
Set-Cookie: id=12345

Conclusion:
Parsing JSON like cookie objects works, except quotes and without spaces. 

Exist some new RFC with JSON data support?
How implementation/support/solution in diferent languages?
Exist another Python library which support cookie with JSON data?

--
title: http.cookies.SimpleCookie.parse error after [keys] -> 
http.cookies.SimpleCookie.parse error after [keys] or some JSON data values
versions: +Python 3.10 -Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41945] http.cookies.SimpleCookie.parse error after [keys]

2020-11-05 Thread Jan Novak


Jan Novak  added the comment:

Possible patch, load parts one by one:

http_cookie = 'id=12345; [object Object]=data; something=not_loaded'
for cookie_key in http_cookie.split(';'):
  c.load(cookie_key)

print c
Set-Cookie: id=12345
Set-Cookie: something=not_loaded

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41945] http.cookies.SimpleCookie.parse error after [keys]

2020-10-05 Thread Jan Novak


New submission from Jan Novak :

If brackets [] are around cookie name,
next cookie names are not loaded.

try:
  import http.cookies as Cookie
except ImportError:
  import Cookie
c = Cookie.SimpleCookie()
c.load('id=12345; [object Object]=data; something=not loaded')
print(c)

Note:
It could cause big problems with session etc.
We found that Chrome/Edge starts to save and send this type of cookies for some 
(couple) users. The origin of that [object Object]=... cookies are probably 
some implementation of
https://cookiepedia.co.uk/cookies/euconsent
and errors somewhere in external javascripts or browsers?

Related issues:
https://bugs.python.org/issue41695
https://bugs.python.org/issue27674

The same problem occures in P3.7, P2.7, six.moves.http_cookies etc.

I know RFT says that cookie-name can't use brackets.
But you can set them to browser cookies.

RFC 6265:
set-cookie-header = "Set-Cookie:" SP set-cookie-string
 set-cookie-string = cookie-pair *( ";" SP cookie-av )
 cookie-pair   = cookie-name "=" cookie-value
 cookie-name   = token
 token = 

RFC 2616:
token  = 1*
   separators = "(" | ")" | "<" | ">" | "@"
  | "," | ";" | ":" | "\" | <">
  | "/" | "[" | "]" | "?" | "="
  | "{" | "}" | SP | HT

--
components: Library (Lib)
messages: 378041
nosy: xnovakj
priority: normal
severity: normal
status: open
title: http.cookies.SimpleCookie.parse error after [keys]
type: behavior
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com