Prevent surrender form spam via back+resubmit #30
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/surrender-form-resubmit-spam"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The public
/surrenderform could be spammed: submit, hit Back, hit Submit again on the cached page — repeatedly, even with every field blank — creating unlimitedpendingSurrenderSubmissionrows.Fix
GET /surrenderissues a token in a hidden field; thePOSTconsumes it. Replaying a stale/cached page (already-used or unknown token) is treated like the existing honeypot case — pretend success, write nothing — so the resubmit loop can no longer create rows. Tokens expire after 2h and are swept on each issue.GET /surrender/thank-youinstead of rendering the confirmation directly from thePOST, so the confirmation page is no longer itself a resubmittable state via Back/Refresh.Testing
No local Postgres available in this environment, and
app.maincannot be imported against SQLite because its startup runs Postgres-only migration SQL (DO $$ ... $$). So thesurrenderrouter was mounted standalone on a bare FastAPI app with a throwaway SQLite engine (viaTestClient, exercising the real router/templates, not hand-called functions) to verify:This covers the router logic end-to-end but does not exercise it against real Postgres or a real browser session — worth a quick manual click-through on staging before/after deploy.