From 76d041f633967efdc4777f5621917a77b4af2147 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 21 Nov 2023 13:11:45 -0800 Subject: [PATCH] Use KHOJ_HOST env var to set allowed/trusted domains to host Khoj Allows hosting Khoj behind other, non "khoj.dev" domains --- src/khoj/app/settings.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/khoj/app/settings.py b/src/khoj/app/settings.py index 97a058da..1126c92e 100644 --- a/src/khoj/app/settings.py +++ b/src/khoj/app/settings.py @@ -26,13 +26,13 @@ SECRET_KEY = os.getenv("KHOJ_DJANGO_SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! DEBUG = os.getenv("KHOJ_DEBUG") == "True" -ALLOWED_HOSTS = [".khoj.dev", "localhost", "127.0.0.1", "[::1]", "beta.khoj.dev"] +# All Subdomains of KHOJ_DOMAIN are trusted +KHOJ_DOMAIN = os.getenv("KHOJ_DOMAIN", "khoj.dev") +ALLOWED_HOSTS = [f".{KHOJ_DOMAIN}", "localhost", "127.0.0.1", "[::1]"] CSRF_TRUSTED_ORIGINS = [ - "https://app.khoj.dev", - "https://beta.khoj.dev", - "https://khoj.dev", - "https://*.khoj.dev", + f"https://*.{KHOJ_DOMAIN}", + f"https://{KHOJ_DOMAIN}", ] COOKIE_SAMESITE = "None" @@ -40,8 +40,8 @@ if DEBUG: SESSION_COOKIE_DOMAIN = "localhost" CSRF_COOKIE_DOMAIN = "localhost" else: - SESSION_COOKIE_DOMAIN = "khoj.dev" - CSRF_COOKIE_DOMAIN = "khoj.dev" + SESSION_COOKIE_DOMAIN = KHOJ_DOMAIN + CSRF_COOKIE_DOMAIN = KHOJ_DOMAIN SESSION_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True