Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#20557 closed Bug (fixed)

Mangled Cookies on Python 3

Reported by: Armin Ronacher Owned by: Aymeric Augustin
Component: HTTP handling Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The WSGI spec mangles the strings when they go into the environment. This not only affects QUERY_STRING, PATH_INFO and SCRIPT_NAME, it also affects headers that are not latin1. This for instance applies to the HTTP_COOKIE header. When you set a cookie named förmlich="nährhaft" with JavaScript, Django will give you a mangled value.

The correct solution on Python 3 is to encode it back to latin1 and decode it from utf-8 as browsers do.

Change History (7)

comment:1 by Aymeric Augustin, 11 years ago

Owner: changed from nobody to Aymeric Augustin
Status: newassigned
Triage Stage: UnreviewedAccepted

Agreed, that's what Django should do.

(I don't remember how this works currently.)

comment:2 by Armin Ronacher, 11 years ago

I just noticed that the stdlib module has some issues with unicode on Python 3. I am going to investigate how I'm going to solve this in Werkzeug and will link you the solution once I have one.

comment:3 by Armin Ronacher, 11 years ago

This is the solution I ended up with in Werkzeug for the time being: https://github.com/mitsuhiko/werkzeug/commit/cf048aad79faa4675f8d90ab57928dc3e09808cb

comment:4 by Aymeric Augustin, 11 years ago

Type: UncategorizedBug

We reached roughly the same conclusion; we just piled hacks upon hacks instead of rewriting the whole thing like you did...

comment:5 by Aymeric Augustin <aymeric.augustin@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In 8aaca651cf5732bbf395d24a7d9f2edfab00250c:

Fixed #20557 -- Properly decoded non-ASCII cookies on Python 3.

Thanks mitsuhiko for the report.

Non-ASCII values are supported. Non-ASCII keys still aren't, because the
current parser mangles them. That's another bug.

comment:6 by Aymeric Augustin <aymeric.augustin@…>, 11 years ago

In fac5735a3daffb82b67ff489f0c963eaf953f6e7:

[1.6.x] Fixed #20557 -- Properly decoded non-ASCII cookies on Python 3.

Thanks mitsuhiko for the report.

Non-ASCII values are supported. Non-ASCII keys still aren't, because the
current parser mangles them. That's another bug.

Simplified backport of 8aaca651 and f5add47 from master.

comment:7 by Aymeric Augustin <aymeric.augustin@…>, 11 years ago

In f5add4712f684a78215263771b8acaeb48e64a81:

Fixed tests introduced in previous commit on Python 2. Refs #20557.

Note: See TracTickets for help on using tickets.
Back to Top