You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
No actionable comments were generated in the recent review.
Walkthrough
The change adds authentication audit events for password and 2FA outcomes, SSO, OAuth application login and logout, account lockouts, user logout, password changes, and 2FA setting changes. Receivers create audit records for each organisation associated with a user. Authentication workflows emit the corresponding signals. OAuth token revocation uses a custom view that emits a signal after confirming that a refresh token was revoked. Integration tests and audit-log documentation cover the events.
Authentication audit logging is mostly in place. Several gaps remain: lockout and incorrect-password events can be missed for LDAP username logins, access-token revocation records no logout, and a null failure count in the lockout receiver can raise an error. The declared OAuth toolkit minimum also admits a version that would break token revocation. These should be addressed or explicitly accepted before merging.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
The axes lockouts, and login attempts under lockout, are not logged. Should they?
It's a bit of scope explosion, but I don't mind: 284a40c + 756750d.
Users with no org leave no trace anywhere. Should they?
No. The interested party in seeing organisation audit logs is an organisation.
CLI and MCP logins aren't logged at all. Neither flagsmith login, the MCP OAuth consent and token exchange, flagsmith logout, nor revoking a token creates a log.
I've added c79ea8a and b0c99b6 which should cover authentication via OAuth.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Data Integrity & Integration · Quick win
Resolve lockout users through the configured login field.
When LDAP is enabled, FFAdminUser.USERNAME_FIELD is username. Axes uses that field by default. For username alice and email alice@example.com, this lookup searches for email alice and returns without creating any lockout audit records. Both lockout event types are lost for this user. (raw.githubusercontent.com)
Resolve the user through the configured login field instead of always using email.
#!/bin/bashprintf'%s\n''--- Relevant test outline ---'
ast-grep outline api/tests/unit/custom_auth/test_unit_custom_auth_serializer.py --match 'djoser|username' --view expanded
printf'%s\n''--- Djoser login-field test ---'
cat -n api/tests/unit/custom_auth/test_unit_custom_auth_serializer.py | sed -n '165,250p'printf'%s\n''--- Authentication configuration ---'
rg -n -C 4 'LOGIN_FIELD|AXES_USERNAME|AXES_FAILURE|AUTHENTICATION_BACKENDS|LDAP_ENABLED' api -g '*.py'printf'%s\n''--- Dependency versions ---'
rg -n -i -C 2 'django-axes|djoser' api -g '*lock*' -g '*toml' -g '*requirements*' -g '*txt'| head -180
Length of output: 17618
@khvn26 The serializer has the same email-only lookup. The LDAP serializer test also shows that the email input can contain a username. Both paths should handle a username that differs from the user’s email.
I could not read the private comment: GitHub returned 404. Could you share its text here? I’m not marking this finding as addressed because no fix has been confirmed.
The reason will be displayed to describe this comment to others. Learn more.
Major · Data Integrity & Integration · Quick win
Use the authentication identity for rejection audits.
When LDAP is enabled, Djoser authenticates the supplied login value through User.USERNAME_FIELD, which is username. For username alice and email alice@example.com, an incorrect password reaches this lookup with alice. The email lookup finds no user, so validation re-raises without sending user_login_password_rejected. The required audit records are missing from every organisation of that user. (raw.githubusercontent.com)
Resolve the user through the configured authentication identity rather than always through email.
The reason will be displayed to describe this comment to others. Learn more.
Major · Data Integrity & Integration · Quick win
Record logout when an access token revokes its session.
If a client submits an access token, this lookup searches for its checksum among refresh tokens and returns None. The locked django-oauth-toolkit 3.4.1 implementation also revokes the bound refresh token when it revokes that access token. The session ends, but Line 233 suppresses the logout audit record. Resolve the bound refresh token before delegation and cover this input alongside the existing refresh-token test. (raw.githubusercontent.com)
The reason will be displayed to describe this comment to others. Learn more.
Major · Stability & Availability · Quick win
Raise the django-oauth-toolkit minimum to 3.4.0.
The declared range admits 3.0.1. That version's RefreshToken model has no token_checksum field; the field was added in 3.4.0. OAuthRevokeTokenView._get_session_refresh_token filters on that field before the base revocation runs. An installation that resolves 3.0.1 therefore fails every revocation request with a FieldError, and no token is revoked. The lock file pins 3.4.1, but it protects only installations that use it, so the declared minimum must exclude 3.0.1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiIssue related to the REST APIdocsDocumentation updatesfeatureNew feature or request
4 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for submitting a PR! Please check the boxes below:
docs/if required so people know about the feature.Changes
Closes #7569
Introduces audit logging for authentication events.
We expand further from the original scope, and also add audit logs for:
Review effort: 4/5
How did you test this code?
Functional tests.