Device Code Phishing Can Hijack AI Coding Agents like GitHub Copilot CLI, Exposing Code and Remote Execution
What Happened — Microsoft’s security research team demonstrated a proof‑of‑concept where an attacker used the OAuth device‑code flow to obtain a valid GitHub token for a user who approved the request. By convincing the user to enter a short code on the legitimate GitHub verification page, the attacker gained the same permissions the user’s client would have, allowing the malicious client to (1) steer an active Copilot CLI session and run commands on the user’s machine, (2) inject false entries into the agent’s memory, (3) read cloud‑synced Copilot sessions, and (4) access private repositories tied to the compromised account. The technique works with any public client that supports the device flow, not just Copilot CLI.
Device‑code phishing has emerged as a repeatable path to account takeover, allowing attackers to bypass passwords by coaxing users into approving a sign‑in on a legitimate site with a short code. Once approved, the compromised token can grant access to email, files or other cloud services, depending on the permissions attached to the account. Microsoft disclosed that the technique was used in campaigns such as EvilTokens, which the company, its industry partners and law‑enforcement agencies disrupted in September 2026, and in the AI‑enabled Storm‑2372 operation earlier that year.
In a new line of inquiry, researchers examined how the same trick could be turned against an AI coding agent rather than a mailbox, using GitHub Copilot CLI as a representative case. The command‑line tool supports the OAuth device flow, a method that lets public clients obtain a token after a user enters a short code on GitHub’s verification page. Because the client identifier is public and no secret is required, any public client that implements the device flow can be abused, and the attacker can request whatever scopes are needed for the target account.
A controlled lab simulation showed what an attacker could do after a victim test account approved a Copilot CLI device‑code request initiated by the attacker’s client. The researchers identified four possible impacts: (1) steering an active Copilot session remotely when the user has enabled remote control and the organization’s policy permits it, allowing the agent to run commands on the user’s machine subject to local OS permissions and approval prompts; (2) inserting misleading entries into the agent’s memory via the /memory command, which could bias future interactions; (3) reading cloud‑synced Copilot sessions that contain prior code snippets, file paths and architectural discussions, provided the organization’s session‑storage policy allows syncing; and (4) accessing private repositories that the compromised account can reach. The team emphasized that these outcomes are proof‑of‑concept results, not attacks observed in the wild, and each depends on the victim’s enabled features, granted scopes and account permissions.
The attack proceeds in five steps. First, the attacker initiates a device‑code sign‑in request; the Copilot CLI client identifier is public, and the request includes the desired scopes. Second, the attacker lures the user by sending the short code and a GitHub verification link, often masquerading as an IT request or a Copilot license check. Third, the user follows the link, signs in on the genuine GitHub domain, and approves the request—a social‑engineering step that the legitimate domain alone cannot flag. Fourth, the attacker‑controlled client automatically completes the sign‑in after approval. Finally, the attacker operates within the permissions granted to the application, exploiting remote‑control capabilities, memory, synced sessions or repository access as described. Microsoft Defender later demonstrated how it can correlate phishing attempts with GitHub authentication activity to help organizations block such suspicious access.
In the controlled experiment, the device‑code flow granted the test account read‑only access to its private repositories. The OAuth request listed the repo scope together with read:user, read:org, gist and codespace. Those scopes are set by the client that initiates the flow, so the level of repository exposure mirrors the client’s request and the account’s existing permissions rather than any intrinsic property of the Copilot CLI. Consequently, any code or infrastructure definitions stored in the account’s repos could be retrieved by the attacker.
A single phishing email, a click on a malicious link, and a seemingly ordinary GitHub authorization page can each appear harmless in isolation. Defenders must therefore correlate the three events to spot a takeover attempt. Microsoft Defender for Cloud Apps, when paired with the GitHub Enterprise Cloud connector, supplies the necessary visibility into GitHub activity to flag such patterns. The research team built two detection rules—one for email‑borne device‑code phishing and another for the same technique delivered via Microsoft Teams—that link suspicious messages and clicks to subsequent OAuth token creation or regeneration events.
Beyond alerting, the team added a disruption capability for GitHub Enterprise Managed Users. When triggered, it suspends the compromised managed identity through the organization’s identity provider, cutting off the attacker’s foothold. The researchers confirmed this action in their test environment and advised responders to also revoke any unexpected OAuth grants, confirm that access has been blocked, and examine potentially affected sessions, repositories, and stored Copilot memory. Availability of these controls depends on proper telemetry, identity integration and deployment prerequisites.
Mitigation advice stresses clear approval policies: users should only enter a device code for a sign‑in they have started themselves. An unsolicited request to “verify” GitHub or enable Copilot—even on a genuine github.com page—should be treated as phishing; GitHub’s verification screen warns users “never use a code sent by someone else.” Organizations are urged to enable Safe Links in Microsoft Defender for Office 365 for both email and Teams, tighten Copilot CLI session settings (prefer the most restrictive “Store local sessions in the Cloud” option that still meets workflow needs), and regularly audit authorized OAuth applications, limiting repository permissions to the minimum required. If Copilot Memory is active, teams should use GitHub’s memory‑management tools to purge suspicious facts, noting that disabling the feature does not automatically erase existing entries.
The simulation’s most striking finding was how little appeared out of the ordinary: the victim visited the authentic GitHub site and approved a request that looked legitimate, yet the request originated from a client the user never launched. The downstream impact hinged on the compromised identity’s repository rights and the Copilot CLI capabilities that were enabled. The observed techniques map to MITRE ATT&CK T1566.002 (spearphishing link) and T1528 (steal application access token). The authors reference GitHub documentation on OAuth app authorization, Copilot CLI authentication, remote session control, and session data for further technical detail.
Microsoft’s documentation now includes a “Managing Copilot Memory” guide for enterprises, which explains how administrators can configure memory settings and control what information the AI retains. A companion “Reviewing your authorized OAuth apps” page walks users through the process of auditing and revoking OAuth permissions, while the “Repository roles for an organization” guide details the permission tiers that can be applied to limit access based on user responsibilities.
In the GitHub‑Enterprise space, Microsoft Learn outlines how to connect GitHub Enterprise Cloud to Microsoft Defender for Cloud Apps, giving security teams visibility into GitHub activity and enabling more thorough investigations. Parallel guidance for Microsoft Defender for Office 365 shows how to set up Safe Links policies that block malicious URLs, reinforcing protection against phishing and other link‑based threats.
The Microsoft Threat Intelligence community continues to publish research on its blog, and it encourages readers to follow its updates on X (formerly Twitter) and Bluesky. The community also shares insights through a dedicated podcast that discusses evolving threat landscapes, and it provides documentation on real‑time protection capabilities that organizations can enable.
Additional resources focus on AI‑specific defenses: Microsoft’s “Securing Copilot Studio agents with Microsoft Defender” guide, a Zero Trust for AI workshop, and the Microsoft 365 Copilot AI security documentation all aim to harden AI deployments. The company’s security blog details how it discovers and mitigates attacks against AI guardrails, including prompt‑injection protection built into Defender for Office 365 and a case study on “AI Recommendation Poisoning” observed in email traffic.
Finally, Microsoft Defender for Office 365’s blog announced a new feature that defends inboxes from prompt‑injection attacks, and the Microsoft Security Blog describes how the organization is reimagining the security operations center for the agentic era with the ISOC framework. Further guidance and tooling updates are expected as the threat landscape evolves.
Why It Matters for Trust & Control Assurance — The scenario tests the effectiveness of identity‑and‑access‑governance controls around OAuth authorizations and least‑privilege scope enforcement.
Who Is Affected — Technology‑SaaS providers, development teams, and any organization that lets developers use AI‑assisted coding tools (e.g., GitHub Copilot, Azure AI extensions).
Recommended Actions —
- Educate users to approve device‑code requests only when they initiate them.
- Enforce least‑privilege OAuth scopes and regularly review/revoke unexpected authorizations.
- Disable remote‑control of Copilot CLI sessions unless required, and set the most restrictive session‑storage policy.
- Deploy Microsoft Defender for Cloud Apps (or equivalent) to detect suspicious device‑code OAuth activity and automate revocation.
Technical Notes — Attack vector: phishing‑based OAuth device‑code flow. No CVE; the risk stems from user‑initiated approval of a legitimate‑looking request. Outcomes depend on granted scopes (read:user, read:org, repo, etc.) and on whether remote‑control and cloud‑session sync are enabled. Source: Microsoft Security Blog