jwt
"jwt not active": Clock Skew, nbf, iat and Leeway Explained
A brand-new token fails with "jwt not active" or "not yet valid (iat)" when the verifier clock lags the issuer. Fix it with a few seconds of leeway and a synced clock.
By Kyle Hurst ·
You log in, get a token, send it to your API a few milliseconds later, and the API throws NotBeforeError: jwt not active. Or PyJWT says The token is not yet valid (iat). The token is fine. The verifier’s clock is a few seconds behind the issuer’s, so to the verifier the token looks like it was issued in the future. The fix is a small leeway (a few seconds, maybe a minute) plus fixing the clock, not turning the check off.
The quick fix for each library, all measured below:
// jsonwebtoken (Node)
jwt.verify(token, key, { algorithms: ['RS256'], clockTolerance: 30 })
// jose (Node, browsers, Deno, Bun)
await jwtVerify(token, key, { clockTolerance: '30s' })
# PyJWT
jwt.decode(token, key, algorithms=["RS256"], leeway=30)
# ruby-jwt
JWT.decode(token, key, true, algorithm: 'RS256', leeway: 30)
// golang-jwt v5
jwt.Parse(token, keyFunc, jwt.WithLeeway(30*time.Second))
Before you paste that, spend one minute confirming it really is skew and not a timezone or milliseconds bug. Leeway hides those. The check is further down.
What the error is actually checking
A JWT carries up to three time claims, each a NumericDate. RFC 7519 defines that as “the number of seconds from 1970-01-01T00:00:00Z UTC until the specified UTC date/time, ignoring leap seconds.” Seconds, not milliseconds, and always UTC.
On exp, §4.1.4 says: “The processing of the “exp” claim requires that the current date/time MUST be before the expiration date/time listed in the “exp” claim. Implementers MAY provide for some small leeway, usually no more than a few minutes, to account for clock skew.”
On nbf, §4.1.5 says: “The processing of the “nbf” claim requires that the current date/time MUST be after or equal to the not-before date/time listed in the “nbf” claim. Implementers MAY provide for some small leeway, usually no more than a few minutes, to account for clock skew.”
On iat, §4.1.6 says: “The “iat” (issued at) claim identifies the time at which the JWT was issued. This claim can be used to determine the age of the JWT.” It gives no rejection rule. Some libraries reject a future iat anyway; the spec doesn’t require it.
So “current date/time” means the verifier’s own clock. Most issuers set iat to their own now, and many set nbf to that same value. If the verifier’s clock is 2 seconds behind, a token used immediately has an nbf 2 seconds in its future. With zero leeway, that’s a rejection. Most libraries default to zero.
The measured table
We built three tokens on this machine: one with nbf 5 seconds in the future, one with iat 5 seconds in the future, and one whose exp passed 5 seconds ago. Then we verified each with every library’s default options and again with 10 seconds of leeway. The Go row comes from reading the v5.3.1 source, because Go isn’t installed here. Every other row is real output.
| Library (version) | nbf +5 s | iat +5 s | exp −5 s | Default leeway | Leeway option |
|---|---|---|---|---|---|
| jsonwebtoken 9.0.3 (Node 22.18) | NotBeforeError: jwt not active | accepted, never checked | TokenExpiredError: jwt expired | 0 | clockTolerance (seconds) |
| jose 6.2.18 (Node 22.18) | JWTClaimValidationFailed: "nbf" claim timestamp check failed | accepted, unless maxTokenAge is set | JWTExpired: "exp" claim timestamp check failed | 0 | clockTolerance (seconds or '30s') |
| PyJWT 2.15.1 (Python 3.15) | ImmatureSignatureError: The token is not yet valid (nbf) | ImmatureSignatureError: The token is not yet valid (iat) | ExpiredSignatureError: Signature has expired | 0 | leeway (seconds or timedelta) |
| ruby-jwt 3.3.0 (Ruby 4.0) | JWT::ImmatureSignature: Signature nbf has not been reached | accepted, unless verify_iat: true | JWT::ExpiredSignature: Signature has expired | 0 | leeway, or nbf_leeway / exp_leeway |
| golang-jwt v5.3.1 (source, not run) | token has invalid claims: token is not valid yet | accepted, unless WithIssuedAt() | token has invalid claims: token is expired | 0 | jwt.WithLeeway(d) |
With 10 seconds of leeway, every library accepted every token, with one exception covered below. A few details the table can’t hold:
- jsonwebtoken never compares
iatto now. Its verify.js checksnbfandexpagainstclockTolerance.iatis only used bymaxAge, which computesiat + maxAgeand rejects if now is past it. A futureiatmakes that deadline later, so it passes. We confirmed this withmaxAge: '1h'and aniat5 seconds ahead (accepted), and even with aniatin milliseconds (also accepted). So if you seejwt not activefrom jsonwebtoken, the cause is alwaysnbf.ignoreNotBefore: truesilences it, but that is the “disable the check” option. - jose checks a future
iatonly when you passmaxTokenAge. Then a 5-second-futureiatfails with"iat" claim timestamp check failed (it should be in the past), andclockToleranceapplies to that check too. WithmaxTokenAge: '1h', clockTolerance: 10the same token passed. - ruby-jwt’s
leewaydoes not apply toiat. Withverify_iat: true, leeway: 10, the 5-second-future token still failed withJWT::InvalidIatError: Invalid iat. ItsIssuedAtcheck reads its own leeway, passed asverify_iat: { leeway: 10 }. With that, it passed. - golang-jwt checks
expandnbfby default but checksiatonly withjwt.WithIssuedAt(). Leeway applies to all three (validator.go). Errors are wrapped, so match witherrors.Is(err, jwt.ErrTokenNotValidYet)rather than comparing strings.
PyJWT changed its mind about iat, twice
If one PyJWT version accepts your token and another rejects it, this is why:
- Up to 1.4.x, a future
iatwas rejected withInvalidIssuedAtError: Issued At claim (iat) cannot be in the future.This came up in issue #190 from a user whose partner’s tokens arrived “a few seconds or minutes ahead of our clock time”. - 1.5.0 through 2.5.0 stopped checking. PR #252 (merged April 2017) removed the check, saying “RFC 7519 does not require or even mention this type of validation.” We ran 2.5.0: a 5-second-future
iatwas accepted. - 2.6.0 and later check again. PR #794 added
ImmatureSignatureError("The token is not yet valid (iat)")wheniat > now + leeway. We ran 2.6.0, 2.7.0 and 2.15.1: all three rejected the token by default and accepted it withleeway=10.
Versions 1.4.2 and 1.5.0 don’t import on Python 3.15, so their behaviour above comes from the changelog and the issue text. If an upgrade past 2.5 suddenly breaks tokens that used to work, a future iat is the likely cause, and leeway covers it. options={"verify_iat": False} also works, but it switches off a check that catches the bugs in the next section.
Rule out the bugs that look like skew
Skew is a few seconds, maybe a few minutes. Anything else is a bug that leeway would hide. Decode the claims and compare them to the verifier’s clock, on the verifier machine:
node -e 'const p=JSON.parse(Buffer.from(process.argv[1].split(".")[1],"base64url"));const now=Math.floor(Date.now()/1000);for(const k of ["iat","nbf","exp"]) if(k in p) console.log(k,p[k],"now minus",k,"=",now-p[k],"s")' "$TOKEN"
date +%s
Then read the gap:
now − iat on the verifier | What it means |
|---|---|
| −1 to about −60 s | Clock skew. Fix the clock and add leeway. |
| A whole number of hours, like −18000 | A timezone bug. The issuer built a “UTC” timestamp from local time. |
| About −1.79 trillion (the claim has 13 digits) | The issuer wrote milliseconds where seconds belong. |
| Positive and large, token already expired | The issuer’s clock is behind, or the token was cached and reused. |
The timezone case is easy to cause in Python. datetime.utcnow() returns a naive datetime, and .timestamp() treats a naive datetime as local time. We ran int(datetime.utcnow().timestamp()) - int(time.time()) with TZ=America/New_York and got 18000, five hours in the future. With TZ=Asia/Tokyo we got -32400, so every one-hour token would be born nine hours old and already expired. The Python docs deprecate utcnow() and recommend datetime.now(timezone.utc).
The milliseconds case behaves differently in each library. With an iat of Date.now() instead of Math.floor(Date.now()/1000), PyJWT rejected it even with leeway (The token is not yet valid (iat)), while jsonwebtoken and jose accepted it by default. An exp in milliseconds is worse. It decodes to the year 58855, so the token never expires and nothing complains. The mirror-image bug is a decoder that skips the × 1000 and shows a correct seconds value as January 1970. Unix timestamps explained covers both. The tell is the digit count: a seconds value has 10 digits today, a milliseconds value 13. Our timestamp converter shows a value as local time, ISO 8601 and “x seconds ago”, and it reads anything above 10¹² as milliseconds, so a milliseconds claim still shows a sensible date. It does say “Read as milliseconds (13 digits)” under the input, so check that line, or use the JWT decoder below, which flags them.
Where skew comes from
The usual sources:
- WSL2 after sleep. microsoft/WSL#5324, “WSL2 date incorrect after waking from sleep”, reports the Linux clock “still where it was when machine went to sleep”. A local API in WSL then sees every token from a cloud identity provider as issued in the future.
- VMs and containers resumed from suspend. A container uses its host’s clock, and Docker Desktop on macOS and Windows runs containers inside a Linux VM that can drift the same way. If
datein a container disagrees with the host, check the VM. - CI runners and long-lived build boxes with no time sync configured.
- Phones and laptops with the time set by hand, when the client checks
expitself to decide when to refresh. - Two servers syncing to different sources. A second or two of disagreement is normal.
Fix the clock
Linux with systemd. timedatectl status shows System clock synchronized: yes/no and whether the NTP service is active. sudo timedatectl set-ntp true “enables and starts the first existing network synchronization service” (timedatectl man page).
Linux with chrony. chronyc tracking shows a line like System time : 0.000006523 seconds slow of NTP time. chrony normally corrects by speeding or slowing the clock, so a large offset takes a long time to close. sudo chronyc makestep steps the clock immediately (chronyc docs); use it only when the offset is large, since a jump can upset software that measures elapsed time.
Windows. In an administrator prompt, w32tm /resync “tells a computer that it should resynchronize its clock as soon as possible” (Windows Time service docs). w32tm /query /status shows the last successful sync and its source.
WSL2. sudo hwclock -s sets the Linux clock from the host’s hardware clock. wsl --shutdown from Windows restarts the VM with a fresh clock. Both come from WSL#5324, where some commenters report hwclock -s not helping or leaving the clock about a minute off, so check with date +%s afterwards.
How much leeway is reasonable
- On
nbfandiat, leeway lets a token be used a few seconds before it says it’s valid. That costs very little. The FAPI 2.0 Security Profile (§5.3.2.1) requires authorization servers to “accept JWTs with aniatornbftimestamp between 0 and 10 seconds in the future” and to reject anything more than 60 seconds ahead. Its rationale: “10 seconds was chosen as a value that does not affect security while greatly increasing interoperability.” - On
exp, leeway extends the life of every token, including stolen ones. With 5 minutes of leeway, a 5-minute access token stays usable for 10.
A sensible default is 5 to 30 seconds, applied to all three claims. If your library allows separate values, as ruby-jwt does with nbf_leeway and exp_leeway, go more generous on nbf and stricter on exp. Going past a minute usually means a clock is broken and should be fixed instead.
Platform defaults vary widely, which is why one stack never sees this error and another sees it daily:
| Platform | Documented default |
|---|---|
Microsoft.IdentityModel (TokenValidationParameters.ClockSkew, used by ASP.NET Core JWT bearer) | 300 seconds (5 minutes) |
Auth0’s Node SDK (express-oauth2-jwt-bearer, clockTolerance) | 5 seconds |
AWS aws-jwt-verify (graceSeconds, applies to exp and nbf) | 0 |
| AWS API Gateway HTTP API JWT authorizer | No leeway setting documented: exp must be after, and nbf and iat before, “the current time in UTC” |
Keycloak (JsonWebToken.isActive(); brokered OIDC provider “Allowed clock skew”) | 10 seconds on nbf, citing FAPI 2.0; the identity-provider setting defaults to 0 |
The 5-minute .NET default is why ASP.NET Core APIs, out of the box, accept tokens for five minutes after exp. Lower it if your tokens are short-lived.
Why some issuers backdate nbf
If you mint tokens and can’t control every verifier’s clock, set nbf a few seconds in the past. A verifier that’s slightly behind then still sees a valid token, and exp is unaffected. We ran these and got nbf exactly 30 seconds before iat:
// jose
new SignJWT(claims).setIssuedAt().setNotBefore('-30s').setExpirationTime('15m')
// jsonwebtoken
jwt.sign(claims, key, { notBefore: -30, expiresIn: '15m' })
This fixes nbf errors only. PyJWT 2.6+ and FAPI-style servers also check iat, so a verifier behind your clock still needs its own leeway or a synced clock. (TOTP codes have the same problem and solve it with a window of adjacent time steps. See how TOTP works.)
Inspect the token yourself
Paste the failing token into our JWT decoder. It runs in your browser and the token isn’t sent anywhere. It shows iat, nbf and exp as dates with how far ahead or behind each one is (“in 5 seconds”, “3 minutes ago”), and badges the token as Expired, Not yet valid, Not expired or No expiry claim. A token that fails with jwt not active gets a badge like “Not yet valid (nbf is in 2 seconds)”. A future iat gets a warning rather than a failure, an nbf or iat less than 5 minutes ahead is labelled as typical clock skew, and a value that looks like milliseconds is flagged. It doesn’t verify the signature, and says so next to the badge. Its times come from your device’s clock, not your server’s, so run the one-liner above on the server when the two might disagree.
To reproduce the error, the JWT generator signs HS256/384/512 tokens in the browser. Its sample payload’s iat is set to the current time when you click Generate, as long as you haven’t edited the payload. Once you edit it, the payload is signed exactly as shown, and “Reset payload” puts the sample back with a fresh iat. “Add nbf now” and “Add iat now” set the current time, and “Add exp +1h” sets exp an hour from now. Edit nbf to a few seconds ahead before generating and you have a token that any zero-leeway verifier rejects. For the rest of the validation checklist (signature, alg, iss, aud), see how JWTs actually work.