-
Notifications
You must be signed in to change notification settings - Fork 889
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
Adding an invalid UTF-8 sequence in the URL make the server to crash. #2725
Conversation
c474841
to
1463435
Compare
On Tue, Jul 26, 2016 at 8:02 AM, Rémy HUBSCHER notifications@github.com
True. WebOb tries to read the path_info as UTF-8 and it results in a It's not clear to me how this leads to a DDoS attack, though. I wouldn't I'm open to the idea that I'm missing something, but on the face of it, Chris |
Ok, in any case having a 500 is not something we want right? |
As @chrisrossi said, this is not a crash nor an exploit. This is a 500 error which you can catch in your application via an exception view or any WSGI middleware just like any other error in your application. @view_config(context=UnicodeDecodeError, renderer='nope.jinja2')
def bad_char_view(request):
request.response.status = 500
return {} |
For reference here is a traceback while using the starter scaffold.
|
Does this means that you wouldn't consider it to be something to fix in webob? |
This would be considered a duplicate of Pylons/webob#115 and Pylons/webob#161 which will still end up raising an exception. There is nothing more for webob to do here as it does not know the charset of the request if it's not utf-8. It is possible to catch the exception and try other encodings, but this is not something we would do automatically. |
We could choose to make it a "400 Bad Request" error response, rather than a 500: it is an error on the part of the client. |
Yes, unfortunately we cannot add a default error view for this in Pyramid until the issues are resolved in webob. We cannot assume that any |
Pyramid defines its own See #2047 as well. |
Let me try that then. |
@mmerickel Regarding the exception view you described a few messages ago, this sadly does not work, the exceptions are not caught by Pyramid and rendered as wanted. |
@olemoign Do you have the debugtoolbar enabled? According to ptweens on a project of mine:
This would mean when the debugtoolbar causes the exception by accessing I'd be interested in seeing a stacktrace from an app that doesn't have debugtoolbar, and where you can't use an exception view to change the error displayed. |
WSGI middleware could catch this though. I am working on fixes in WebOb... |
@bertjwregeer You are perfectly right, this is caused by the debugtoolbar. 2016-08-19 14:30:50,437 ERROR [waitress][waitress] Exception when serving /¿
Traceback (most recent call last):
File "/Users/olemoign/.pyenv/versions/rta/lib/python3.5/site-packages/pyramid_debugtoolbar/toolbar.py", line 173, in toolbar_tween
p = request.path_info
File "/Users/olemoign/.pyenv/versions/rta/lib/python3.5/site-packages/webob/descriptors.py", line 68, in fget
return req.encget(key, encattr=encattr)
File "/Users/olemoign/.pyenv/versions/rta/lib/python3.5/site-packages/webob/request.py", line 166, in encget
return bytes_(val, 'latin-1').decode(encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbf in position 1: invalid start byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/olemoign/.pyenv/versions/rta/lib/python3.5/site-packages/waitress/channel.py", line 338, in service
task.service()
File "/Users/olemoign/.pyenv/versions/rta/lib/python3.5/site-packages/waitress/task.py", line 169, in service
self.execute()
File "/Users/olemoign/.pyenv/versions/rta/lib/python3.5/site-packages/waitress/task.py", line 399, in execute
app_iter = self.channel.server.application(env, start_response)
File "/Users/olemoign/.pyenv/versions/3.5.1/envs/rta/lib/python3.5/site-packages/paste/translogger.py", line 69, in __call__
return self.application(environ, replacement_start_response)
File "/Users/olemoign/.pyenv/versions/rta/lib/python3.5/site-packages/pyramid/router.py", line 236, in __call__
response = self.invoke_subrequest(request, use_tweens=True)
File "/Users/olemoign/.pyenv/versions/rta/lib/python3.5/site-packages/pyramid/router.py", line 211, in invoke_subrequest
response = handle_request(request)
File "/Users/olemoign/.pyenv/versions/rta/lib/python3.5/site-packages/pyramid_debugtoolbar/toolbar.py", line 175, in toolbar_tween
raise URLDecodeError(e.encoding, e.object, e.start, e.end, e.reason)
pyramid.exceptions.URLDecodeError: 'utf-8' codec can't decode byte 0xbf in position 1: invalid start byte When disabled, Pyramid catches the exception as it should. |
Unfortunately this is not the first time that debugtoolbar messes up; unfortunately that's more like a rule, not an exception :D |
It is not only about debugtoolbar, you will have the same problem with any other plugin trying to read request.GET or request.path. |
@Natim That's not true unless they install themselves as a tween BEFORE the execview. Otherwise you can capture the |
How can I check if it is the case? Here is the code: https://github.com/Kinto/kinto/blob/eadd6e23f44ef0b4584823db49347e7114f8b0eb/kinto/core/initialization.py#L334-L341 |
That's a You can list tweens from the command line by using:
This will list the Tweens and the order in which they are executed. |
Another way of fixing it that might be interesting: https://github.com/mozilla-services/mozservices/pull/40/files |
Thanks for the helpful discussion. I’t been a while since the latest update and just yesterday this arrived in our log file:
@Natim’s initial suggestion to add a I’m curious though: is catching a |
One more thought. In order to log/inspect the faulty URL,
|
You can pull the |
Thanks @bertjwregeer! I noticed something odd here, though. When I send
and log as you said _log.info("Failed to decode url: %s", f"{env['REQUEST_METHOD']} {env['SERVER_NAME']}:{env['SERVER_PORT']}{env['PATH_INFO']} {env['SERVER_PROTOCOL']}") Then the server logs the following:
which, upon closer inspection is:
Notice how the initial Question: the other dictionary keys ( |
Ah, yeah, That being said, You can see the values that NEED to exist in the WSGI environ documented in PEP3333: https://www.python.org/dev/peps/pep-3333/#environ-variables |
Sorry, I misspoke, |
I've got a few website done using Pyramid, Cornice and lately Kinto (the two last ones helps to make great HTTP API's on top of Pyramid)
One of them has got pentested using OpenVAD and we found an error that can make any Pyramid website to crash.
How to reproduce?
Add the string '%82%AC' in the URL of your Pyramid project and see it fails.