dify - ✅(Solved) Fix [Refactor/Chore] Standardize failed login audit logging [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langgenius/dify#35053Fetched 2026-04-14 05:56:45
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
1
Author
Participants
Assignees
Timeline (top)
referenced ×3assigned ×1closed ×1cross-referenced ×1

Add structured warning-level audit logs for failed console and web login flows and standardize the failure reasons behind those logs.

The change introduces a shared LoginFailureReason StrEnum for bounded reason codes and logs normalized email plus remote IP when login requests fail due to invalid credentials, account state, lockouts, or invalid email-code verification.

Root Cause

Add structured warning-level audit logs for failed console and web login flows and standardize the failure reasons behind those logs.

The change introduces a shared LoginFailureReason StrEnum for bounded reason codes and logs normalized email plus remote IP when login requests fail due to invalid credentials, account state, lockouts, or invalid email-code verification.

Fix Action

Fixed

PR fix notes

PR #35054: refactor(auth): standardize failed login audit logging

Description (problem / solution / changelog)

[!IMPORTANT]

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Fixes #35053.

  • add warning-level audit logs for failed console and web login paths
  • standardize failed-login reason codes with the shared LoginFailureReason enum
  • keep the log payload limited to normalized email, reason code, and remote IP

Screenshots

BeforeAfter
N/AN/A

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This does not apply to typos!)
  • Ive updated the documentation accordingly.

Changed files

  • api/controllers/console/auth/login.py (modified, +30/-1)
  • api/controllers/web/login.py (modified, +30/-3)
  • api/services/entities/auth_entities.py (modified, +16/-0)
  • api/tests/unit_tests/controllers/console/auth/test_login_logout.py (modified, +85/-25)
  • api/tests/unit_tests/controllers/web/test_web_login.py (modified, +96/-14)
RAW_BUFFERClick to expand / collapse

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for refactors or chores; if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Description

Add structured warning-level audit logs for failed console and web login flows and standardize the failure reasons behind those logs.

The change introduces a shared LoginFailureReason StrEnum for bounded reason codes and logs normalized email plus remote IP when login requests fail due to invalid credentials, account state, lockouts, or invalid email-code verification.

Motivation

Failed login attempts currently surface to clients but do not emit explicit auth-failure audit logs. That makes it harder to troubleshoot user-reported login failures even when centralized log collection is available.

This chore improves observability while keeping sensitive fields out of the logs and avoiding ad hoc reason strings.

Additional Context

  • Keep passwords, tokens, and verification codes out of the logs.
  • Use the same reason-code vocabulary across console and web login entry points.

extent analysis

TL;DR

Implement a standardized logging mechanism for failed login attempts using a shared LoginFailureReason enum to improve observability without exposing sensitive information.

Guidance

  • Introduce a LoginFailureReason StrEnum to standardize reason codes for failed login attempts, ensuring consistency across console and web login flows.
  • Log normalized email and remote IP addresses for failed login requests, excluding sensitive fields like passwords, tokens, and verification codes.
  • Ensure the logging mechanism is implemented for both console and web login entry points, using the same reason-code vocabulary.
  • Review existing login failure handling code to integrate the new logging mechanism, focusing on invalid credentials, account state, lockouts, and invalid email-code verification scenarios.

Example

from enum import StrEnum

class LoginFailureReason(StrEnum):
    INVALID_CREDENTIALS = "invalid_credentials"
    ACCOUNT_LOCKED = "account_locked"
    INVALID_EMAIL_CODE = "invalid_email_code"
    # Add other reason codes as needed

# Example logging implementation
def log_login_failure(reason: LoginFailureReason, email: str, remote_ip: str):
    # Log the failure reason, email, and remote IP, excluding sensitive information
    print(f"Login failure: {reason} - {email} - {remote_ip}")

Notes

This implementation assumes that the LoginFailureReason enum and logging mechanism will be integrated into the existing login failure handling code. The example provided is a simplified illustration and may require modifications to fit the specific use case.

Recommendation

Apply workaround by implementing the standardized logging mechanism using the LoginFailureReason enum, as it improves observability and consistency across login flows without exposing sensitive information.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

dify - ✅(Solved) Fix [Refactor/Chore] Standardize failed login audit logging [1 pull requests, 1 participants]