Skip to content

fix: scope email verification code to the user session#255

Merged
DogukanUrker merged 1 commit into
DogukanUrker:mainfrom
GoodVaibhs:fix/verify-user-session-code
Jun 20, 2026
Merged

fix: scope email verification code to the user session#255
DogukanUrker merged 1 commit into
DogukanUrker:mainfrom
GoodVaibhs:fix/verify-user-session-code

Conversation

@GoodVaibhs

@GoodVaibhs GoodVaibhs commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

The verification code generated in verify_user() was stored in a module-level global variable, so it was shared across every visitor's request. If two users requested a verification email around the same time, the second request's code silently overwrote the first's, making the first user's code invalid before they could use it.

Store the code in the user's own session instead, consistent with how this route already tracks per-user state (session['username'], session['language']). The generated code is now saved to session['verification_code'] right after it is created, and the submitted code is compared against session.get('verification_code') instead of the old global variable.

Summary by CodeRabbit

  • Refactor
    • Improved reliability and security of the account verification process.

The verification code generated in verify_user() was stored in a module-level global variable, so it was shared across every visitor's request. If two users requested a verification email around the same time, the second request's code silently overwrote the first's, making the first user's code invalid before they could use it.

Store the code in the user's own session instead, consistent with how this route already tracks per-user state (session['username'], session['language']).
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9db992af-5faf-4e34-a085-b6aee7f56d45

📥 Commits

Reviewing files that changed from the base of the PR and between fe7a05a and 409b7e8.

📒 Files selected for processing (1)
  • app/routes/verify_user.py

📝 Walkthrough

Walkthrough

In app/routes/verify_user.py, the verification code is now stored in and retrieved from the Flask session (session["verification_code"]) instead of a module-level global variable, covering both the code-generation path (before sending the email) and the code-validation path (when the user submits the code).

Changes

Verification Code Session Storage

Layer / File(s) Summary
Verification code read/write via session
app/routes/verify_user.py
On email send, the generated code is now assigned to session["verification_code"]. On POST submission, the submitted code is compared against session.get("verification_code") instead of a global variable.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 A global once roamed, shared and free,
Now tucked in the session, safe as can be.
Each browser its own little code to keep,
No tangled state, no leaky heap.
The rabbit hops on — no globals today! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug and solution clearly, but does not follow the required template structure with 'Fixes #' and 'Proposed Changes' sections. Add the required template sections: include a 'Fixes #' issue reference and a 'Proposed Changes' bullet-point list summarizing the modifications.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: moving email verification code storage from a module-level variable to user session scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@DogukanUrker DogukanUrker self-requested a review June 20, 2026 06:30

@DogukanUrker DogukanUrker left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

lgtm

@DogukanUrker DogukanUrker merged commit 41b4251 into DogukanUrker:main Jun 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants