My django project allows downloding images from static folder:
http://0.0.0.0:8001/static/img/login.png
This makes sense.
But what concerns me is that it also allows me downloading files even outside of the static folder such as:
http://0.0.0.0:8000/logs/result.log
or even worse:
http://0.0.0.0:8000/users/models.py
All my local files can be downloaded via clients.
This is a high security vulnerability. No matter what is the permission of my folders on my Linux server. I do not have such items in my path and I do not expect these paths being served.
How can I fix this?
BASE_DIR = Path(__file__).resolve().parent.parent
DEBUG = True
INSTALLED_APPS = [
'comments',
'home',
'users',
'articles',
'notifications',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.sessions',
'django.contrib.staticfiles',
'static_precompiler',
'django_markup',
'django_minify_html',
'django_rename_app',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django_minify_html.middleware.MinifyHtmlMiddleware',
]
ROOT_URLCONF = 'profplus.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ["templates"],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'profplus.wsgi.application'
STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'static_precompiler.finders.StaticPrecompilerFinder',
]