spec-first / connexion

Connexion is a modern Python web framework that makes spec-first and api-first development easy.
https://connexion.readthedocs.io/en/latest/
Apache License 2.0
4.5k stars 766 forks source link

URL containing new line character (%0A) causes an error 500 #1970

Open boubou191911 opened 2 months ago

boubou191911 commented 2 months ago

Description

When a parameter in the request URL contains a new line character encoded as %0A in the URL, connexion framework issues an erro 500. Ex: POST http://127.0.0.1:8000/greeting/e%0Aric

Expected behaviour

The URL parameter should be parsed.

Actual behaviour

Error in getting the URL parser. RuntimeError("Working outside of operation context. Make sure your app is wrapped in a ContextMiddleware and you're processing a request while accessing the context.") Traceback (most recent call last): File "/opt/conda/envs/historian/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app await app(scope, receive, sender) File "/opt/conda/envs/historian/lib/python3.12/site-packages/connexion/middleware/swagger_ui.py", line 222, in call await self.router(scope, receive, send) File "/opt/conda/envs/historian/lib/python3.12/site-packages/starlette/routing.py", line 756, in call await self.middleware_stack(scope, receive, send) File "/opt/conda/envs/historian/lib/python3.12/site-packages/starlette/routing.py", line 806, in app await self.default(scope, receive, send) File "/opt/conda/envs/historian/lib/python3.12/site-packages/connexion/middleware/swagger_ui.py", line 235, in default_fn await self.app(original_scope, receive, send) File "/opt/conda/envs/historian/lib/python3.12/site-packages/connexion/middleware/routing.py", line 154, in call await self.router(scope, receive, send) File "/opt/conda/envs/historian/lib/python3.12/site-packages/starlette/routing.py", line 756, in call await self.middleware_stack(scope, receive, send) File "/opt/conda/envs/historian/lib/python3.12/site-packages/starlette/routing.py", line 806, in app await self.default(scope, receive, send) File "/opt/conda/envs/historian/lib/python3.12/site-packages/connexion/middleware/routing.py", line 48, in call await self.next_app(original_scope, receive, send) File "/opt/conda/envs/historian/lib/python3.12/site-packages/connexion/middleware/abstract.py", line 261, in call await self.app(scope, receive, send) File "/opt/conda/envs/historian/lib/python3.12/site-packages/connexion/middleware/abstract.py", line 261, in call await self.app(scope, receive, send) File "/opt/conda/envs/historian/lib/python3.12/site-packages/connexion/middleware/abstract.py", line 261, in call await self.app(scope, receive, send) File "/opt/conda/envs/historian/lib/python3.12/site-packages/connexion/middleware/lifespan.py", line 26, in call await self.next_app(scope, receive, send) File "/opt/conda/envs/historian/lib/python3.12/site-packages/connexion/middleware/abstract.py", line 261, in call await self.app(scope, receive, send) File "/opt/conda/envs/historian/lib/python3.12/site-packages/connexion/apps/flask.py", line 151, in call return await self.asgi_app(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/historian/lib/python3.12/site-packages/a2wsgi/wsgi.py", line 165, in call return await responder(scope, receive, send) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/historian/lib/python3.12/site-packages/a2wsgi/wsgi.py", line 200, in call await self.loop.run_in_executor( File "/opt/conda/envs/historian/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(self.args, self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/historian/lib/python3.12/site-packages/a2wsgi/wsgi.py", line 256, in wsgi iterable = self.app(environ, start_response) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/historian/lib/python3.12/site-packages/flask/app.py", line 1476, in wsgi_app response = self.handle_exception(e) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/historian/lib/python3.12/site-packages/flask/app.py", line 1473, in wsgi_app response = self.full_dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/historian/lib/python3.12/site-packages/flask/app.py", line 882, in full_dispatch_request rv = self.handle_user_exception(e) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/historian/lib/python3.12/site-packages/flask/app.py", line 880, in full_dispatch_request rv = self.dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/historian/lib/python3.12/site-packages/flask/app.py", line 865, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(view_args) # type: ignore[no-any-return] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/historian/lib/python3.12/site-packages/connexion/apps/flask.py", line 68, in call return self.fn(args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/historian/lib/python3.12/site-packages/connexion/decorators/main.py", line 132, in wrapper request = self.framework.get_request(uri_parser=self.uri_parser) ^^^^^^^^^^^^^^^ File "/opt/conda/envs/historian/lib/python3.12/site-packages/connexion/decorators/main.py", line 72, in uri_parser uri_parser_class = self.uri_parser_class or operation.uri_parser_class ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/historian/lib/python3.12/site-packages/werkzeug/local.py", line 318, in get obj = instance._get_current_object() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/conda/envs/historian/lib/python3.12/site-packages/werkzeug/local.py", line 519, in _get_current_object raise RuntimeError(unbound_message) from None RuntimeError: Working outside of operation context. Make sure your app is wrapped in a ContextMiddleware and you're processing a request while accessing the context. INFO: 127.0.0.1:56016 - "POST /greeting/e%0Aric HTTP/1.1" 500 Internal Server Error

Steps to reproduce

Simply run the quick start app of the documentation (https://connexion.readthedocs.io/en/latest/quickstart.html) and post /greeting/e%0Aric

Additional info:

Output of the commands:

juhoinkinen commented 2 months ago

Duplicate of https://github.com/spec-first/connexion/issues/1908.