Consider a media site's on-call page: login completion falls after CAPTCHA is added to every sign-in while authentication failures climb. This is a response exercise, not a reported incident. The responder sees two symptoms, but a failure counter cannot establish whether bots are being rejected or legitimate readers are abandoning a challenge; meanwhile, a stolen session still needs containment.
Short answer: use CAPTCHA after login failures as the default, measure both rejection and completion rates, and require evidence before challenging every login. Always-on CAPTCHA imposes friction on every returning reader; a failure threshold concentrates it on suspicious attempts and is usually the better conversion-versus-security trade. Keep refresh-token rotation and stolen-session revocation independently testable, because a login challenge does not establish the trustworthiness of an already-issued session.
Contain the session. Then investigate.
Should CAPTCHA follow login failures when conversion falls?
Work backward from the page. An increase in authentication failures can represent successful rejection or an expanding incident, and adding CAPTCHA everywhere can make the graph quieter while pushing reader abandonment outside its measurement boundary. The earlier signal needs to connect the decision to challenge with eventual login completion. Otherwise the on-call cannot tell whether the defense helped the reader journey or merely stopped counting the readers it lost.
Count the journey.
Define completion as completed logins divided by login starts within a declared observation window. Define challenge rejection against verification attempts, and retain abandonment separately. These are proposed metric definitions, not production measurements. A completion SLO should describe a legitimate reader's ability to sign in; challenge rejection is a diagnostic signal, not a replacement for that objective. A rejected challenge does not by itself identify a bot, and an accepted one does not establish that the session is safe.
Put the session-containment action beside this view. The responder needs to identify the session being revoked and confirm the result, while refresh-token rotation remains part of the session lifecycle. Neither action should disappear behind a reassuring CAPTCHA chart.
Instrument the decision before tuning the threshold
Record the policy decision, challenge outcome, and final login outcome using an internal correlation identifier. Don't log passwords, refresh tokens, or challenge response tokens. The measurement needs relationships between events, not the secrets that authorized them.
Suppose an evaluation cohort contains 100 login starts and a failure policy challenges 10 of them. These are illustrative counts, not observed traffic or recommended thresholds. Compare completion across all 100 starts, then inspect the challenged 10 separately; measuring only readers who passed verification erases both rejection and abandonment. Give an always-on cohort the same observation window and an explicit assignment rule, so the comparison cannot reward whichever policy loses more readers before counting begins.
The denominator check is straightforward: retain all 100 starts even if only 10 receive challenges. The session check needs a separate probe. This runnable Go program verifies a designated test session and prints the service response without assuming undocumented response fields. Configure INFRAI_BASE_URL with the service's HTTPS v1 API base, INFRAI_API_KEY with a key from the environment, and TEST_SESSION_ID with the test session identifier. Run the probe before and after the controlled revocation exercise, interpret its response against the contract, and keep the output out of public logs.
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"time"
)
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func run() error {
base := strings.TrimRight(os.Getenv("INFRAI_BASE_URL"), "/")
key := os.Getenv("INFRAI_API_KEY")
session := os.Getenv("TEST_SESSION_ID")
u, err := url.Parse(base)
if err != nil || u.Scheme != "https" || u.Host == "" ||
u.User != nil || u.Path != "/v1" || u.RawQuery != "" || u.Fragment != "" {
return fmt.Errorf("configure the HTTPS v1 API base")
}
if key == "" || session == "" {
return fmt.Errorf("API key and test session ID are required")
}
client := &http.Client{
Timeout: 10 * time.Second,
CheckRedirect: func(*http.Request, []*http.Request) error {
return http.ErrUseLastResponse
},
}
for attempt := 0; attempt < 4; attempt++ {
req, err := http.NewRequest(http.MethodGet,
base+"/auth/session/verify/"+url.PathEscape(session), nil)
if err != nil {
return err
}
req.Header.Set("Authorization", "Bearer "+key)
resp, err := client.Do(req)
if err != nil {
return err
}
body, readErr := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
resp.Body.Close()
if readErr != nil {
return readErr
}
if resp.StatusCode == http.StatusTooManyRequests && attempt < 3 {
delay := time.Second * time.Duration(1<<attempt)
value := resp.Header.Get("Retry-After")
if seconds, err := strconv.Atoi(value); err == nil && seconds >= 0 {
delay = max(delay, time.Duration(seconds)*time.Second)
} else if until, err := http.ParseTime(value); err == nil {
delay = max(delay, time.Until(until))
}
time.Sleep(delay)
continue
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("session verification HTTP %d: %s", resp.StatusCode, body)
}
fmt.Printf("%s\n", body)
return nil
}
return fmt.Errorf("verification retry budget exhausted")
}
Don't pick a threshold from that example.
A failure threshold is cheap to implement and easy to tune, but the counter still needs a definition: which attempts contribute, how long they remain relevant, and what happens after a successful login. Test the possibility that an account-based counter burdens a reader targeted by someone else, or that an address-based counter groups unrelated readers. A distributed attack also needs an evaluation; a local threshold is not evidence that the broader pattern has been controlled.
Capacity planning follows the challenged share. An always-on policy sends every login through challenge handling; an after-failures policy sends a subset that can expand during abuse. Size for that expansion and for authentication work surrounding it. No measured throughput or latency result is available here to support a capacity promise, so a workload test belongs in the rollout criteria.
Buy versus build around the policy boundary
Keep the decision to require a challenge separate from verification. A stable capability contract lets the provider behind verification change without rewriting application policy code, although replacement behavior still needs acceptance testing. Infrai offers one REST API with a consistent interface across backend capabilities and multi-vendor routing; its public request and response schemas are a supporting advantage when reviewing the contract before a change. Those platform properties do not prove identical security outcomes between CAPTCHA providers.
Buying verification doesn't select a failure threshold, define the reader-completion SLO, or demonstrate session containment. Those responsibilities need an owner.
| Buy or build choice | Where to evaluate it | Trade-off and acceptance boundary |
|---|---|---|
| Google reCAPTCHA | A candidate for teams considering Google's challenge service | Compare completion and rejection under the same placement rule; changing the policy and provider together obscures causality. |
| Cloudflare Turnstile | An alternative for teams considering Cloudflare's challenge service | Exercise the actual media browser and login journeys; another provider name is not evidence of equivalent outcomes. |
| hCaptcha | A third verification-provider candidate | Include abandonment in the comparison; acceptance of challenges alone cannot select a winner. |
| Auth0 | A candidate when the purchase decision includes the identity platform | Evaluate refresh and revocation behavior as well as login admission; a challenge-service comparison cannot settle that broader choice. |
| Firebase Authentication | A candidate for an application reviewing its authentication platform | Check the application's required session lifecycle explicitly rather than assuming CAPTCHA results establish containment. |
| Keycloak | A candidate when evaluating self-managed identity infrastructure | Put deployment and on-call ownership in the decision alongside control over policy. |
| Build the placement policy around purchased verification | A team needing control over failure accounting and escalation | The platform team owns counters, instrumentation, and threshold tuning. |
The first three choices address challenge verification; the identity products involve a broader boundary and should not be scored as interchangeable CAPTCHA widgets. There is no comparable conversion or abuse-rejection dataset here that justifies ranking the providers. Their documentation starts the integration review; equivalent journeys and placement rules supply the evidence for selection.
An adapter can reduce application changes while leaving operational procedures and security acceptance tests specific to the replacement. Put that work in the roadmap. A shared interface cannot remove the team's responsibility for judging behavior.
Test containment separately from challenge placement
Run a controlled exercise with a designated test session: rotate its refresh token through the supported session flow, revoke that session, and check authorization behavior against the documented contract. Keep credentials out of the record. Establish what the application accepts after rotation and revocation without guessing token lifetimes, reuse behavior, or propagation guarantees.
This is a release criterion.
Now compare login policies while retaining that containment test. If challenge rejection improves but legitimate completion falls, the policy has exchanged reader friction for abuse resistance; decide whether the exchange fits the SLO and threat evidence. If the containment exercise misses its acceptance criteria, a better CAPTCHA chart cannot compensate. The controls answer different questions.
The default remains after-failures because most logins are legitimate and should not carry the burden imposed by the abusive minority. Challenging every login needs evidence that the narrower policy leaves meaningful exposure and that the broader one addresses it at an acceptable completion cost.
The threshold has a false-positive budget
Set the threshold too low and legitimate mistakes become challenge traffic, adding friction while a reader is already struggling to sign in; set it too high and more suspicious attempts reach authentication before the challenge applies. Neither direction can be judged from rejection counts alone.
Define a review rule before rollout: inspect completion and abandonment when the challenged share changes, retain the policy version with measurements, and give the on-call a documented way to adjust the threshold. The exact alert boundary needs traffic evidence. Inventing a universal number would make the runbook look finished while leaving its central decision unsupported.
The false-positive cost is a returning reader who could have completed login but leaves during the challenge. Measure that possibility alongside rejection, keep session revocation independently testable, and spend operational capacity on the control the evidence says needs work.
Further reading
References:
Top comments (0)