[PR #220·221] Server Security Review Fixes: Login Lockouts Anyone Could Trigger, and a Daily Photo Limit
These two PRs fix items 4 and 8 from the server security review (parts 1 and 2) of 2026-11-12. PR 220 fixes item 4 (anyone could keep a customer’s phone-number login locked), and PR 221 fixes item 8 (photo uploads had no daily limit). They are separate findings, so I put them side by side in one post.
Both ran on my Windows computer. A Claude Code session (Claude Fable 5.2) read the code, laid out the options, wrote the work instructions, implemented, checked and opened the PR, and Codex (gpt-6.1-terra) wrote the tests. The implementation side did not edit the test files. The final review was codex exec review (Codex’s default model, name unknown). This post has no real passwords or tokens; it only describes file and function names and behavior.
PR 220: Devices That Have Logged In Skip the Number Lockout
What was wrong
Wrong-password attempts were counted by phone number alone. Someone who knew only a customer’s number could keep sending wrong passwords and keep that customer’s phone login locked for 15 minutes at a time.
What changed
A device that has logged in to that account with number and password before skips the number-wide wait. It gets its own counter (the same 5 tries → 1 minute → up to 15 minutes). An unknown device still shares the one number-wide counter, as before.
- The device value (
X-Device-Id, a random value the app creates at install) is not stored as is. Only a hash (a fingerprint that hides the original, SHA-256) goes intosessions.device_hash. - The counter table
login_throttlesis now keyed by “number + device fingerprint”. The row with an empty fingerprint is the number-wide counter. - A “device that has logged in” counts only through sessions that are not ended, or ended by the user’s own logout. Sessions ended by password recovery, an admin ending logins, a number change, suspension, refresh-key reuse or account deletion do not count.
- The database structure changes (migration 0005). The customer app and admin web do not change.
Chosen approach and rejected options
Claude laid out three options and I picked option C.
- Rejected: leave it (
option A). Customers who have not linked Kakao or Apple have no way to log in again while under attack. - Rejected: count by number + device only (the option Claude first recommended). The sender can change the device value, so changing it every time allows endless tries without waiting. Claude read the code and withdrew that recommendation.
- Rejected: count by number + device and add a separate number-wide cap (
option B). Changing the device value and sending up to the cap locks the account the same way. - No new table. I added one column to
sessionsand one tologin_throttles. “Devices that have logged in” is found from session rows instead of being stored separately, so existing code that ends sessions (recovery, admin end, and so on) needs no change for a device to be forgotten. - Kakao and Apple logins do not remember devices. Adding that means more places to change, so it was left out this time.
PR 221: At Most 300 Photos per User in 24 Hours
What was wrong
A logged-in customer could upload up to 30 photos a minute, with no daily or overall limit. One account (or a stolen session) could upload up to 43,200 photos a day and fill the server storage.
What changed
If a user has uploaded 300 photos in the last 24 hours, the next photo is refused.
- Before uploading, the server counts rows in the photo table (
photos) by uploader and upload time. It counts all modules together, and both photos attached to a record and photos not yet attached. - Over the limit, it answers 429
photo_daily_limitand creates neither a row nor a file. - The app shows under that photo: “You’ve reached the daily photo limit. Please try again tomorrow.” The screen layout does not change; it reuses the existing failure display.
- The number 300 is one line,
PHOTO_DAILY_LIMITinpackages/shared/src/policy.ts. - The database structure does not change, and neither does the admin web.
Chosen approach and rejected options
Claude laid out the options, and I picked option A with 300 photos. The numbers behind it:
- An honest heavy day is about 135 photos (3 pilot modules × 3 record types × 5 photos × 3 times a day, all by one person). I could not find the daily record count in the documents, so “3 times” is an assumption.
- Abused today: 43,200 photos a day. At roughly 5MB each, that is about 216GB a day. I have not measured a photo’s size (the original is re-saved at quality 95 and one more display copy is made).
- At 300 photos: about 1.5GB a day per account.
Rejected:
- A limit on photos not attached to a record (
option B): attaching the photo to a record avoids the limit, and honest customers who add and remove photos could get caught. - Leave it until the next detailed task (
option C): not a wrong choice, but one lookup can block it, so it went in now. - Per-module totals: honest modules keep growing photos and would eventually hit them.
- Lowering the per-minute limit: even 10 a minute is 14,400 a day, and only customers who pick 5 photos at once are inconvenienced.
- A new table of counts: photo rows are only deleted by the 7-day cleanup, so counting the photo table alone is accurate for the last 24 hours.
- An index (a list that speeds up lookups): it is a database structure change, so it was not added. It is not needed at pilot scale.
Failure cases
| What can break | What the system does | What the user sees | Test |
|---|---|---|---|
| The 301st photo | Only that photo is refused with 429; no row or file | New message under the photo; memo and other photos kept | Server: success just under the limit, refusal after, file count unchanged |
| 24 hours pass | Accepted again (no manual unlock) | Normal | Server: succeeds after moving the clock 24 hours and 1 second |
| Another user uploads a lot to the same module | Counted per user | Normal | Server: succeeds even if another user has 300 photos |
| Uploads split across modules | Counted together | New message | Server: two-module total is refused |
| A stolen session uses up the limit | The real customer also cannot upload for up to 24 hours | New message. No alert reaches the head office | None. The user sees the message, but the head office has no way to know |
| Several photos uploaded at once go slightly over | A few more are accepted | Normal | None (accepted; damage is small) |
| The photo table grows so large the count slows down | Uploading gets slower | The uploading indicator lasts longer | None. An index would be added then |
Not done this time
- Storage usage monitoring and alerts, and telling the head office when a user hits the limit: left for after a deployment environment exists.
- Hiding the “upload again” button on a photo that hit the limit: left out to keep screen changes small.
- Measuring the real stored size of one photo.
A document added alongside: security review item 7 stays as is
On the same day I decided to leave security review item 7 as it is (anyone who knows a phone number can lock an invitation or recovery code by entering 5 wrong codes), and I asked for one line in the decision log plus a decision memo to go into this PR. The code did not change. Claude recommended splitting this into a separate PR since the topic differs from the photo limit, but I chose to keep it in this one.
The reasons and numbers come from another Claude Code session (model unknown) that handled item 7, passed on through a shared note. Claude in this session re-checked them against the same code (8 digits, 5 tries, 7 days and 1 hour, 10 and 30 per minute). That session noted it had not received my decision directly; the basis for the decision is what I said in this session.
How it was checked
PR 220
- On the commit with only the new tests, Codex’s tests showed 9 of 21 new tests failing (the other 12 pass under the current rules too).
- After the implementation, the 21 new tests and the existing login, recovery and database structure tests, 55 in all, passed.
- The full
npm run verifypassed in 438 seconds: 699 server, 325 admin web, 463 customer app tests. No test was rerun one by one. npm run e2e:apppassed 12 tests (44 seconds). Tests were not found under.claude/worktrees, so the same commit ran in a Codex clone.codex exec review --base origin/mainfound no defect to fix. Codex said it could not run the database tests because it has no Docker.
PR 221
- On the commit with only the new tests, 8 of 10 new server tests failed (the other 2 pass under the current rules too).
- After the implementation, one test failed with 401. The test kept using a login token that had expired after moving the clock more than 24 hours. The implementation side did not fix it itself; it sent it back to Codex, which fixed it.
- After that, the 10 new server tests, 10 existing photo tests and 28 app message and photo pipeline tests passed.
- The full
npm run verifypassed in 322 seconds: 709 server, 325 admin web, 464 customer app tests. No test was rerun one by one. npm run e2e:apppassed 12 tests (45 seconds), run in a Codex clone for the same reason.codex exec review --base origin/mainfound no defect to fix, and said for the same reason that it could not run the database tests.
The admin web did not change in either PR, so npm run e2e was not run.
What was not checked
- Real phone checks: for PR 220, whether the phone you were using still logs in and whether reinstalling the app makes it an unknown device; for PR 221, whether the new message appears on a real screen.
- PR 220’s migration rollback (down) was not run.
- A customer on a new phone or with a reinstalled app still hits the number lockout while under attack. Kakao or Apple login or a recovery code unlocks it.
- There is no cleanup that deletes old rows from
login_throttles(there was none before either). - In this session, the end-of-response verification hook reported failure twice even though all tests had passed. Running the same command by hand passed. The cause was not found.
Lessons
- Check in the code who sets a value. Claude’s first recommendation assumed the server could trust the device value, but the sender can change it.
- Count by something the attacker cannot change. Using records the server already holds, such as “has logged in from this device before”, solves it without a new table.
- Tests that move the clock far must also consider login token expiry. Claude decided to write “get a fresh token after moving the clock” into the next work instructions.
- In a new working folder (worktree), run
npm cifirst. In both tasks the first verification failed because the dependencies (node_modules) were not installed. The order in the handover file should have been followed first.