简体   繁体   English

Django ALLOWED_HOSTS 中的 0.0.0.0 是否存在安全风险?

[英]Is 0.0.0.0 in Django ALLOWED_HOSTS a security risk?

There's plenty of these questions based on configuration of Django's settings, but I'm asking from a security perspective--有很多基于 Django 设置配置的问题,但我是从安全角度问的——

Background: This is (obviously) a Django app which I am running inside a Docker container;背景:这是(显然)一个 Django 应用程序,我在 Docker 容器中运行; gunicorn is running in that container and set to listen on port 8000 ( gunicorn my_app.wsgi:application --bind 0.0.0.0:8000 ). gunicorn 在该容器中运行并设置为侦听端口 8000 ( gunicorn my_app.wsgi:application --bind 0.0.0.0:8000 )。 Nginx is public-facing (listening on 80) and running in a separate container. Nginx 面向公众(在 80 上监听)并在单独的容器中运行。 Nginx sends the requests to the Django container over the internal.network setup by docker-compose. Nginx 通过 docker-compose 设置的 internal.network 将请求发送到 Django 容器。

At the moment, I'm running this on a cloud machine with an ephemeral IP. I have added that to my ALLOWED_HOSTS so that it reads ALLOWED_HOSTS=['XX.XXX.XX.XX'] where xx.xxx.xx.xx is the actual IP. The application works.目前,我正在一台具有临时 IP 的云计算机上运行它。我已将其添加到我的 ALLOWED_HOSTS 中,以便它读取ALLOWED_HOSTS=['XX.XXX.XX.XX']其中xx.xxx.xx.xx是实际的 IP。该应用程序有效。

My question: My application monitoring just informed me of an apparent error which read:我的问题:我的应用程序监控刚刚通知我一个明显的错误,内容如下:

api_1    | 2020-07-29 16:50:24,498 django.security.DisallowedHost.response_for_exception ERROR    
Invalid HTTP_HOST header: '0.0.0.0:8000'. You may need to add '0.0.0.0' to ALLOWED_HOSTS.

This was not a request I made-- likely just some bot.不是我提出的请求——可能只是一些机器人。

Should I actually add 0.0.0.0 to ALLOWED_HOSTS ?我真的应该将0.0.0.0添加到ALLOWED_HOSTS吗? Or is that a security risk?或者这是一个安全风险? Will that allow bogus requests through?这会允许虚假请求通过吗? What does 0.0.0.0 mean in the context of my Django application? 0.0.0.0在我的 Django 应用程序的上下文中意味着什么? If it should only get receiving requests sent by the nginx server, shouldn't those all have the xx.xxx.xx.xx IP as the host header?如果它应该只接收由 nginx 服务器发送的请求,那么这些服务器不应该都将 xx.xxx.xx.xx IP 作为主机 header 吗?

I don't necessarily want all these bot/scanning requests to fill-up my application monitoring with junk and this does not seem to be a "real" error.我不一定希望所有这些机器人/扫描请求用垃圾填满我的应用程序监控,这似乎不是“真正的”错误。 My understanding of.networking is limited, so I apologize if this is a simple question.我对.networking的理解有限,所以如果这是一个简单的问题,我很抱歉。

Thanks!谢谢!

I would only add the IP addresses or hosts that you know to be legitimate to ALLOWED_HOSTS.我只会将您知道合法的 IP 地址或主机添加到 ALLOWED_HOSTS。 It is a setting to prevent bots from doing potential damage to your system.这是一种防止机器人对您的系统造成潜在损害的设置。

In terms of filling up your application monitoring system, I would have a system that allows for ignoring these once you have reviewed them在填写您的应用程序监控系统方面,我会有一个系统,一旦您审查了它们,就可以忽略它们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM