Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django ALLOWED_HOSTS: OK to include 'localhost' on a deployed settings file?

Tags:

django

I'm working in Django 1.8. I have set ALLOWED_HOSTS as follows, in both my local and deployed settings:

ALLOWED_HOSTS = ['localhost', 'my.deployed.url']

That way I don't need to change the settings in the deployed version. (Not that this is difficult to do, it's just convenient this way.)

Is there any security reason why I shouldn't have localhost there on the deployed settings on the remote server?

From the docs I don't think there is, but just wanted to check.

like image 878
Richard Avatar asked Jun 01 '15 17:06

Richard


People also ask

What is the usage of ALLOWED_HOSTS in Django project settings?

ALLOWED_HOSTS. A list of strings representing the host/domain names that this Django site can serve. This is a security measure to prevent HTTP Host header attacks, which are possible even under many seemingly-safe web server configurations.

What is allowed host?

An allowed host may be an additional subdomain used by your web application or a completely separate domain used for an API. For example, you can add https://api.example.com as an allowed host to the main target https://www.example.com.


2 Answers

As long as the app does not give superpowers to requests with 'localhost' in the Host http header it should be ok.

like image 93
Peter Tillemans Avatar answered Oct 19 '22 23:10

Peter Tillemans


In Django 2.1.4, another solution is: ALLOWED_HOSTS = ['127.0.0.1']

like image 6
Gajmera Avatar answered Oct 19 '22 23:10

Gajmera