mirror of
https://github.com/daniviga/django-ram.git
synced 2026-02-03 17:40:39 +01:00
Implement CSP via Django 6.0
This commit is contained in:
@@ -1,4 +1,13 @@
|
|||||||
|
from django import VERSION as DJANGO_VERSION
|
||||||
|
from django.utils.termcolors import colorize
|
||||||
from ram.utils import git_suffix
|
from ram.utils import git_suffix
|
||||||
|
|
||||||
|
if DJANGO_VERSION < (6, 0):
|
||||||
|
exit(
|
||||||
|
colorize(
|
||||||
|
"ERROR: This project requires Django 6.0 or higher.", fg="red"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
__version__ = "0.19.10"
|
__version__ = "0.19.10"
|
||||||
__version__ += git_suffix(__file__)
|
__version__ += git_suffix(__file__)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ Django settings for ram project.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from django.utils.csp import CSP
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
@@ -12,9 +13,7 @@ STORAGE_DIR = BASE_DIR / "storage"
|
|||||||
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = (
|
SECRET_KEY = "django-ram-insecure-Chang3m3-1n-Pr0duct10n!"
|
||||||
"django-ram-insecure-Chang3m3-1n-Pr0duct10n!"
|
|
||||||
)
|
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
@@ -48,6 +47,7 @@ MIDDLEWARE = [
|
|||||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||||
"django.middleware.common.CommonMiddleware",
|
"django.middleware.common.CommonMiddleware",
|
||||||
"django.middleware.csrf.CsrfViewMiddleware",
|
"django.middleware.csrf.CsrfViewMiddleware",
|
||||||
|
"django.middleware.csp.ContentSecurityPolicyMiddleware",
|
||||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||||
"django.contrib.messages.middleware.MessageMiddleware",
|
"django.contrib.messages.middleware.MessageMiddleware",
|
||||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||||
@@ -109,11 +109,25 @@ DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|||||||
MEDIA_URL = "media/"
|
MEDIA_URL = "media/"
|
||||||
MEDIA_ROOT = STORAGE_DIR / "media"
|
MEDIA_ROOT = STORAGE_DIR / "media"
|
||||||
|
|
||||||
# cookies hardening
|
# Enforce a CSP policy:
|
||||||
SESSION_COOKIE_NAME = '__Secure-sessionid'
|
CDN_WHITELIST_CSP = ["https://cdn.jsdelivr.net/"]
|
||||||
|
SECURE_CSP = {
|
||||||
|
"default-src": [CSP.SELF] + CDN_WHITELIST_CSP,
|
||||||
|
"img-src": ["data:", "*"],
|
||||||
|
"script-src": [
|
||||||
|
CSP.SELF,
|
||||||
|
CSP.UNSAFE_INLINE,
|
||||||
|
"https://www.googletagmanager.com/",
|
||||||
|
]
|
||||||
|
+ CDN_WHITELIST_CSP,
|
||||||
|
"style-src": [CSP.SELF, CSP.UNSAFE_INLINE] + CDN_WHITELIST_CSP,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Cookies hardening
|
||||||
|
SESSION_COOKIE_NAME = "__Secure-sessionid"
|
||||||
SESSION_COOKIE_SECURE = True
|
SESSION_COOKIE_SECURE = True
|
||||||
SESSION_COOKIE_HTTPONLY = True
|
SESSION_COOKIE_HTTPONLY = True
|
||||||
CSRF_COOKIE_NAME = '__Secure-csrftoken'
|
CSRF_COOKIE_NAME = "__Secure-csrftoken"
|
||||||
CSRF_COOKIE_SECURE = True
|
CSRF_COOKIE_SECURE = True
|
||||||
CSRF_COOKIE_HTTPONLY = True
|
CSRF_COOKIE_HTTPONLY = True
|
||||||
|
|
||||||
@@ -169,7 +183,7 @@ MANUFACTURER_TYPES = [
|
|||||||
("model", "Model"),
|
("model", "Model"),
|
||||||
("real", "Real"),
|
("real", "Real"),
|
||||||
("accessory", "Accessory"),
|
("accessory", "Accessory"),
|
||||||
("other", "Other")
|
("other", "Other"),
|
||||||
]
|
]
|
||||||
|
|
||||||
ROLLING_STOCK_TYPES = [
|
ROLLING_STOCK_TYPES = [
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
pytz
|
pytz
|
||||||
pillow
|
pillow
|
||||||
markdown
|
markdown
|
||||||
Django
|
Django>=6.0
|
||||||
djangorestframework
|
djangorestframework
|
||||||
django-solo
|
django-solo
|
||||||
django-countries
|
django-countries
|
||||||
|
|||||||
Reference in New Issue
Block a user