Inserted auth_token headers aren't WSGI compliant

Bug #1794179 reported by Tim Burke
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
keystonemiddleware
In Progress
High
Unassigned

Bug Description

The PEP says [1]:

> "Native" strings (which are always implemented using the
> type named ``str``) ... are used for request/response
> headers and metadata

and

> Do not be confused however: even if Python's ``str`` type
> is actually Unicode "under the hood", the *content* of
> native strings must still be translatable to bytes via
> the Latin-1 encoding!

But when auth_token adds headers [2], it takes them straight from the auth_ref, which was deserialized from JSON and thus uses unicode. This may or may not be the right thing to do on Python 3 (I haven't looked to see whether the AccessInfo instances typically limit unicode values to the Latin-1 set or not), but it's definitely wrong for Python 2 where all headers should be bytes. This can cause applications to break in not-always-obvious ways [3].

I've attached a partial fix, but more thought seems required -- in particular there are places where we set some headers to None, which also seems out of spec.

[1] https://www.python.org/dev/peps/pep-3333/#a-note-on-string-types
[2] https://github.com/openstack/keystonemiddleware/blob/5.2.0/keystonemiddleware/auth_token/_request.py#L162-L168
[3] https://bugs.launchpad.net/swift/+bug/1793880

Revision history for this message
Tim Burke (1-tim-z) wrote :
Revision history for this message
Morgan Fainberg (mdrnstm) wrote :

This looks great and we totally would like to have this fix in keystonemiddleware. Can you submit the patch to our gerrit: review.openstack.org ? Thanks!

Changed in keystonemiddleware:
status: New → Triaged
importance: Undecided → High
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to keystonemiddleware (master)

Fix proposed to branch: master
Review: https://review.openstack.org/613681

Changed in keystonemiddleware:
assignee: nobody → Morgan Fainberg (mdrnstm)
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on keystonemiddleware (master)

Change abandoned by Morgan Fainberg (<email address hidden>) on branch: master
Review: https://review.opendev.org/613681

Changed in keystonemiddleware:
assignee: Morgan Fainberg (mdrnstm) → nobody
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.