Skip to content

fix(student): limit verification codes to five a day per person - #88

Open
lorenzocorallo wants to merge 1 commit into
mainfrom
fix/student-verification-daily-cap
Open

lorenzocorallo wants to merge 1 commit into
mainfrom
fix/student-verification-daily-cap

Conversation

@lorenzocorallo

Copy link
Copy Markdown
Member

Before

To prove you are a student, you ask for a six-digit code at your @mail.polimi.it address. Each code allows 5 wrong guesses. The only limit on asking for codes was 60 seconds between requests. Each new code started again from 0 guesses.

Anyone can make an account with Google. So:

  • One account could try 5 guesses a minute, all day: 7,200 guesses a day out of 1,000,000 codes. That is about 0.7% a day, for any address, even one that does not exist. With 100 accounts, one of them would likely get the student state within a day.
  • One account could make us send 1,440 emails a day to Polimi addresses it picks.

Now

One person can ask for at most 5 codes in any 24 hours. The sixth gets a 429 with "You asked for too many codes. Try again tomorrow." and no email is sent. That is 25 guesses a day (0.0025%) and 5 emails a day per account.

  • The count is kept in a new table, student_verification_send, with one row per code. It is not on the challenge row, so a new code, a confirmation, a failed email, or another account asking for the same address does not reset it.
  • A code whose email fails still counts.
  • The check runs in the same locked transaction as the 60-second check, so parallel requests cannot go over the limit.
  • Rows older than 24 hours are deleted in that same transaction. Rows are deleted with the user (on delete cascade).
  • There is no limit per address, so a stranger cannot lock a student out of their own address.
  • The 60-second wait, the 5 guesses per code and everything else stay the same.

This adds migration 0025_student_verification_daily_limit (made with vp run db:generate). The audit doc now mentions the daily limit.

Tests

New tests in src/auth/student-verification.integration.test.mjs:

  • the sixth code in 24 hours is refused and nothing is sent; codes work again after 24 hours
  • the count is not reset by a successful confirmation, by failed emails, or by another account asking for the same address
  • parallel requests do not go over 5
  • deleting the user removes their rows

Run against a fresh PostgreSQL 18 in Docker:

  • vp check: pass
  • vp test: pass
  • the student, RBAC security, user deletion and user directory PostgreSQL suites: 58 passed (run one file at a time; run in parallel, one user directory test fails because the files share the database, and it passes alone)
  • the migration applies on a fresh database with both vp run db:migrate and scripts/migrate.mjs, and db:generate afterwards finds no changes

Note: the commit is not signed, because the 1Password signing agent refused in this session.

Each new code reset the five-guess limit and only a 60-second cooldown applied,
so one account could guess about 7,200 codes and send 1,440 emails a day.
Count sent codes per person in a new table and refuse a sixth within 24 hours.
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Student verification requests now have a per-user limit of five sends in a rolling 24-hour window. The change adds send-record storage, rejects requests at the limit, and adds integration tests and audit documentation.

Changes

Student verification send limit

Layer / File(s) Summary
Send record storage
src/db/evidence.ts, drizzle/0025_student_verification_daily_limit.sql, drizzle/meta/_journal.json
A new table stores each verification send with its user and timestamp. The migration adds a cascading user reference and an index on user ID and send time.
Daily limit enforcement and validation
src/auth/student-verification.ts, src/auth/student-verification.integration.test.mjs, docs/rate-limit-audit.md
Requests remove records at or before the 24-hour cutoff, count the user’s remaining records, and return status 429 when the count is at least five. Integration tests cover limit behavior, and the audit documents the limit and what does not reset its count.

Change: Bug fix

Merge Risk: Minimal · up to a0088

This change limits student verification codes to five per person per 24 hours and adds the supporting table and migration. No concrete defect was found, so merge risk is minimal.

Pre-merge checks: Passed 3

Check name Status Explanation
Title check Passed The title names the main change: a per-person limit of five student verification codes per day. The raw summary confirms a rolling 24-hour, five-send limit in requestStudentVerification, backed by a n…
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.
Full details: Title check

Explanation

The title names the main change: a per-person limit of five student verification codes per day. The raw summary confirms a rolling 24-hour, five-send limit in requestStudentVerification, backed by a new student_verification_send table and migration 0025. The title is specific, concise, and follows the conventional commit style.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9fe232e and a008886.

Files ignored due to path filters: 1

  • drizzle/meta/0025_snapshot.json is excluded by !drizzle/meta/*_snapshot.json
Files selected for processing: 6

  • docs/rate-limit-audit.md
  • drizzle/0025_student_verification_daily_limit.sql
  • drizzle/meta/_journal.json
  • src/auth/student-verification.integration.test.mjs
  • src/auth/student-verification.ts
  • src/db/evidence.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant