fix(security): flag logins that lose country attestation#1718
Merged
Conversation
A login-risk assessment early-returned NULL_RISK whenever the current login carried no country attestation, so a change from a known country to an unplaceable location never raised the member-session red flag while a change to a different known country did. Treat a null country as an anomaly (unknown_country) when the user has an established country history, mirroring new_country. A null country with no prior history stays inconclusive so local-dev and self-hosted logins are not tripped. Persist the risk blob whenever there is a country or an anomaly so the unknown_country verdict reaches the member-sessions panel.
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.
Problem
An org owner reviewing a member's recent sessions sees a red flag when the member's country changes from one known country to another (
AU -> KR), but a change from a known country to an unplaceable location (no country attested) raised no flag at all. Both should be treated the same way.Root cause
The red flag is computed at login in
assessLoginRiskand stored insessions.risk_flags_json; the member-sessions panel only renders what was stored. That function returned early with a no-anomaly signal whenever the login carried no country attestation, before comparing against the user's prior countries. A second guard in the session-create hook only persisted the risk blob when a country was present, so even a computed anomaly with a null country would have been dropped.Fix
unknown_countryanomaly when the user has an established country history, mirroring the existingnew_countrypath. A null country with no prior history stays inconclusive, so local-dev and self-hosted logins are not tripped.unknown_countryverdict reaches the panel.unknown_country -> "Unknown location"badge label.Impossible-travel detection now also runs on the null-country path (previously skipped by the early return), a strict improvement since IP-fallback coordinates can still be present.
Tests
pnpm vitest run tests/unit/login-risk.test.ts-- 17 passed. Updated the "no country" cases to assert they stay inconclusive only without history, and added coverage forunknown_countryfiring with prior history (CFXXsentinel and full CF bypass).pnpm type-check-- clean.