Open hofst opened 2 years ago
At a glance, it looks like there is no match_info available in BaseRequest. I think the best solution would be to change middlewares to run even on system routes: https://github.com/aio-libs/aiohttp/issues/3287#issuecomment-2276937564
Describe the bug
Context: I believe the recommended way to remove the Server header is via
on_response_prepare
. This works well in most but not all cases. Since the Server header is a security liability, it is important to remove it in all cases. But independently, it would be important to have a reliable mechanism/hook/callback to modify all responses. Note: The callback is called correctly for other errors, e.g., routing errors.Problem: One noteworthy case where the callback does not work is the processing of
BaseRequests
which does not call theon_response_prepare
callback. Unfortuantely, aiohttp internally usesBaseRequests
in case of parser errors. You can provoke parser errors, e.g, viacurl -X ASD localhost
. This is not a contrived example. I have noticed such requests from some unknown attacker/bot in my logs today.Independent but related issue: I tried to work around it by manually overwriting the
BaseRequest._prepare_hook
from outside but noticed another problem: It appears that anasyncio.CancelledError
is not handled correctly if it is raised during a parsing errors from the_prepare_hook
: the socket stays open and leaks (from the client's perspective).To Reproduce
curl -X ASD localhost
on_resposne_prepare
callback is not calledExpected behavior
on_resposne_prepare callbacks should always be called and for any Response
Logs/tracebacks
Python Version
aiohttp Version
multidict Version
yarl Version
OS
Ubuntu 21.04
Related component
Server
Additional context
No response
Code of Conduct