fix(auth): enforce issuer + validate sign-in tokens + test the session guards#57
Merged
Conversation
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.
Summary
Quality/security audit fixes for the Google auth flow in
lib/auth-context.js+lib/env.js, with behavioral tests that fail if any bug is reintroduced.Fixes
isSessionStillValid): the issuer check wasif (claims.iss && !ALLOWED_ISSUERS.has(claims.iss))— a falsy/missingissshort-circuited the check, so a token minted with no issuer was honoured. Nowif (!claims.iss || !ALLOWED_ISSUERS.has(claims.iss)) return falserequires a present, allow-listed issuer.{user:null}session persistence (handleAuthResult): asuccesswith no decodableid_tokenused to write a{user:null}blob to SecureStore. Now it throws (caller maps tosetError) and skips the write entirely.handleAuthResult): live sign-in now runs the sameisSessionStillValidgate used on restore, so a session can no longer be "valid enough to log in but purged next launch". Expired / foreign-issuer tokens are rejected at sign-in.assertGoogleEnvreachability (lib/env.js): env was read once at module load, making the missing-WEB-client throw untestable. Reads are now lazy + injectable (assertGoogleEnv(env),readGoogleClientIds(env)); on-device behaviour is unchanged because Expo still inlinesEXPO_PUBLIC_*.waitFor) sojest --coverageis stable.Tests
isSessionStillValidunit tests: valid, expired exp, non-numeric exp, missing iss, empty iss, foreign iss, undecodable token.handleAuthResultguards: no-token / garbage-token / expired / foreign-issuer all throw and write nothing.assertGoogleEnv/readGoogleClientIdsenv tests (missing-WEB throw now reachable).34/34 tests pass (was 20). Coverage: statements 88.23, branches 77.5, functions 83.33, lines 89.01 — all above thresholds (75/55/70/80). Lint clean. Coverage run stable across 5 consecutive runs.