Fix Paperless login redirect issue

- Configure LOGIN_REDIRECT_URL and LOGOUT_REDIRECT_URL to /paperless/
- Set proper cookie paths for session isolation (/paperless/ instead of /)
- Use environment variables for redirect URLs in paperless_custom_settings.py
- Add PAPERLESS_URL and PAPERLESS_FORCE_SCRIPT_NAME to env template
- Ensure FORCE_SCRIPT_NAME respects environment variable

This fixes the issue where logging into Paperless redirects to the root Django
app instead of staying within the Paperless scope. The docker-compose.yml
already has the correct environment variables set.
This commit is contained in:
2025-10-05 20:57:06 +02:00
parent 544284dd8b
commit da66bd356e
2 changed files with 16 additions and 4 deletions

View File

@@ -10,9 +10,18 @@ SESSION_COOKIE_NAME = 'paperless_sessionid'
# Also change CSRF cookie name for good measure
CSRF_COOKIE_NAME = 'paperless_csrftoken'
# Ensure cookies are scoped to avoid conflicts
SESSION_COOKIE_PATH = '/'
CSRF_COOKIE_PATH = '/'
# Scope cookies to Paperless path to avoid conflicts
SESSION_COOKIE_PATH = '/paperless/'
CSRF_COOKIE_PATH = '/paperless/'
# Different secret key salt to ensure session isolation
SESSION_COOKIE_SALT = 'paperless.sessions'
SESSION_COOKIE_SALT = 'paperless.sessions'
# Fix login redirect to stay within Paperless scope
# Use environment variable if set, otherwise default to /paperless/
LOGIN_REDIRECT_URL = os.getenv('PAPERLESS_LOGIN_REDIRECT_URL', '/paperless/')
LOGOUT_REDIRECT_URL = os.getenv('PAPERLESS_LOGOUT_REDIRECT_URL', '/paperless/')
LOGIN_URL = '/paperless/accounts/login/'
# Ensure Force Script Name for proper URL handling behind proxy
FORCE_SCRIPT_NAME = os.getenv('PAPERLESS_FORCE_SCRIPT_NAME', '/paperless')