[Django] #27181: Sites framework does not normalize domains with trailing "."

43 views
Skip to first unread message

Django

unread,
Sep 5, 2016, 10:28:52 AM9/5/16
to django-...@googlegroups.com
#27181: Sites framework does not normalize domains with trailing "."
-------------------------------+--------------------
Reporter: bluetech | Owner: nobody
Type: Bug | Status: new
Component: contrib.sites | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
I have a Django project which uses the sites framework. The site is picked
by the {{{Host}}} and not by setting {{{SITE_ID}}}. Suppose one of the
domains is "mysite.com". In DNS, this is equivalent to "mysite.com." (note
the trailing dot). The nginx webserver, uwsgi, and Django's own
{{{ALLOWED_HOSTS}}} accept "mysite.com." where "mysite.com" is specified.
For example, the {{{validate_host()}}} function in http/request.py has
this line:

{{{
host = host[:-1] if host.endswith('.') else host
}}}

which strips the trailing dot if it exists, before matching (this code is
not ideal BTW, I think it will not work as intended if the host has a
port).

However, the sites framework (in contrib/sites/models.py,
{{{SiteManager._get_site_by_request}}}) fails to match in this case. This
causes 500 when {{{get_current_site()}}} is called whenever a user
requests some URL like "http://mysite.com./".

It would be nice if the sites framework was fixed to match trailing dot as
well, similar to how https://code.djangoproject.com/ticket/24834 was fixed
to deal with a {{{Host}}} like "mysite.com:80".

--
Ticket URL: <https://code.djangoproject.com/ticket/27181>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 6, 2016, 10:44:55 AM9/6/16
to django-...@googlegroups.com
#27181: Sites framework does not normalize domains with trailing "."
-------------------------------+------------------------------------

Reporter: bluetech | Owner: nobody
Type: Bug | Status: new
Component: contrib.sites | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


Comment:

Perhaps `http.request.split_domain_port()` should remove the trailing dot
rather than `validate_host()` looking for the trailing dot.

--
Ticket URL: <https://code.djangoproject.com/ticket/27181#comment:1>

Django

unread,
Nov 4, 2016, 4:30:32 PM11/4/16
to django-...@googlegroups.com
#27181: Sites framework does not normalize domains with trailing "."
-------------------------------+------------------------------------
Reporter: Ran Benita | Owner: nobody
Type: Bug | Status: new
Component: contrib.sites | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Anton Samarchyan):

* has_patch: 0 => 1
* version: 1.10 => master


Comment:

Added [https://github.com/django/django/pull/7470 PR 7470]

--
Ticket URL: <https://code.djangoproject.com/ticket/27181#comment:2>

Django

unread,
Nov 5, 2016, 5:23:29 AM11/5/16
to django-...@googlegroups.com
#27181: Sites framework does not normalize domains with trailing "."
-------------------------------+------------------------------------
Reporter: Ran Benita | Owner: nobody
Type: Bug | Status: new

Component: contrib.sites | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Zbigniew Siciarz):

* cc: zbigniew@… (added)
* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/27181#comment:3>

Django

unread,
Nov 21, 2016, 12:54:53 PM11/21/16
to django-...@googlegroups.com
#27181: Sites framework does not normalize domains with trailing "."
-------------------------------+------------------------------------
Reporter: Ran Benita | Owner: nobody
Type: Bug | Status: new

Component: contrib.sites | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Anton Samarchyan):

* needs_tests: 1 => 0


Comment:

Added tests [https://github.com/django/django/pull/7470 PR 7470]

--
Ticket URL: <https://code.djangoproject.com/ticket/27181#comment:4>

Django

unread,
Nov 22, 2016, 9:15:39 AM11/22/16
to django-...@googlegroups.com
#27181: Sites framework does not normalize domains with trailing "."
-------------------------------+------------------------------------
Reporter: Ran Benita | Owner: nobody
Type: Bug | Status: new

Component: contrib.sites | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/27181#comment:5>

Django

unread,
Nov 25, 2016, 4:30:15 PM11/25/16
to django-...@googlegroups.com
#27181: Sites framework does not normalize domains with trailing "."
-------------------------------+------------------------------------
Reporter: Ran Benita | Owner: nobody
Type: Bug | Status: new

Component: contrib.sites | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Anton Samarchyan):

* needs_better_patch: 1 => 0


Comment:

Added test [https://github.com/django/django/pull/7470 PR 7470]

--
Ticket URL: <https://code.djangoproject.com/ticket/27181#comment:6>

Django

unread,
Nov 29, 2016, 6:17:31 PM11/29/16
to django-...@googlegroups.com
#27181: Sites framework does not normalize domains with trailing "."
-------------------------------+------------------------------------
Reporter: Ran Benita | Owner: nobody
Type: Bug | Status: closed
Component: contrib.sites | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"05d2c5a66dd72c26e5221855e08834a66c844399" 05d2c5a]:
{{{
#!CommitTicketReference repository=""
revision="05d2c5a66dd72c26e5221855e08834a66c844399"
Fixed #27181 -- Allowed contrib.sites to match domains with trailing ".".
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27181#comment:7>

Reply all
Reply to author
Forward
0 new messages