-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
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
Invalid SERVER_NAME
+ url_for
leads to AttributeError
#5392
Comments
SERVER_NAME
+ url_for
leads to AttributeError
I'm having a hard time evaluating this. None of the suggested fixes are really useful. 1 is not possible. 3 is not possible, except to "handle" it by raising an error, which is what happens when the app context (instead of request context) can't create an adapter. 2 is possible, at least to raise a clearer error message closer to where the problem occurs, as explained for 3, but it shouldn't be something the dev should consider handling, since ultimately it's an issue with the server environment. There is a little known feature called |
Thanks for checking this. I know it's a weird one, with not a clear path forward. I like the idea to register a url build error handler 👍 |
Hi, I now found a reproducible example by just providing an invalid Host header value. I also reported it to cheroot: cherrypy/cheroot#646 |
After thinking about this more, I'm going to close it for now. It seems to be mainly a server configuration issue rather than an issue with Flask. I don't think spending time resurrecting/changing an unused feature in Flask is really worth it for this. |
Anyways, thanks for the time analysis this. I hugkly appreciate it! |
In our environment we have some security scanners running which generate artificial HTTP requests. Since they are closed source and I can't generate these calls with other tools, I created the below example which starts at the flask level and assumes that an invalid server passed thru the levels.
Error
As you can see, the server_name passed to flask is invalid. This should normally not happen, but let's just assume that it might happen. In my case I use cheroot and it let's it thru.
Then the server name should be encoded with IDNA which fails and that is fine. However, then the custom error handler for 400 is called and in my case it contains a
url_for
call. This call then fails with anAttributeError
because the request was never fully consumed by flask.Even if this seems now a little bit artificial, I would like to ask, if flask could improve its handling here, I have the following ideas
AttributeError
so that the caller ofurl_for
can handle it gracefullyNone
url_adapter
inurl_for
Environment:
This error also happens with flask/werkzeug 3.0
The text was updated successfully, but these errors were encountered: