Opened 8 years ago
Closed 8 years ago
#27181 closed Bug (fixed)
Sites framework does not normalize domains with trailing "."
Reported by: | Ran Benita | Owned by: | nobody |
---|---|---|---|
Component: | contrib.sites | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | zbigniew@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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".
Change History (7)
comment:1 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 8 years ago
Cc: | added |
---|---|
Needs tests: | set |
comment:5 by , 8 years ago
Patch needs improvement: | set |
---|
Perhaps
http.request.split_domain_port()
should remove the trailing dot rather thanvalidate_host()
looking for the trailing dot.