ImpersonateLoggedOnUser is a Windows API call that runs code in the security context of a logged-on user. It is used after a process has obtained a suitable user token, allowing access checks to treat the process as that user until the token is reverted or closed.
What the call does
ImpersonateLoggedOnUser is part of the Windows impersonation model, where a process temporarily adopts a user’s security context after it has obtained a usable token. That changes how Windows evaluates access checks for files, registry keys, named pipes, network resources and other securable objects while the impersonation is active.
The key idea is not privilege creation but context switching. The process keeps running, yet Windows treats subsequent access as if the logged-on user were making the request, until the token is reverted or closed.
Why impersonation exists
Windows impersonation is used when a service, server-side component or helper process needs to act on behalf of a user without permanently becoming that user. It is common in request handling, delegated operations and server applications that must honor the caller’s existing rights rather than the service account’s broader permissions.
That design helps preserve least privilege, because the code can perform a specific action under the caller’s identity instead of granting the process broad standing access. It also makes authorization decisions more faithful to the real user context that initiated the request.
How it works in practice
Before impersonation can occur, the process must already have a suitable token. The API then associates that token with the current thread or execution path so access decisions are evaluated against the impersonated user. In Windows terms, this is a runtime security-context change, not a password check or a new login event.
Because the effect is scoped to execution context, developers must be careful about when the impersonation starts and ends. Reverting at the wrong time can cause unexpected access failures, while failing to revert can leave later operations running under the wrong user context.
Security implications and failure modes
Impersonation is powerful because it can bridge trust boundaries inside an application, but that also makes it sensitive. If a process acquires the wrong token, inherits a token it should not use, or continues impersonating longer than intended, it can perform actions with more authority than the design expected.
Misuse can also obscure accountability. Logs may reflect the impersonated user for some operations and the service identity for others, so reviewers need to understand where the context changes occurred and whether the application cleaned them up correctly.
Risk and Threat Considerations
Impersonation becomes risky when a process can obtain or reuse a high-value token, because the attacker or faulty code can make protected resources appear accessible as another user. The danger is not the API itself, but the authority it can project if token handling, scoping or reversion is wrong.
Failure mechanism: The process runs with a borrowed security context, so any token confusion, overlong impersonation window or incomplete reversion can turn a temporary delegation into unauthorized access or privilege misuse.
Impact: Sensitive files, administrative shares, internal services and other protected resources may be accessed under the wrong user context, which can lead to lateral movement, data exposure or misleading audit records.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
MITRE ATT&CK addresses the attack and risk surface, while NIST SP 800-53 Rev 5 sets the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| NIST SP 800-53 Rev 5 | IA-2 — Identification and Authentication (Organizational Users) | Impersonation relies on established user identity before access decisions are made. |
| AC-6 — Least Privilege | The API is used to limit actions to the caller's context rather than broad service rights. | |
| Recommendation — Verify that user identity is established before any impersonated access path is used. Constrain impersonation paths so they only grant the minimum access needed for the task. | ||
| MITRE ATT&CK | T1134 — Access Token Manipulation | Impersonation is an access-token technique that changes the security context used for access. |
| Recommendation — Map impersonation activity to token-manipulation detections and alert on suspicious context switching. | ||
Practitioner Guidance
Why practitioners should care: Treat impersonation as an explicit trust boundary in code review and design review. The main operational question is whether the thread or request ever needs to act as the caller, and if so, whether the code clearly brackets the impersonation window and restores the original context immediately afterward.
What to watch for: Pay close attention to paths that combine token acquisition, delegation and downstream resource access, especially when a service handles multiple users concurrently. Impersonation bugs are often subtle because the code may work correctly in test while still creating cross-request or cross-user exposure under load.
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 November 9, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org