Skip to content

Commit 2d556d9

Browse files
authored
Add 0.0.0.0 to non-production ALLOWED_HOSTS (#225)
The Dev Center guide instructs users running this project locally to visit `http://localhost:5001`, however, some users don't read the guide properly and instead use the URL output by gunicorn to the logs: ``` [2024-05-27 09:52:07 +0000] [1] [INFO] Listening at: http://0.0.0.0:5001 (1) ``` Django's default debug mode `ALLOWED_HOSTS` only includes `localhost` and `127.0.0.1` etc, so as a result using `0.0.0.0` would result in a `DisallowedHost` error: https://docs.djangoproject.com/en/5.0/ref/settings/#allowed-hosts According to RFC5735 `0.0.0.0` shouldn't be a routable IP, however, browsers and some other clients choose to treat it like localhost: https://stackoverflow.com/a/55646032 Adding it to `ALLOWED_HOSTS` is safe, so we might as well do so to improve the UX when users don't follow the guide properly. See: https://devcenter.heroku.com/admin/articles/feedback/2161#27486 https://devcenter.heroku.com/admin/articles/feedback/2161#27738 GUS-W-14193867.
1 parent f15864a commit 2d556d9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

gettingstarted/settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@
4747
DEBUG = True
4848

4949
# On Heroku, it's safe to use a wildcard for `ALLOWED_HOSTS``, since the Heroku router performs
50-
# validation of the Host header in the incoming HTTP request. On other platforms you may need
51-
# to list the expected hostnames explicitly to prevent HTTP Host header attacks. See:
50+
# validation of the Host header in the incoming HTTP request. On other platforms you may need to
51+
# list the expected hostnames explicitly in production to prevent HTTP Host header attacks. See:
5252
# https://docs.djangoproject.com/en/5.0/ref/settings/#std-setting-ALLOWED_HOSTS
5353
if IS_HEROKU_APP:
5454
ALLOWED_HOSTS = ["*"]
5555
else:
56-
ALLOWED_HOSTS = []
56+
ALLOWED_HOSTS = [".localhost", "127.0.0.1", "[::1]", "0.0.0.0"]
5757

5858

5959
# Application definition

0 commit comments

Comments
 (0)