-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
We have a user with a latin-1 encoded user agent:
>>> b"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) 3V\xE4xel/1.5.0-239 Chrome/108.0.5359.215 Electron/22.3.8 Safari/537.36".decode('utf-8')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 83: invalid continuation byte
>>> b"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) 3V\xE4xel/1.5.0-239 Chrome/108.0.5359.215 Electron/22.3.8 Safari/537.36".decode('latin-1')
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) 3Växel/1.5.0-239 Chrome/108.0.5359.215 Electron/22.3.8 Safari/537.36'
With kong 3.8 this is breaking as it seems to make the assumptions that headers are utf-8 encoded:
----------------------------------------, context: ngx.timer
Exception occurred during processing of request from , context: ngx.timer
Traceback (most recent call last):, context: ngx.timer
File "/usr/local/lib/python3.10/dist-packages/kong_pdk/listener.py", line 59, in handle, context: ngx.timer
File "msgpack/_unpacker.pyx", line 540, in msgpack._cmsgpack.Unpacker.__next__, context: ngx.timer
File "msgpack/_unpacker.pyx", line 463, in msgpack._cmsgpack.Unpacker._unpack, context: ngx.timer
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 83: invalid continuation byte, context: ngx.timer
----------------------------------------, context: ngx.timer
However this assumption is incorrect as the encoding of HTTP headers seems to be ill-defined. I don't think that HTTP client is necessarily making an "incorrect" assumption by using latin-1. The PDK probably should just treat headers as bytes, or at the very least have a fallback mechanism to ascii on the str.decode.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels