Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

A secure authentication backend needs more than a JWT decoder and a password check. Set a trusted token-validation policy, protect refresh tokens against theft and replay, throttle login attempts using more than one signal, and make failed logins as indistinguishable as practical. The details depend on your token profile and threat model; there is no universal algorithm, lockout threshold, or timing target that fits every service.

Start with the authentication flow and its trust boundaries

Separate the jobs your backend performs: verifying a user’s credentials, issuing access tokens, validating those tokens at APIs, and issuing replacement access tokens when a session continues. Each step has different risks. A signed JWT can still be invalid for your API; a refresh token can be replayed if stolen; and login errors can disclose whether an account exists even when their wording looks generic.

Write down the token profile your service accepts before implementing verification. Specify the trusted issuer, intended audience, required claims, signing or encryption expectations, and the keys and algorithms your service permits. The IETF’s RFC 8725, JSON Web Token Best Current Practices, treats JWT handling as a security-sensitive protocol decision because attacks have exploited underspecified mechanisms and incorrect implementations.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Validate JWTs using trusted policy, not token-supplied instructions

A JWT is a container for claims; decoding its header and payload does not establish that the token is authentic or appropriate for your API. Verify its integrity using trusted configuration, then validate the claims required by the token profile. OWASP advises rejecting unsecured alg: none tokens and choosing verification algorithms from the relying party’s own configuration rather than trusting the token header. See the OWASP REST Security Cheat Sheet.

  • Algorithm and key policy: Allow only algorithms and keys configured by your service. Do not let a JWT header decide which verification method to use.
  • Issuer (iss): Check that the token was issued by the expected authority.
  • Audience (aud): Check that the token is intended for this API or service.
  • Expiry (exp): Enforce expiration when required by the token profile.
  • Other profile claims: Validate any additional claims your application relies on for authorization or token handling.

Do not treat one algorithm or a fixed list of claims as mandatory for every JWT deployment. Requirements depend on the token’s purpose and profile. The important distinction is that the verifier defines and enforces the policy; successful parsing alone is not validation.

Choose a refresh-token replay defense

Access tokens are commonly short-lived, while refresh tokens let a client obtain new access tokens without repeating the full authorization process. That convenience also makes refresh tokens valuable to an attacker who steals one: it may be replayed to mint more access tokens. RFC 9700 describes refresh tokens as “a convenient and user-friendly way to obtain new access tokens.” The IETF published RFC 9700, Best Current Practice for OAuth 2.0 Security, as BCP 240 in January 2025.

For public clients, RFC 9700 requires refresh tokens to be sender-constrained or rotated. These are different defenses, not interchangeable labels for the same mechanism:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Approach How it works Important trade-off
Sender constraint Bind the refresh token to a client instance using an appropriate proof-of-possession mechanism, so possession of the token alone is not sufficient. Protection depends on the client’s ability to securely use the binding mechanism.
Rotation Issue a replacement refresh token and invalidate the previous one, while retaining the relationship between tokens so reuse can be detected. If a previously invalidated token is replayed, the authorization server cannot tell which party submitted it. It may revoke the active token, requiring the legitimate user to obtain a fresh authorization grant.

In either design, protect refresh tokens in transit and storage, and bind them to the consented scope and resource servers. Decide how the application will recover if replay detection revokes an active token; that response is a security measure with a real user-facing cost, not just an internal logging event.

Throttle login attempts without creating an easy lockout attack

Login throttling should account for both attacks concentrated on one account and attacks distributed across many accounts. OWASP’s Authentication Cheat Sheet discusses maximum attempt counts, observation windows, account lockouts, and lockout duration, while warning that an attacker may deliberately lock out someone else’s account.

Signal or control What it helps address Design consideration
Per-account or per-username limit Repeated attempts focused on one person, including attempts spread across source addresses. Lockout and throttling can inconvenience the legitimate user or be abused to deny access. Provide a considered recovery path and monitor the effects.
Per-source limit, such as per IP or related source Many attempts against different accounts coming from one source, as in broad password spraying. A source-only control may not stop attempts distributed across many sources. Consider the relevant attack pattern rather than relying on one bucket.
Multiple buckets Different combinations of targeted and distributed automated attempts. OWASP’s Bot Management and Anti-Automation guidance discusses per-username and per-IP limits and token-bucket or sliding-window methods. A single bucket keyed only by IP plus username may not constrain broad credential-stuffing activity.

Choose thresholds, observation periods, and lockout behavior for your account population and threat model; the cited guidance does not establish one numeric threshold appropriate to every service. Apply anti-automation protections to credential-recovery endpoints as well as login. OWASP’s API Security Top 10:2023, API2 Broken Authentication, calls for anti-brute-force mechanisms on authentication endpoints and identifies acceptance of weak or unsigned JWTs as a broken-authentication risk.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Make failed logins hard to distinguish

A generic message such as “Invalid credentials” is not enough if the backend behaves differently for an existing and a nonexistent account. For example, an implementation that quickly rejects an unknown username but performs password verification for a known one may create a measurable response-time difference. An attacker can use repeated observations to infer which accounts exist.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make the observable behavior of authentication failures as similar as practical:

  • Use the same user-facing failure message for an unknown account and an incorrect password.
  • Review processing paths so one failure state does not consistently take substantially less work than another.
  • Compare HTTP status codes and other response behavior, not just the message text.
  • Include account recovery and related authentication endpoints in the review, since they can reveal similar account-validity signals.

This guidance addresses timing differences and other response discrepancies that can enable account enumeration. It is not a complete treatment of every cryptographic side-channel attack, which requires threat-specific analysis.

Keep standards and draft guidance distinct

Security recommendations have a publication status as well as a date. RFC 9700 is the published OAuth 2.0 Security Best Current Practice relevant to refresh-token replay defenses. RFC 8725 is the published JWT Best Current Practice, dated February 2020, and advises readers to account for applicable updates and errata as security assessments evolve.

A separate OAuth security update, draft-ietf-oauth-security-topics-update, was an Internet-Draft dated July 6, 2026, expiring January 7, 2027. It proposes updates but is not an adopted RFC; do not describe draft text as binding published guidance. OWASP cheat sheets are living guidance, while the cited API Security Top 10 page is specifically the 2023 edition.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.