Short-lived codes can still be extracted if malware can recover the screen fast enough. The risk comes from the rendering window, not just the code lifetime. If an attacker can optimise the pixel recovery path, seconds can be enough to capture a value that was assumed to be ephemeral.
Why short-lived codes are vulnerable before they expire
One-time codes only protect you if the attacker cannot recover them during the brief period they are visible. If malware can inspect the screen, intercept the rendered pixels, or scrape the code from the UI fast enough, the code’s short lifetime matters less than the capture window. The control assumption is not “the code lasts long enough,” but “the code cannot be extracted before it disappears.”
The important distinction is between code validity and code observability. A code can be cryptographically or operationally short-lived and still be exposed through screenshots, accessibility layers, remote desktop streams, overlay malware, browser instrumentation, or rapid screen capture. In practice, the attack succeeds when the attacker optimises the pixel recovery path faster than the user or system removes the value from view.
That is why ephemeral presentation is not the same as secrecy. A code displayed for only a few seconds still exists as rendered content, and anything that can observe that content in real time can harvest it. The shorter the display window, the harder the job becomes, but the window rarely drops to zero. Short lifetime reduces exposure; it does not eliminate extraction risk.
What the attack path looks like in practice
This weakness usually appears when malware already has local visibility or a remote foothold and is watching for authentication artefacts. It does not need to understand the full login flow if it can simply collect the code as soon as it appears. That is why one-time codes are often beaten by speed, automation, and pre-positioned access rather than by sophisticated cryptanalysis.
The attacker’s advantage comes from automation around the display event. A capture routine can poll the screen, hook a rendering path, or read from an active session far faster than a human could transcribe the code. In other words, the exploit is not “break the code,” it is “see the code first.” When the code is the final step in the login process, that single observation may be enough to complete the transaction before the code expires.
For practitioners, that means the relevant question is whether the code is resistant to observation, not just whether it is short-lived. If the environment permits malware-assisted screen recovery, then the code is acting as a weak shared secret under time pressure, not as a strong phishing-resistant authenticator.
Why this matters for authentication design
One-time codes are a weaker assurance mechanism than phishing-resistant methods because they can be replayed by whoever sees them first. They are still useful in many environments, but they should be treated as a convenience control with a known capture risk, not as a high-assurance proof that the genuine user is present. In that sense, the security boundary sits around the capture channel, not only around the token itself. The MFA Guide is useful here because it contrasts code-based MFA with phishing-resistant options and shows where bypasses typically occur.
The best control choice depends on the threat model. If the endpoint can be trusted and the code is only a fallback, the residual risk may be acceptable. If malware, remote support abuse, or screen scraping are realistic, then the organisation should prefer methods that bind the proof to a device, a cryptographic challenge, or a phishing-resistant flow rather than to a value that can be copied from pixels. The distinction matters because short-lived codes mainly defend against reuse, while they are far less effective against immediate capture.
That is also why event timing matters. A code that appears during a high-risk session, on an unmanaged device, or inside a remote-access chain is much more exposed than the same code on a locked-down workstation. The risk is not uniform; it rises when the attacker can place themselves close to the render path or when the environment already has software capable of reading the screen.
Risk and Threat Considerations
Short-lived codes create a narrow but very real observation window for malware and other local capture mechanisms. If the attacker can watch the display pipeline or the user interface fast enough, the code can be harvested and reused before its expiry time becomes relevant.
Failure mechanism: The defender assumes time limit equals safety, but the attacker only needs a faster capture path to obtain the rendered value during its brief appearance. Screen scraping, overlay capture, remote-session interception, and accessibility abuse are the practical mechanisms that collapse the safety margin.
Impact: The attacker can complete authentication, bypass the intended second factor, or drive account takeover using a value that was supposed to be temporary. At scale, repeated capture of short-lived codes becomes an operational exposure, especially where the same endpoint weakness is reused across many accounts.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10 and MITRE ATT&CK address the attack and risk surface, while NIST SP 800-63 and NIST SP 800-53 Rev 5 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-02 — Secret Leakage | Codes exposed on screen can be captured like other secrets before expiry. |
| Recommendation — Reduce exposure windows and prevent screen-based leakage of one-time codes. | ||
| NIST SP 800-63 | Phishing-Resistant Authentication | Short-lived codes are weaker when screen capture or relay is possible. |
| Recommendation — Prefer phishing-resistant authenticators over code-based second factors where capture risk exists. | ||
| NIST SP 800-53 Rev 5 | IA-5 — Authenticator Management | One-time codes are authenticators whose lifecycle and handling affect compromise risk. |
| Recommendation — Limit authenticator exposure and rotate or retire weak factors where practical. | ||
| MITRE ATT&CK | T1113 — Screen Capture | The attack path depends on rapid collection of information from the display. |
| Recommendation — Detect and block screen-capture activity on systems that display authentication codes. | ||
Practitioner Guidance
What to verify: Treat the question as an endpoint observability problem first. Verify whether the device, browser, remote-access stack, or EDR policy allows another process to see the rendered code before the user consumes it. If the answer is yes, the control is weaker than the expiry time suggests.
Decision rule: If the authentication factor can be copied from the screen and replayed within its lifetime, treat it as low assurance for any workflow that protects privileged access, customer accounts, or sensitive transactions. In those cases, move toward phishing-resistant authentication rather than relying on shorter expiry alone.
Practitioner takeaway: Expiry time reduces opportunity, but it does not fix a capture-prone design; the real control question is whether the factor can be observed and replayed faster than it can disappear.
Related resources from NHI Mgmt Group
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on October 12, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org