Skip to content

fix(auth): harden MFA and session lifecycle - #284

Open
NeerajCodz wants to merge 4 commits into
mainfrom
fix/auth-security-issues
Open

NeerajCodz wants to merge 4 commits into
mainfrom
fix/auth-security-issues

Conversation

@NeerajCodz

@NeerajCodz NeerajCodz commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Changes

  • Harden session security, authentication challenges, TOTP enrollment, and recovery flows.

Issues

Fixes #264
Fixes #265
Fixes #266
Fixes #273
Fixes #274
Fixes #275
Fixes #276
Fixes #277
Fixes #278

@vercel

vercel Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
finapp Ready Ready Preview Nov 27, 2026 2:54am UTC

@NeerajCodz

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-27T02:36:21.888930Z
We couldn’t complete this review. Comment @codex review to try again.
557dbe0 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 8655f216c3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- Correct MFA challenge, enrollment, recovery, and session-security handling.
- Fixes #264, #265, #266, #273, #274, #276, #277, and #278.
@NeerajCodz NeerajCodz changed the title fix(security): add full quiet zone to TOTP QR codes fix(auth): harden MFA and session lifecycle Nov 27, 2026
@NeerajCodz

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aafdb1e6eb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread convex/users/queries.ts Outdated
.filter((q) =>
q.and(q.neq(q.field('_id'), current._id), q.eq(q.field('deletedAt'), undefined)),
)
.paginate({ numItems: GROUP_PROFILE_SEARCH_PAGE_SIZE, cursor });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Replace the repeated paginated scan

When more than 50 matching users must be inspected before finding 20 discoverable profiles, this loop invokes .paginate() a second time and the production query throws instead of returning suggestions. Convex permits only one paginated call per query; its pagination documentation explicitly notes that the second call raises an exception, so this scan needs a non-paginated bounded approach or separate query invocations.

Useful? React with 👍 / 👎.

Comment on lines +172 to +175
next === 'active' &&
userId &&
backgroundAt.current !== null
) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear the background timestamp while signed out

If the app is backgrounded and restored while userId is null, this condition skips the only statement that clears backgroundAt. After the user signs in, a later inactive → active transition—such as opening and dismissing a system overlay—uses that stale pre-sign-in timestamp and can immediately relock the returning user's app or invalidate an in-flight device unlock. Clear the timestamp whenever the app becomes active, while applying the timeout only when a user is present.

Useful? React with 👍 / 👎.

Comment thread convex/auth.ts
Comment on lines 110 to 112
await sendTwoFactorEmail(email, code);
} catch (error) {
await ctx.runMutation(internal.authEmailChallenges.revoke, { challengeIdHash });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep TOTP sign-in independent of email delivery

When the email provider is unavailable, this awaited fallback send throws and the catch revokes the challenge before a TOTP-enabled user receives its ID. The previous TOTP path created a challenge without sending email, so this change makes authenticator and recovery-code sign-in unavailable during any email outage even though neither method needs email; for accounts with those factors, keep the fallback send best-effort or still return a usable challenge when delivery fails.

Useful? React with 👍 / 👎.

Comment thread convex/security.ts
Comment on lines +186 to +190
.query('sessionDevices')
.withIndex('by_user', (q) => q.eq('userId', user._id))
.filter((q) => q.neq(q.field('sessionId'), sessionId))
.first();
if (priorDevice && (await privacyFor(ctx, user._id)).signInAlerts)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fall back to active sessions for sign-in alerts

When another valid session has not yet created a sessionDevices row—such as an older client or a client whose best-effort touchSession call failed—priorDevice is null and this new sign-in produces no security alert. The client hooks swallow touch failures, and mobile does not retry, whereas the replaced authSessions predicate detected this case; retain the historical-device check but also treat another active session as prior account use.

Useful? React with 👍 / 👎.

['Pixel 8', 'android', false],
]);
const alerts = await t.run((ctx) => ctx.db.query('notifications').collect());
expect(alerts.map((row) => [row.type, row.title])).toEqual([

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restore the missing alerts lookup in the device test

This test now references alerts without declaring it because the query that initialized the variable was removed. Whenever test:web reaches this case, Vitest throws ReferenceError: alerts is not defined before evaluating the updated expectations, so the test suite cannot pass.

Useful? React with 👍 / 👎.

- Bound username-search candidates while retaining privacy filtering.
- Restore the notification fixture used by the security assertion.
@NeerajCodz

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

- Query the fixture notifications using the seeded user id.

This branch was successfully deployed

1 active deployment
Preview — 362b940d Deployed Nov 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment