GitHub Repositories Hijacking AI Coding Assistants: A Prompt Injection Attack Analysis

Malicious GitHub repositories use files like agents.md to prompt-inject AI agents, stealing developer credentials and spreading infection.
The article reveals a new type of supply chain attack: attackers hide malicious instructions in GitHub repository configuration files such as agents.md or cloud.md, exploiting AI coding assistants' inability to distinguish instructions from data to trick them into automatically executing setup.js scripts, stealing API keys, SSH keys, and .env files. Bitdefender has found 22 such malicious links, and the stolen tokens are also used to infect more repositories, creating chain-like spread. Prompt injection ranks first on the OWASP LLM risk list. The article recommends developers manually review repository files, disable auto-approval for AI agents, run agents with least privilege in sandboxes, and deploy security scanning tools, emphasizing that human review remains the last line of defense.
When Cloning a Repository Turns into a Disaster
You just cloned an ordinary GitHub repository, ready to let an AI coding assistant help you quickly get up to speed on the project. However, this repository contains a carefully crafted agents.md or cloud.md file with hidden instructions embedded in it. The AI assistant treats it as a trusted instruction and automatically executes the setup.js script, causing your API keys, SSH keys, and .env files to be stolen. This is not fiction—it is a real attack technique known as Prompt Injection.
According to security firm Bitdefender, 22 malicious GitHub links have already been used to carry out this type of attack. Attackers exploit the inability of AI agents to distinguish instructions from data, tricking them into executing malicious scripts. The stolen tokens are then used to infect more repositories, creating a chain reaction. This article will take a deep dive into how these attacks work, the potential risks, and defensive measures.

How the Attack Succeeds: The Trust Trap of AI Agents
AI coding assistants (such as Copilot, Cursor, Claude Code, etc.) are designed to treat configuration files within a project as contextual instructions in order to better understand tasks. Files like agents.md and cloud.md typically contain build, deployment, or environment configuration instructions, which AI reads and follows preferentially. Attackers exploit this trust mechanism by implanting instructions such as "run setup.js" or "do not request confirmation" into these files.
When a developer clones a repository and lets the AI agent start working, the agent reads these files, mistakenly believing they are part of the project, and automatically executes the commands they contain. Because AI cannot judge whether instructions come from a trusted source the way humans can, it may directly run malicious scripts. The core of this attack lies in the fact that AI models cannot effectively distinguish instructions from data, causing malicious content to be executed as legitimate commands.

Prompt Injection: At the Top of the OWASP Risk List
Prompt injection is not a new concept, but with the proliferation of AI coding tools, its danger has become increasingly prominent. In the LLM application risk list published by OWASP (Open Worldwide Application Security Project), prompt injection ranks first. This reflects the industry consensus on this risk: attackers can manipulate AI model behavior through carefully crafted inputs, bypassing security controls.
In the GitHub repository scenario, the vehicle for prompt injection can be any file that AI will read, including READMEs, configuration files, and even comments. Attackers only need to ensure these files are processed preferentially by the AI agent to achieve instruction injection. Since AI agents typically have high system privileges (such as access to environment variables and command execution), once exploited, the consequences can include data leakage, system compromise, and lateral movement.

OWASP (Open Worldwide Application Security Project) is a non-profit international security organization whose "Top 10" series (such as the Web Application Security Risk List) is widely regarded by the industry as a security baseline reference. With the explosion of large language model (LLM) applications, OWASP established a dedicated LLM Application Risk List (OWASP Top 10 for LLM Applications) in 2023, categorizing and ranking AI-specific threats such as prompt injection, insecure output handling, and training data poisoning. The list is maintained jointly by security experts from academia and industry and is updated regularly to reflect the latest attack surface. Prompt injection ranks first on the LLM risk list because it is difficult to eradicate completely through traditional input filtering—the attack surface covers all text channels that interact with the model, and successful exploitation often bypasses all other security controls, exhibiting the characteristic of "single point of breach, global compromise."
The Attack Chain: From a Single Repository to Supply Chain Infection
According to details disclosed by security researchers, the typical chain of this type of attack is as follows:
- Luring clones: Attackers disguise malicious repositories as useful tools or libraries and spread them through social media, forums, and other channels to entice developers to clone them.
- Implanting instructions: Hidden instructions in
agents.mdorcloud.mdrequire the AI agent to executesetup.jsand skip confirmation steps. - Stealing credentials: The
setup.jsscript reads and exfiltrates API keys, SSH keys, and sensitive information from.envfiles. - Lateral spread: Using the stolen tokens to access the victim's GitHub account and infect other repositories they own, further expanding the scope of impact.
You may not have noticed that attackers can use automated tools to mass-generate malicious repositories to improve attack efficiency. The 22 links discovered by Bitdefender are just the tip of the iceberg; the actual number may be much higher.

A supply chain attack refers to an attacker not directly attacking the final target, but instead compromising upstream components that the target depends on (such as open-source libraries, build tools, and development environments), using the trust chain to "legitimately" deliver malicious code to downstream users. GitHub repository hijacking is a new variant of supply chain attacks in the AI coding scenario: the malicious repository itself is the attack vehicle, the AI agent is the execution entry point, and the stolen tokens become a springboard for spreading to more repositories. Compared with traditional supply chain attacks (such as the SolarWinds incident), the unique aspect of this type of attack is that it exploits the AI agent's "natural trust" in project files to bypass human review—developers often do not inspect natural language instructions in agents.md line by line, while AI treats them as high-priority commands to execute. This means that defense cannot rely solely on traditional code signing or dependency scanning; it also requires trust grading and human confirmation of the sources of instructions given to AI agents.
Defense Strategies: How to Avoid Becoming the Next Victim
Facing the threat of prompt injection, developers and organizations can take the following measures to reduce risk:
- Review repository contents: Before trusting a new repository, manually inspect
agents.md,cloud.md, and any files the AI agent may read to confirm there are no suspicious instructions. - Disable auto-approval: Configure the AI agent to request confirmation before executing commands, preventing scripts from running silently.
- Limit permissions: Use the minimum necessary permissions for AI agents, for example by running them in containers or sandboxes, to prevent direct access to sensitive credentials.
- Use security tools: Deploy security scanning tools capable of detecting malicious repositories or anomalous instructions, such as static analysis or behavioral monitoring.
- Raise awareness: Educate team members to recognize prompt injection risks and avoid casually cloning repositories of unknown origin.
In addition, AI tool providers are gradually introducing protective mechanisms, such as verifying the source of instructions and limiting the scope of automatic execution. But as of now, human review remains the last line of defense.
The Principle of Least Privilege is a fundamental tenet of information security: any entity (user, program, or AI agent) should only be granted the minimum permissions necessary to complete its task, and permissions should have time limits. In the AI coding assistant scenario, this means the agent should not run with the developer's full permissions, but should be placed in an isolated environment (such as a container, virtual machine, or dedicated sandbox), mounting only the current project directory and stripping access to ~/.ssh, ~/.aws, and production credentials in environment variables. Specific practices include: running AI tools under a separate low-privilege system account, using temporary tokens instead of long-lived credentials, and setting up human approval gates for AI-generated code in CI/CD. Even if the agent is hijacked by prompt injection, least privilege can confine the damage within the sandbox, preventing credential exfiltration and lateral movement.
Conclusion: Trust but Verify
AI coding assistants greatly improve development efficiency, but they also introduce new attack surfaces. The GitHub repository hijacking incidents remind us that while enjoying convenience, we must remain vigilant. Before cloning a repository next time, take a few minutes to check those seemingly harmless configuration files—your API keys may be hanging by a thread.
Share this article with friends who habitually clone repositories casually, to help more people avoid the trap.
Related articles

Apple Bans Developer Account for 69 Days Without Human Response: The Cost of Automated Review
An Argentine independent iOS developer had his Apple Developer Program account banned by automated risk controls for 69 days, receiving only automated replies even after submitting all documents. This article reconstructs the incident and analyzes how automated review harms developers and why platform appeals fail.

PostMount: Seamless Microsoft 365 Compatibility for Legacy Email Apps
PostMount is a Windows app that uses a local IMAP/POP3/SMTP server and OAuth/Microsoft Graph to let legacy email clients, printers, and ERP systems securely connect to Microsoft 365 without Basic Auth. It supports shared mailboxes, mail relay, and mailbox export.

DeskVac: Tidy Up Your Mac Desktop with a Robot Vacuum Animation
DeskVac is a free, open-source Mac desktop tidying app that uses a robot vacuum animation to sort real file icons into folders by type—no deletions, with Undo support. Here's how it works, its safety design, and who it's for.