This page explains how challenges are kept safe. The design is shared with the Go port of the same package.
What is stored
Each image is a challenge with a random 128-bit id. The store keeps a record with the id, its mode
(session or keyed), its profile, a deadline, the attempt limit, and a verifier. The verifier is an
HMAC-SHA256 of the id, profile and normalized answer, under a key derived from APP_KEY. The answer
itself is never stored, logged or sent. The configured answer and key fields are excluded from
flashed old input. Register every renamed or nested field in CAPTCHA_ANSWER_FIELDS or
CAPTCHA_KEY_FIELD.
One pass per challenge
- Issuing writes the attempt counter for a limited profile, then the record.
- A check reserves a failure unit before any challenge read, including the current session pointer.
- It reads the live record and atomically counts the attempt before comparing on a limited profile.
- An exhausted challenge stops before comparison. A correct answer passes only if the check removes the live record and, for session mode, the challenge is still current.
- The check returns its failure unit at most once on known outcomes other than a wrong answer. A store error, deadline or cancellation before the attempt increment returns the unit. Once the increment starts, an uncertain outcome keeps the unit. The same applies once comparison begins on an unlimited profile.
A store failure or timeout fails the check. If returning a unit fails after a correct comparison, the challenge stays consumed and the check returns a store error or timeout. The caller has one two-second deadline for the entire check.
Sessions
The session only marks which challenge it last saw. The store keeps the current challenge per session (by a hash of the session id) and profile, and both must agree. An old copy of a session cookie can't bring back an earlier image.
Limits
The challenge store admits at most N images per client per clock minute across profiles, and at most N wrong answers per client and profile per clock minute. Both counters use atomic increments in fixed windows. See Deployment for the settings and operational limits.
The rule applies the 256-byte answer limit to the string it receives. Configure the answer and key
exemptions alongside other providers' exceptions in the application's final
with_middleware callback. The app checks the global replacements
at boot. On an exempt answer, the limit applies before whitespace normalization.
Laravel can trim unregistered fields or turn empty strings into null first. A missing or blank submission rejected by the rule spends no attempt. A value
that exceeds 256 bytes counts as a wrong answer if a live challenge is checked.
Math challenges offer low guessing resistance. There are only 29 possible sums, and boot requires one to three attempts for a math profile.
What a captcha can't do
An image captcha slows automated submissions down. It doesn't stop a determined attacker with OCR. Pair it with rate limits on the form itself, and offer people who can't read the image another way in.