Understanding Time Drift in Classic TOTP Tokens
Timeâbased OneâTime Passwords (TOTP) â defined in RFCâŻ6238 â are widely used for secondâfactor authentication. A TOTP value is generated by applying a cryptographic hash to a shared secret and a time counter, typically derived by dividing the current Unix time by a step interval (usually 30âŻseconds). For the server to verify the code successfully, both the TOTP generator (app or hardware token) and the server must have closely synchronized clocks.
What Is Time Drift?
âTime driftâ occurs when the clock inside a TOTP token (especially hardware tokens with independent oscillators) deviates from the serverâs clock. Without compensation, a drift of even tens of seconds can cause valid codes to be rejected because they no longer match the serverâs expected value. Time drift is an inherent issue in any electronic clock or RTC chipâincluding those in hardware TOTP tokensâwhere the internal oscillatorâs frequency deviates slightly from its ideal value due to manufacturing tolerances, aging, and environmental factors like ambient temperature. In real-world devices, this drift typically results in a time discrepancy of ±2 minutes per year, though the actual value can vary significantly with temperature fluctuations.
How RFCâŻ6238 Recommends Handling Time Drift
RFCâŻ6238 acknowledges that clocks may differ and recommends several mechanisms for handling drift:
- Validation window: Servers SHOULD accept OTPs not only for the current time step (T) but also for a number of adjacent steps before and after (e.g., Tâ1, T+1). This compensates for modest clock skew between client and server.
- Resynchronization logic: If a token consistently generates OTPs ahead or behind the serverâs time, the server can record the offset in time steps once a valid OTP is detected. Future validations can then adjust for this drift, improving reliability without compromising security.
-
Limits and recovery: The server should define a maximum allowable drift. If the tokenâs drift exceeds this limit, authentication should fail, and the user may need to perform explicit resynchronization or re-enrollment to realign the token with the server.
Example: How Microsoft Entra ID Handles Time Drift
Microsoftâs identity platform (Microsoft Entra ID) implements its own timeâdrift compensation for OATH TOTP tokens, both during token activation and subsequent signâins. According to Microsoft documentation:
- For tokens with a 30âsecond refresh interval, Entra ID allows a drift of ±1 day during activation and ±1 minute during authentication. (Microsoft Docs)
- For tokens with a 60âsecond refresh interval, the server allows a drift of ±2 days during activation and ±2 minutes during authentication. (Microsoft Docs)
During authentication, Entra ID automatically checks the OTP across the allowed window. If a code falls within the acceptable drift, the server accepts it and records the observed drift for subsequent validations, effectively learning per-token offsets and improving user reliability without compromising security.
Real-World Benefits of Drift Compensation
These mechanisms ensure that users of hardware tokens, which may have accumulated significant drift over months, can still authenticate successfully. The combination of a validation window and per-token drift tracking allows Microsoft Entra ID to maintain usability while staying aligned with RFCâŻ6238 recommendations.
Limitations of TOTP and Time Drift Strategies
Despite compensation mechanisms like overlapping validation windows or learned drift adjustment, classic TOTP remains fundamentally vulnerable to certain attack classes â particularly phishing. An attacker who can trick a user into entering a valid TOTP code can immediately reuse it (within the short code validity window). Also, TOTP codes do not provide cryptographic evidence of the authenticating domain or channel, making them susceptible to real-time phishing sites that mirror legitimate login pages.
Stronger Alternatives: FIDO2 and PIV
For scenarios where phishing resistance is required, modern standards like FIDO2 (WebAuthn) or PIV (Personal Identity Verification) smart cards are strongly recommended. In addition to not relying on time, these methods leverage asymmetric cryptography and cryptographically bind authentication to the intended origin, making it infeasible for a malicious site to harvest credentials and reuse them elsewhere.
Subscribe to our mailing list
Want to keep up-to-date with the latest Token2 news, projects and events? Join our mailing list!