AI

Cursor AI in Attacks: How Hackers Exploit AI Coding Assistants

Published  ·  9 min read

You use Cursor AI to write code faster. It helps you debug. It suggests improvements. It generates boilerplate. You trust it.

That trust is exactly what attackers are counting on.

Security researchers have found that Cursor AI and similar tools can be turned against developers. Attackers are hiding malicious instructions in AGENTS.md files and PNG images. The AI reads them, follows the instructions, and leaks your secrets.

Your AI assistant is powerful. That power works both ways.

Important Disclaimer

This article is for educational and defensive purposes only. The techniques described here are shared to help security professionals understand emerging threats so they can better protect their systems.

Do not use these techniques against systems you do not own or do not have explicit written permission to test. Unauthorized testing is illegal in most jurisdictions.

What Is Cursor AI?

Cursor AI is an AI coding assistant. It helps developers write, debug, and refactor code. It plugs into your development environment. It reads your codebase. It understands your project. It follows instructions from files like AGENTS.md.

That is what makes it useful. That is also what makes it vulnerable.

Cursor AI reads AGENTS.md automatically. It treats these files as project rules. It does what they say without asking questions.

Attackers know this. They are using it against you.

How Attackers Hijack Cursor AI

The attack is simple. The damage is not.

The AGENTS.md Exploit

An attacker submits a pull request to your repository. It contains an AGENTS.md file. It looks harmless. It looks like a coding convention file.

But hidden inside are instructions for the AI.

The instructions tell Cursor AI to read your .env file. Then it tells the AI to turn every secret into a list of numbers. Then it tells the AI to write those numbers into your source code.

You see a routine code change. You commit it. The attacker reads the commit. They decode the numbers. They have your secrets.

You never knew what happened.

The PNG Image Exploit

Attackers are also hiding instructions inside PNG images. The image looks like a screenshot or a diagram. But inside the image, written as text, are the attacker's commands.

Cursor AI can read images. It does not question what it finds.

The Ghostcommit Connection

  • This is similar to the Ghostcommit attack. In Ghostcommit, attackers hid instructions inside PNG images. AI coding assistants read them and leaked secrets.
  • Cursor AI was one of the tools that leaked. Researchers found that the coding harness mattered more than the AI model itself.
  • The same model leaked under one tool and refused under another. Cursor AI leaked. Other tools did not.

This is not about the AI model. This is about how the tool is built.

Scenario 1: The Compromised Repository

The Setup

A developer uses Cursor AI with a public repository. The repository has an AGENTS.md file. The developer never read it carefully.

The Attack

An attacker adds an AGENTS.md file with hidden instructions. The developer takes the PR without analyzing it appropriately.

The Result

Cursor AI analyzes the AGENTS.md file. It uses the hidden instructions in the file. It also opens the .env file and uncovers the secrets.

The Aftermath

The attacker manages to acquire API keys and credentials. This process remains unknown to the developer.

Scenario 2: The Malicious Image

The Setup

The developer clones a repository which has a PNG image. It appears harmless.

The Attack

The PNG has hidden instructions written on it. The Cursor AI decodes the instructions written on the PNG file.

The Result

The Cursor AI decodes the .env file and transforms the secrets into numbers to be placed in the source code. This is where the developer commits the source code.

The Aftermath

The attacker then decodes the secrets contained in the commit to access the developer’s credentials.

Scenario 3: CI/CD pipeline

The Setup

Cursor AI is integrated into the CI/CD pipeline of the business. The AI automatically merges pull requests. The AI can see everything.

The Attack

The attacker sends a PR that contains an AGENTS.md file and a PNG image. The AI merges the request automatically.

The Result

The Cursor AI processes both files. Secrets of CI/CD pipeline are revealed by the AI.

The Aftermath

Attackers get hold of deployment keys and cloud credentials. Attackers deploy malicious code in production environment.

Scenario 4: The Disgruntled Contributor

The Setup

There is a contributor that has permissions to make changes to an open source repository. This contributor is unhappy and wants to harm the project.

The Attack

This contributor creates an AGENTS.md file containing hidden instructions. This action seems like an ordinary addition of documentation files.

The Result

The Cursor AI analyzes the newly created AGENTS.md file and reveals secrets of the repository. The disgruntled contributor observes the committed data.

The Aftermath

The contributor takes advantage of the revealed secrets and damages the project.

Scenario 5: The Supply Chain Poisoning

The Setup

An attacker creates a popular open source package. They include a malicious AGENTS.md file in it.

The Attack

The download occurs and they put it to use. They use Cursor AI for their projects. The AI opens the AGENTS.md file that is included in the downloaded package.

The Result

The AI runs the commands. It leaks secrets from the developer's repository.

The Aftermath

Thousands of developers are compromised. The attacker steals API keys and sensitive data from many organizations.

Why Cursor AI Is Vulnerable

It Reads AGENTS.md Automatically

Cursor AI treats AGENTS.md as project policy. It opens the file and executes the instructions found inside. Attackers use this to inject malicious prompts.

It Can Read Images

Cursor AI can read images. It follows instructions hidden inside them. Attackers use PNG images to sneak malicious prompts past code reviewers.

It Has Access to Secrets

Cursor AI has access to the repositories it works on. This includes the .env file and others. Attackers can tell the AI to leak this data.

It Follows Instructions Without Question

Cursor AI is built to be helpful. It does what it is told. Attackers take advantage of this by hiding instructions that look legitimate.

How to Keep Your Privacy Safe

1. Review AGENTS.md Files

Never assume that your AGENTS.md files are safe until you review them. Study them to identify if there is anything questionable about them. Do not accept what you do not understand.

2. Deny AI Agents’ Access to the Secrets

If the AI agents don’t need access to your .env file, then deny them that privilege.

3. Inspect Non-Text Attachments

Do not assume images are safe. Use tools that can analyze image content. Be suspicious of images in pull requests.

4. Monitor AI Agents for Unusual Behavior

Watch for attempts to read credential files. Watch for attempts to write strange data into your code. Watch for anything unusual.

5. Use Multimodal Defensive Scanners

Use tools that can analyze image content. Test them against attack variants. Make sure they are able to defend themselves from attacks via image-based prompt injection.

6. Check for Coding Harness Security

Think about security when you evaluate AI tools. Ask how much authority they give to project files. Test how they handle untrusted content.

7. Assume Anything an Agent Reads Is Attack Surface

Prompt injection is not just a text problem anymore. Images, documents, and PDFs can also carry hidden instructions. Assume everything that your AI is reading has the potential to be a threat.

8. Check the Commit History of Your Files

Check the commit history of your files for anything unusual. Investigate number series that don’t make any sense since they might have secrets hidden within.

9. Employ AI Agents with Caution

Let the AI agents have access to any sensitive material only when necessary. They should be treated like a privileged user.

10. Keep AI Tools Updated

Vendors are fixing these issues. Make sure you are using the latest versions.

Defensive Tools and Techniques

Defense Layer

Approach

Effectiveness

AGENTS.md Review

Manual inspection

Moderate

Restrict Access

Limit agent access to secrets

High

Image Inspection

Multimodal review tools

High

Behavior Monitoring

Watch for anomalies

Moderate

Defensive Scanners

Block image-based injection

High

Code Harness

Scrutinize design

High

Commit Auditing

Review for obfuscated data

Moderate

The Bottom Line

Cursor AI is a powerful tool. It helps you write code faster. But that power comes with risk.

Attackers are using prompt injection in AGENTS.md files and PNG images. They are stealing secrets from repositories. The attacks are simple. The damage is severe.

You can defend against them. Review AGENTS.md files. Restrict agent access. Inspect images. Monitor behavior. Use defensive scanners.

Do not trust your AI assistant blindly. It is powerful. It is helpful. It is also a potential backdoor.

The attackers are already using these techniques. Do not wait until you are compromised.

FAQ Section

What is Cursor AI?

Cursor AI is an AI-powered assistant that enables developerss to create, debug, and refactor their code.

How can attackers use Cursor AI?

Attackers can hide instructions in AGENTS.md file and PNG files. The AI reads and executes the hide instructions.

What is the Ghostcommit attack?

Ghostcommit is an attack where hidden instructions are placed inside PNG images. AI coding assistants read them and leak secrets.

Can Cursor AI see my secrets?

Yes, Cursor AI has access to the repository it operates on, including .env files and others.

How do I defend myself from this threat?

Check AGENTS.md files, limit agents’ access to secrets, check non-text attachments, observe suspicious actions, and use defensive scanners.

Is Cursor AI the only vulnerable tool?

Not necessarily. There are other AI coding assistants which are vulnerable as well. What matters is the coding harness design.

Can I use Cursor AI safely?

Yes, but be careful. Restrict its access to sensitive information, monitor its reading and its activities.

What should I do if I find evidence of an attack?

Rotate all secrets immediately. Audit your commit history. Review your AI tooling and security controls.

Professional Services

Explore Our Cybersecurity Services

Our insights are backed by hands-on service delivery. If your business needs professional cybersecurity support, our UK-based specialists are ready to help.

© 2016 – 2026 Red Secure Tech Ltd. Registered in England and Wales — Company No: 15581067