Fix UnicodeDecodeError when decode API input
Convert UnicodeDecodeError to HTTPBadRequest in FaultWrapper. Change-Id: I826f05084b0a0ef170ef293d382868409b96ed3d Closes-Bug: #1746202
This commit is contained in:
parent
a07d522970
commit
bf19988984
@ -20,6 +20,7 @@ import webob.dec
|
|||||||
import webob.exc
|
import webob.exc
|
||||||
|
|
||||||
from manila.api.openstack import wsgi
|
from manila.api.openstack import wsgi
|
||||||
|
from manila.i18n import _
|
||||||
from manila import utils
|
from manila import utils
|
||||||
from manila.wsgi import common as base_wsgi
|
from manila.wsgi import common as base_wsgi
|
||||||
|
|
||||||
@ -40,6 +41,11 @@ class FaultWrapper(base_wsgi.Middleware):
|
|||||||
status, webob.exc.HTTPInternalServerError)()
|
status, webob.exc.HTTPInternalServerError)()
|
||||||
|
|
||||||
def _error(self, inner, req):
|
def _error(self, inner, req):
|
||||||
|
if isinstance(inner, UnicodeDecodeError):
|
||||||
|
msg = _("Error decoding your request. Either the URL or the "
|
||||||
|
"request body contained characters that could not be "
|
||||||
|
"decoded by Manila.")
|
||||||
|
return wsgi.Fault(webob.exc.HTTPBadRequest(explanation=msg))
|
||||||
LOG.exception("Caught error: %s", inner)
|
LOG.exception("Caught error: %s", inner)
|
||||||
|
|
||||||
safe = getattr(inner, 'safe', False)
|
safe = getattr(inner, 'safe', False)
|
||||||
|
@ -184,3 +184,12 @@ class ExceptionTest(test.TestCase):
|
|||||||
api = self._wsgi_app(fail)
|
api = self._wsgi_app(fail)
|
||||||
resp = webob.Request.blank('/').get_response(api)
|
resp = webob.Request.blank('/').get_response(api)
|
||||||
self.assertEqual(500, resp.status_int)
|
self.assertEqual(500, resp.status_int)
|
||||||
|
|
||||||
|
def test_validate_request_unicode_decode_fault(self):
|
||||||
|
@webob.dec.wsgify
|
||||||
|
def unicode_error(req):
|
||||||
|
raise UnicodeDecodeError("ascii", "test".encode(), 0, 1, "bad")
|
||||||
|
|
||||||
|
api = self._wsgi_app(unicode_error)
|
||||||
|
resp = webob.Request.blank('/test?foo=%88').get_response(api)
|
||||||
|
self.assertEqual(400, resp.status_int)
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- This patch converts UnicodeDecodeError exception into BadRequest, plus
|
||||||
|
an explicit error message. Fix invalid query parameter could lead to
|
||||||
|
HTTP 500.
|
Loading…
Reference in New Issue
Block a user