Add abuse protection to the ROI calculator form
The calculator endpoint was open to anyone, and it has been collecting spam submissions. Add a layered guard that runs before anything is written to the DB or sent to the AI provider: - Cloudflare Turnstile CAPTCHA, verified server-side (active when TURNSTILE_* keys are configured; fails closed if unverifiable) - Honeypot field that only bots fill in - Signed, single-use form token enforcing a 4s minimum fill time - Per-IP rate limiting (5 per 10 min, 25 per 24h) Layers 2-4 need no configuration and work on their own, so submissions are throttled immediately; adding Turnstile keys upgrades it to a full challenge. Blocked submissions now stop the flow client-side instead of silently showing a result. Also sets `trust proxy` for correct client IPs behind nginx, caps the JSON body at 32kb, and fixes a latent ReferenceError in the "AI not configured" branch that called saveCalcSubmission() before the variables it closes over were declared. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
17
styles.css
17
styles.css
@@ -821,6 +821,23 @@ a.feature-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg)
|
||||
}
|
||||
.input-prefix-wrap input { padding-left: 28px; }
|
||||
.calc-error { color: var(--red); font-size: 13px; margin: 8px 0; font-weight: 500; }
|
||||
|
||||
/* Honeypot — visually and semantically hidden, but still fillable by bots.
|
||||
Deliberately not `display:none`, which the better bots skip. */
|
||||
.calc-hp {
|
||||
position: absolute !important;
|
||||
left: -9999px;
|
||||
top: -9999px;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
overflow: hidden;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* CAPTCHA widget slot — collapsed until a challenge is actually rendered */
|
||||
.calc-captcha:empty { display: none; }
|
||||
.calc-captcha { margin: 12px 0 0; display: flex; justify-content: center; }
|
||||
.calc-submit-btn { width: 100%; justify-content: center; margin-top: 16px; }
|
||||
.calc-fine {
|
||||
font-size: 11px;
|
||||
|
||||
Reference in New Issue
Block a user