security: fix SMTP credential exposure and auth bypass
- C-1: Move EMAIL_HOST_PASSWORD to os.environ (was hardcoded plaintext) - C-2: Enable token-user cross-validation in validate_token_and_get_user() (compares token.user_id with user.id to prevent impersonation) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@ DEBUG = False
|
||||
ALLOWED_HOSTS = [
|
||||
'db.eventifyplus.com',
|
||||
'uat.eventifyplus.com',
|
||||
'em.eventifyplus.com',
|
||||
'backend.eventifyplus.com',
|
||||
'admin.eventifyplus.com',
|
||||
'app.eventifyplus.com',
|
||||
@@ -149,8 +150,13 @@ LOGIN_URL = 'login'
|
||||
LOGIN_REDIRECT_URL = 'dashboard'
|
||||
LOGOUT_REDIRECT_URL = 'login'
|
||||
|
||||
# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
||||
# DEFAULT_FROM_EMAIL = 'no-reply@example.com'
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
EMAIL_HOST = 'mail.bshtech.net'
|
||||
EMAIL_PORT = 587
|
||||
EMAIL_USE_TLS = True
|
||||
EMAIL_HOST_USER = 'no-reply@eventifyplus.com'
|
||||
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD', '')
|
||||
DEFAULT_FROM_EMAIL = 'Eventify <no-reply@eventifyplus.com>'
|
||||
|
||||
SUMMERNOTE_THEME = 'bs5'
|
||||
|
||||
|
||||
@@ -80,13 +80,13 @@ def validate_token_and_get_user(request, error_status_code=None):
|
||||
status=status
|
||||
))
|
||||
|
||||
# Verify username matches token user
|
||||
# if user.username != username:
|
||||
# status = 401 if error_status_code else None
|
||||
# return (None, None, None, JsonResponse(
|
||||
# {"status": "error", "message": "token does not match user"},
|
||||
# status=status
|
||||
# ))
|
||||
# Verify token belongs to this user
|
||||
if token.user_id != user.id:
|
||||
status = 401 if error_status_code else None
|
||||
return (None, None, None, JsonResponse(
|
||||
{"status": "error", "message": "token does not match user"},
|
||||
status=status
|
||||
))
|
||||
|
||||
# Success - return user, token, data, and None for error_response
|
||||
return (user, token, data, None)
|
||||
|
||||
Reference in New Issue
Block a user