Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

fix: added logout user before sso pipeline starts#2

Merged
robrap merged 18 commits intoedx:masterfrom
Akanshu-2u:akanshu/test-auth-pipeline
Sep 22, 2025
Merged

fix: added logout user before sso pipeline starts#2
robrap merged 18 commits intoedx:masterfrom
Akanshu-2u:akanshu/test-auth-pipeline

Conversation

@Akanshu-2u
Copy link

@Akanshu-2u Akanshu-2u commented Sep 10, 2025

Description:

Users logging in through OAuth SSO could retain session data from previous logins, creating potential security risks and confusion when switching between accounts.

Solution:

Added logout(request) call in EdXOAuth2.start() method to clear existing sessions before OAuth authentication begins.

JIRA:

BOMS-3

@Akanshu-2u Akanshu-2u requested a review from robrap September 10, 2025 13:05
Copy link

@robrap robrap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I added questions for follow-up.

@Akanshu-2u Akanshu-2u requested a review from robrap September 12, 2025 19:52
Copy link

@robrap robrap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Akanshu-2u. I found all this very helpful. Why don't you proceed with some unit tests and a temporary rollout toggle. You can add observability for the state of the toggle and for when the user is logged out.

@Akanshu-2u Akanshu-2u force-pushed the akanshu/test-auth-pipeline branch from fd1aa99 to 2968468 Compare September 15, 2025 13:09
Copy link

@jcapphelix jcapphelix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Akanshu-2u I've given few changes.

@jcapphelix jcapphelix marked this pull request as ready for review September 18, 2025 12:15
@jcapphelix
Copy link

This can go for further approvals.

@Akanshu-2u Akanshu-2u requested a review from robrap September 18, 2025 12:17
@robrap robrap changed the title [Do not merge] fix: added logout user before sso pipeline starts fix: added logout user before sso pipeline starts Sep 18, 2025
Copy link

@robrap robrap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'm looking forward to getting this more comprehensive fix out.

Co-authored-by: Robert Raposa <rraposa@gmail.com>
Copilot AI review requested due to automatic review settings September 19, 2025 07:08
Akanshu-2u and others added 3 commits September 19, 2025 12:39
Co-authored-by: Robert Raposa <rraposa@gmail.com>
Co-authored-by: Robert Raposa <rraposa@gmail.com>
Co-authored-by: Robert Raposa <rraposa@gmail.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Introduces a session cleanup step before initiating a new OAuth2 flow to avoid user association conflicts by logging out any currently authenticated user, guarded by a new feature toggle and enhanced observability.

  • Adds ENABLE_OAUTH_SESSION_CLEANUP toggle plus monitoring/logging in start()
  • Implements comprehensive tests for start() behavior across toggle and request/user states
  • Updates test dependency versions (one version pin appears potentially invalid)

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
requirements/test.txt Bumps multiple dependency versions (one questionable version pin: cffi==2.0.0).
auth_backends/backends.py Adds toggle, logging, and session cleanup logic to OAuth start() with observability attributes.
auth_backends/tests/test_backends.py Adds parametrized tests covering authenticated/unauthenticated, missing request, and request without user paths.
CHANGELOG.rst Reclassifies a patch release section to Added with new feature notes (potential semver concern).

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Robert Raposa <rraposa@gmail.com>
Copilot AI review requested due to automatic review settings September 19, 2025 07:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Robert Raposa <rraposa@gmail.com>
Copilot AI review requested due to automatic review settings September 19, 2025 07:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Robert Raposa <rraposa@gmail.com>
Copilot AI review requested due to automatic review settings September 19, 2025 07:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

auth_backends/backends.py:1

  • Custom attribute keys used in set_custom_attribute do not match the documented custom_attribute_name comments or the expectations in the new tests (which assert calls like 'start.session_cleanup_toggle_enabled', 'start.user_authenticated_before_cleanup', and 'start.session_cleanup_performed'). This mismatch will cause the tests to fail and leads to inconsistent monitoring data. Align the keys by changing 'session_cleanup.toggle_enabled' -> 'start.session_cleanup_toggle_enabled', 'session_cleanup.logout_required' -> 'start.user_authenticated_before_cleanup', and 'session_cleanup.logout_performed' -> 'start.session_cleanup_performed'.
"""Django authentication backends.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@robrap
Copy link

robrap commented Sep 19, 2025

@Akanshu-2u: Also, can you please update the PR description in general, and also add a link to our private jira ticket (and a link in the ticket to this PR, if that doesn't exist). Thanks.

Copilot AI review requested due to automatic review settings September 22, 2025 07:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

@jcapphelix jcapphelix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All my comments are addressed.

PR description and JIRA links to be added, post that, it can be sent for re-review.

@Akanshu-2u Akanshu-2u requested a review from robrap September 22, 2025 09:00
@Akanshu-2u
Copy link
Author

@Akanshu-2u: Also, can you please update the PR description in general, and also add a link to our private jira ticket (and a link in the ticket to this PR, if that doesn't exist). Thanks.

Addressed.

Copy link

@robrap robrap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor fixes that I will commit and then squash and merge.

Copilot AI review requested due to automatic review settings September 22, 2025 19:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


user_authenticated = (
request is not None and
hasattr(request, 'user') and
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hasattr(request, 'user') check is unnecessary and potentially misleading. Django's request objects always have a user attribute (either an authenticated user or AnonymousUser). This check should be removed as it adds no value and could mask real issues.

Suggested change
hasattr(request, 'user') and

Copilot uses AI. Check for mistakes.
set_custom_attribute('session_cleanup.logout_required', user_authenticated)

if user_authenticated and ENABLE_OAUTH_SESSION_CLEANUP.is_enabled():
existing_username = getattr(request.user, 'username', 'unknown')
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using getattr with a default value of 'unknown' is inappropriate here. Since we've already verified request.user.is_authenticated is True, the user object is guaranteed to have a username attribute. This should be simplified to request.user.username to avoid logging misleading 'unknown' values.

Suggested change
existing_username = getattr(request.user, 'username', 'unknown')
existing_username = request.user.username

Copilot uses AI. Check for mistakes.
@robrap robrap merged commit 7c1791e into edx:master Sep 22, 2025
9 checks passed
@robrap robrap deleted the akanshu/test-auth-pipeline branch September 22, 2025 19:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants