Since Django was previously fixed to handle `request.get_host()` raising
`DisallowedHost` elsewhere in `CsrfViewMiddleware.process_view()` (see
ticket #28693), it seems like it should be handled here, too.
--
Ticket URL: <https://code.djangoproject.com/ticket/32578>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Tim Graham):
It might be better to perform host validation elsewhere in Django as
suggested in #27575 so that `DisallowedHost` doesn't need to be caught
everywhere.
--
Ticket URL: <https://code.djangoproject.com/ticket/32578#comment:1>
Comment (by Chris Jerdonek):
Another option would be for `get_host()` to accept an argument that causes
it to return e.g. `None` on a disallowed host instead of raising
`DisallowedHost`. That would make people more aware of that possibility
and give callers another option aside from a try-except for handling that
case.
--
Ticket URL: <https://code.djangoproject.com/ticket/32578#comment:2>
* Attachment "32578.diff" added.
Regression test.
* type: Uncategorized => Bug
* easy: 0 => 1
* stage: Unreviewed => Accepted
Comment:
Thanks for the report. I attached a test.
--
Ticket URL: <https://code.djangoproject.com/ticket/32578#comment:3>
Comment (by Chris Jerdonek):
Thanks, Mariusz. However, do you know for sure that's testing the right
code path? `_origin_verified()` only gets called when `if request.method
not in ('GET', 'HEAD', 'OPTIONS', 'TRACE')`, but the test appears to be
`GET`. I could be wrong though since my observation is based on inspection
rather than running the test.
--
Ticket URL: <https://code.djangoproject.com/ticket/32578#comment:4>
* Attachment "32578.diff" added.
Regression test.
--
Comment (by Mariusz Felisiak):
Replying to [comment:4 Chris Jerdonek]:
> Thanks, Mariusz. However, do you know for sure that's testing the right
code path? `_origin_verified()` only gets called when `if request.method
not in ('GET', 'HEAD', 'OPTIONS', 'TRACE')`, but the test appears to be
`GET`. I could be wrong though since my observation is based on inspection
rather than running the test.
Test crashes because `method` is not set in this case. I updated attached
test to use the `POST` method.
----
Replying to [comment:2 Tim Graham]:
> It might be better to perform host validation elsewhere in Django as
suggested in #27575 so that DisallowedHost doesn't need to be caught
everywhere.
This can be tricky, so I'd fix this case independently and discuss the
options in #27575.
--
Ticket URL: <https://code.djangoproject.com/ticket/32578#comment:5>
Comment (by Chris Jerdonek):
> Test crashes because method is not set in this case. I updated attached
test to use the POST method.
It might be good to fix `_get_GET_no_csrf_cookie_request()` so that the
method is indeed set to `GET`.
--
Ticket URL: <https://code.djangoproject.com/ticket/32578#comment:6>
Comment (by Mariusz Felisiak):
Replying to [comment:6 Chris Jerdonek]:
> It might be good to fix `_get_GET_no_csrf_cookie_request()` so that the
method is indeed set to `GET`.
Agreed, [https://github.com/django/django/pull/14166 PR].
--
Ticket URL: <https://code.djangoproject.com/ticket/32578#comment:7>
* owner: nobody => Chris Jerdonek
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/32578#comment:8>
* has_patch: 0 => 1
Comment:
PR: https://github.com/django/django/pull/14179
--
Ticket URL: <https://code.djangoproject.com/ticket/32578#comment:9>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"ff514309e178e3955012050ead9b8fc66dc21a5b" ff514309]:
{{{
#!CommitTicketReference repository=""
revision="ff514309e178e3955012050ead9b8fc66dc21a5b"
Fixed #32578 -- Fixed crash in CsrfViewMiddleware when a request with
Origin header has an invalid host.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32578#comment:10>