Introduction to AGENTS.md Files and AI Coding Agents

Agents such as AI coding agents, like OpenAI Codex and Claude Code, rely on AGENTS.md files to guide their actions. These files contain project-specific instructions, including tools to use, test running procedures, and coding conventions. However, malicious AGENTS.md files can lead to unintended consequences. Researchers at Forever Security found a malicious AGENTS.md file in a customer's Downloads folder that tricked an AI coding agent into installing a rogue npm package, leading to potential data exposure. This article delves into the details of how such attacks can occur and what users can do to mitigate risks.

How AI Coding Agents Can Be Hijacked Using Malicious AGENTS.md Files

The Attack Vector: AGENTS.md Files in Downloads

Malicious AGENTS.md File in Downloads Folder

Researchers at Forever Security discovered a malicious AGENTS.md file in a customer's Downloads folder. This file tricked an AI coding agent into installing a rogue npm package, leading to potential data exposure. The AGENTS.md file served as the agent's working directory, and the agent automatically loaded and executed the malicious instructions contained within.

The Anatomy of a Malicious AGENTS.md File

Malicious AGENTS.md files are plain-text files that contain project-specific instructions for AI coding agents. These files are not executable but can contain malicious instructions that lead to AI agents running commands, installing packages, or changing settings. The AGENTS.md file in the customer's Downloads folder contained malicious instructions that led to the installation of the npm package 'function-color.'

The Impact of the Attack

The installation of the rogue npm package led to the installation of a malicious package, exposing sensitive data. The AGENTS.md file in the Downloads folder served as the agent's working directory, and the agent automatically loaded and executed the malicious instructions contained within. The attack required the target to launch their AI agent in the same directory so it could load the instruction file and digest its malicious instructions.

Preventing and Mitigating the Risk

Preventing the Attack

To prevent such attacks, users should avoid setting the Downloads folder as an AI coding agent's working directory. The Downloads folder is a special folder that the web can write to on its own. An attacker could drop a malicious file into the Downloads folder without the user's knowledge. Users should be cautious when visiting malicious pages and ensure they are downloading files from trusted sources.

Mitigating the Risk

To mitigate the risk, users should implement security measures such as monitoring and logging of AI coding agents' activities. They should also ensure that AI coding agents are running in a secure environment, with appropriate permissions and access controls. Additionally, users should educate themselves and their teams about the risks associated with AI coding agents and the importance of maintaining a secure environment.

Conclusion

AI coding agents are powerful tools that can significantly enhance productivity and innovation. However, they are not immune to security risks. By understanding the risks and taking appropriate precautions, users can protect their AI coding agents and ensure that they are not hijacked by malicious AGENTS.md files. Users should avoid setting the Downloads folder as an AI coding agent's working directory and implement security measures to mitigate the risk of such attacks. This article aims to raise awareness and provide practical guidance for users to protect their AI coding agents and their data.

Tags: AI Coding Agents, AGENTS.md Files, Downloads Folder, Security Risks, Malicious Instructions, npm Packages

Agents Coding Hijacked Malicious Using