Protect privileged sign-in and customer password recovery

This commit is contained in:
parkel committed 2026-11-22 11:30:58 +01:00
1 parent 0143543abd
commit 2e9caf5498
27 files changed
+1195 -8

No files matched your search

+55
View File
@@ -42,6 +42,16 @@ def ip_addresses_env(name, limit):
SECRET_KEY = required_env("COULOBRE_SECRET_KEY")
HTTPS_PROXY = os.environ.get("COULOBRE_HTTPS_PROXY") == "1"
REQUIRE_PRIVILEGED_MFA = (
os.environ.get(
"COULOBRE_REQUIRE_PRIVILEGED_MFA", "1" if HTTPS_PROXY else "0"
)
== "1"
)
OTP_TOTP_ISSUER = "Coulobre Panel"
TRUST_APACHE_CLIENT_IP = (
os.environ.get("COULOBRE_TRUST_APACHE_CLIENT_IP") == "1"
)
DEBUG = not HTTPS_PROXY and os.environ.get("COULOBRE_DEBUG") == "1"
ALLOWED_HOSTS = os.environ.get(
"COULOBRE_ALLOWED_HOSTS", "localhost,127.0.0.1,[::1]"
@@ -61,6 +71,9 @@ INSTALLED_APPS = [
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django_otp",
"django_otp.plugins.otp_totp",
"django_otp.plugins.otp_email",
"coulobre.hosting",
]
@@ -70,6 +83,8 @@ MIDDLEWARE = [
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django_otp.middleware.OTPMiddleware",
"coulobre.hosting.sign_in.PrivilegedFactorMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"coulobre.hosting.impersonation.CustomerImpersonationMiddleware",
@@ -141,6 +156,42 @@ LOGIN_URL = "panel:login"
LOGIN_REDIRECT_URL = "panel:accounts"
LOGOUT_REDIRECT_URL = "panel:login"
PASSWORD_RESET_TIMEOUT = 1800
PASSWORD_RESET_ORIGIN = os.environ.get("COULOBRE_PASSWORD_RESET_ORIGIN", "")
if PASSWORD_RESET_ORIGIN:
try:
reset_origin = urlsplit(PASSWORD_RESET_ORIGIN)
if (
reset_origin.scheme != "https"
or not reset_origin.hostname
or reset_origin.username is not None
or reset_origin.path not in ("", "/")
or reset_origin.query
or reset_origin.fragment
or reset_origin.port == 0
or any(char.isspace() for char in PASSWORD_RESET_ORIGIN)
):
raise ValueError
except ValueError:
raise ImproperlyConfigured(
"Set COULOBRE_PASSWORD_RESET_ORIGIN to the HTTPS panel origin."
) from None
EMAIL_HOST = os.environ.get("COULOBRE_SMTP_HOST", "")
EMAIL_PORT = int(os.environ.get("COULOBRE_SMTP_PORT", "587"))
EMAIL_HOST_USER = os.environ.get("COULOBRE_SMTP_USER", "")
EMAIL_HOST_PASSWORD = os.environ.get("COULOBRE_SMTP_PASSWORD", "")
EMAIL_USE_TLS = os.environ.get("COULOBRE_SMTP_STARTTLS", "1") == "1"
EMAIL_TIMEOUT = 10
DEFAULT_FROM_EMAIL = os.environ.get(
"COULOBRE_EMAIL_FROM", "Coulobre Panel <panel@localhost>"
)
OTP_EMAIL_SUBJECT = "Your Coulobre Panel verification code"
OTP_EMAIL_BODY_TEMPLATE = (
"Your Coulobre Panel verification code is {{ token }}. "
"It expires in five minutes."
)
CELERY_BROKER_URL = os.environ.get(
"COULOBRE_BROKER_URL", "amqp://guest:guest@127.0.0.1:5672//"
)
@@ -282,6 +333,10 @@ if (LOCAL_ACCOUNT_BACKUP_MAIL and REMOTE_ACCOUNT_BACKUP_MAIL) or (
"Choose one mailbox transport for backup and one for restore."
)
CELERY_BEAT_SCHEDULE = {
"expire-panel-sign-in-windows": {
"task": "coulobre.hosting.tasks.expire_sign_in_windows",
"schedule": 600.0,
},
"dispatch-account-retirements": {
"task": "coulobre.hosting.tasks.dispatch_account_retirements",
"schedule": 5.0,