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 Tim Graham, 8 years ago

Triage Stage: UnreviewedAccepted

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

comment:2 by Anton Samarchyan, 8 years ago

Has patch: set
Version: 1.10master

Added PR 7470

comment:3 by Zbigniew Siciarz, 8 years ago

Cc: zbigniew@… added
Needs tests: set

comment:4 by Anton Samarchyan, 8 years ago

Needs tests: unset

Added tests PR 7470

comment:5 by Tim Graham, 8 years ago

Patch needs improvement: set

comment:6 by Anton Samarchyan, 8 years ago

Patch needs improvement: unset

Added test PR 7470

comment:7 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In 05d2c5a:

Fixed #27181 -- Allowed contrib.sites to match domains with trailing ".".

Note: See TracTickets for help on using tickets.
Back to Top