Skip to content

fix(email): verify mailbox identity on OAuth reconnect#5648

Merged
o3LL merged 1 commit into
odysseus-dev:devfrom
RaresKeY:fix/email-oauth-reconnect-identity
Jul 22, 2026
Merged

fix(email): verify mailbox identity on OAuth reconnect#5648
o3LL merged 1 commit into
odysseus-dev:devfrom
RaresKeY:fix/email-oauth-reconnect-identity

Conversation

@RaresKeY

@RaresKeY RaresKeY commented Jul 20, 2026

Copy link
Copy Markdown
Member

Summary

Keep Google OAuth reconnects bound to the mailbox already configured on the saved account. The callback now requires a verified user-info email, compares it case-insensitively with every populated IMAP/SMTP login, and refuses to replace credentials when the identities differ.

A successful reconnect also requires and replaces both the access token and the offline refresh token as one pair. Existing tokens remain untouched when identity verification fails or Google omits a fresh refresh token.

Target branch

  • This PR targets dev, not main.

Linked Issue

Fixes #5638

Part of #5637

Type of Change

  • Bug fix (non-breaking — fixes a confirmed issue)
  • New feature (non-breaking — adds new behaviour)
  • Breaking change (changes or removes existing behaviour)
  • Refactor / cleanup (behaviour unchanged)
  • Documentation only
  • CI / tooling / configuration

Checklist

  • I searched open issues and open PRs — adjacent OAuth work exists, but none owns this reconnect identity contract.
  • This PR targets dev.
  • My changes are limited to callback identity/credential replacement and focused regressions.
  • I ran the app end-to-end. No disposable Google account was available; route-level and adjacent email tests were run in an isolated environment with mocked provider/network I/O instead.

How to Test

  1. Run the OAuth and adjacent email suites:

    python -m pytest -q tests/test_email_oauth.py tests/test_email_owner_scope.py tests/test_email_imap_timeout.py tests/test_email_smtp_security.py tests/test_imap_leak_fixes.py
  2. Reconnect a saved Google account with the same mailbox and verify the callback succeeds and replaces both credentials.

  3. Attempt to reconnect it with a different Google identity and verify the callback reports identity verification failure without changing the saved credentials.

  4. Return an access token without a fresh refresh token and verify the existing credential pair remains unchanged.

Current-dev isolated validation passes 150 adjacent tests. Python compilation and diff checks pass. Live Google validation remains a reviewer item.

Visual / UI changes

N/A — callback validation and tests only; no UI rendering changed.

Screenshots / clips

N/A — no visual changes.

@github-actions github-actions Bot added the ready for review Description complete — ready for maintainer review label Jul 20, 2026
@RaresKeY
RaresKeY marked this pull request as ready for review July 21, 2026 12:20
@RaresKeY RaresKeY added the bug Something isn't working label Jul 21, 2026

@o3LL o3LL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, I would suggest adding a new test but it could be done later, PR is in a good state already.

The identity gate now also runs on first-time connects. For a fresh account with empty imap_user/smtp_user, configured_logins is empty, so the gate reduces to "userinfo email must be present" and auto-fill proceeds correct. But no test covers this path: the test helper _make_account defaults both logins to test@example.com, so every callback test exercises a populated row. If someone later tightens any(login != verified_email ...) into a positive match requirement, first-connect breaks with no test catching it. One test with fresh account, successful userinfo, assert tokens stored and imap_user/smtp_user auto-filled would lock in the empty-set semantics.

@o3LL
o3LL merged commit 808e9c8 into odysseus-dev:dev Jul 22, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready for review Description complete — ready for maintainer review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

email: verify mailbox identity during OAuth reconnect

2 participants