Repository navigation
fix(oauth): Match device login_hint with ASCII-only case folding - #129114
Merged
Merged
Conversation
The login_hint check compared emails with str.casefold(), which maps some non-ASCII characters onto ASCII (U+212A KELVIN SIGN folds to "k"). A hint for one address could then be approved by a look-alike account. Use emails_match, the ASCII-only helper the other auth email comparisons switched to in #127401 and #128720. Co-Authored-By: BYK <[email protected]>
BYK
approved these changes
Oct 28, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up to #128458, from this review thread.
The device-flow
login_hintcheck compared the hint to the signed-in user's primary email withstr.casefold(). Unicode case folding maps some non-ASCII characters onto ASCII. For example, U+212A KELVIN SIGN folds tok. 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_accountinoauth_device.pynow callsemails_matchdirectly. It was the only caller ofApiDeviceCode.accepts_user_email, so I removed that method. The model module can't importsentry.auth.emailwithout a cycle, because that module importsUser,Organizationand org services.test_login_hint_rejects_unicode_lookalikecovers 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.pyandtest_oauth_device_authorization.pypass (40 tests). prek and mypy pass on the changed files.via BYK.
--
View Junior Session in Sentry