Skip to content

ref(auth): Apply consistent email matching in user service and SSO verification - #127401

Merged
markatsentry merged 1 commit into
masterfrom
mark/auth-email-matching-followup
Oct 14, 2026
Merged

markatsentry merged 1 commit into
masterfrom
mark/auth-email-matching-followup

Conversation

@markatsentry

@markatsentry markatsentry commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

stricter email checking from login sources

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 14, 2026
@markatsentry
markatsentry force-pushed the mark/auth-email-matching-followup branch 4 times, most recently from 90dd24e to 232cafb Compare October 14, 2026 18:00
@markatsentry
markatsentry marked this pull request as ready for review October 14, 2026 18:44
@markatsentry
markatsentry requested review from a team as code owners October 14, 2026 18:44
…rification

Follow-up to #127388. Use the same ASCII-only email comparison in the
remaining user service lookups and tighten the SSO account confirmation
check to the issuing identity.
@markatsentry
markatsentry force-pushed the mark/auth-email-matching-followup branch from 232cafb to d84a047 Compare October 14, 2026 19:56
@markatsentry
markatsentry enabled auto-merge (squash) October 14, 2026 20:06
@markatsentry
markatsentry merged commit e9e09a5 into master Oct 14, 2026
88 checks passed
@markatsentry
markatsentry deleted the mark/auth-email-matching-followup branch October 14, 2026 20:12
adrianviquez pushed a commit that referenced this pull request Oct 14, 2026
…rification (#127401)

stricter email checking from login sources
joshuarli pushed a commit to joshuarli/sentry that referenced this pull request Oct 27, 2026
…ails (getsentry#128720)

Two email comparisons still used Python's Unicode-aware lowercasing.
Unicode case mapping can turn some non-ASCII characters into ASCII ones
(for example, U+212A lowercases to "k"), so a look-alike address could
be treated as an existing one.

- `AuthIdentityHandler._email_verified_via_pending_invite` compared the
SSO identity email to the invited email with `.lower()`. It now uses
`emails_match`, the ASCII-only helper from getsentry#127401.
- `RegistrationValidator.validate_email` returned `value.lower()`, so a
look-alike address was saved as the ASCII address it resembles. It now
returns `ascii_casefold(value)`, which lowercases only A-Z.

The duplicate-account check in `validate_email` intentionally keeps
`iexact`. Postgres `UPPER` matches some look-alikes (for example, "ı" to
"I"), and for a uniqueness check, over-matching is the safe direction:
it refuses to create a look-alike twin of an existing account.
BYK added a commit that referenced this pull request Oct 28, 2026
…9114)

Follow-up to #128458, from [this review
thread](#128458 (comment)).

The device-flow `login_hint` check compared the hint to the signed-in
user's primary email with `str.casefold()`. Unicode case folding maps
some non-ASCII characters onto ASCII. For example, U+212A KELVIN SIGN
folds to `k`. So a hint for one address could be approved by an account
whose email only looks like it.

This switches the check to `sentry.auth.email.emails_match`. That helper
folds ASCII A–Z only, and it's what the other auth email comparisons
moved to in #127401 and #128720.

- `ensure_expected_account` in `oauth_device.py` now calls
`emails_match` directly. It was the only caller of
`ApiDeviceCode.accepts_user_email`, so I removed that method. The model
module can't import `sentry.auth.email` without a cycle, because that
module imports `User`, `Organization` and org services.
- `test_login_hint_rejects_unicode_lookalike` covers the case. It fails
on the old code, which returns 200, and passes with this change, which
returns 403. The existing ASCII case-insensitivity test still passes.

**Verification:** `test_oauth_device.py` and
`test_oauth_device_authorization.py` pass (40 tests). prek and mypy pass
on the changed files.

<!-- junior-request-attribution:start -->
via **BYK**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:local%3Aweb%3A7f8efa11623b9416987ceb44 -->

--

[View Junior Session in
Sentry](https://sentry.sentry.io/explore/conversations/local%3Aweb%3A7f8efa11623b9416987ceb44/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: BYK <burak.kaya@sentry.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants