Summary
Cursor AI code editor versions prior to 2.5 allowed AI agents to write to unprotected .git configuration and hook files inside the project workspace.
A malicious or prompt-injected agent could persist malicious Git hooks that lead to remote code execution outside the intended sandbox when Git operations later trigger those hooks, without additional user interaction.
Affected context
The issue affects Cursor environments where:
- The AI agent (or tools it invokes) can write to the project filesystem, including
.gitdirectories. - Git is installed and used in the environment, and its hooks are executed in the host context rather than inside the same restricted sandbox as the AI.
- Git configuration and hook files are not isolated, filtered, or subject to stricter permissions than general project files.
In such setups, the AI sandbox boundary does not align with Git's execution model, allowing configuration changes inside .git to influence later host-level Git operations.
Exploit preconditions
- Attack surface: The AI assistant and tools invoked through Cursor that can write files into the project workspace.
- Required access: Logical ability for an AI agent or prompt-injected tool to create or modify files under
.git/, including hook scripts and Git config files. - Trigger point: Subsequent Git commands (e.g., commit, push, merge, checkout, receive) that cause Git to run hooks automatically using the host's execution context.
- Why exploitation is possible: The AI sandbox was treated as untrusted but was still permitted to write to Git's configuration and hook locations. Git then trusts and executes these hook scripts without re-enforcing the sandbox boundary, effectively bridging from a constrained AI environment to a more privileged host environment.
Why this happens
The core problem is an improper authorization boundary between AI-generated file writes and sensitive Git control files. Under CWE-862: Missing Authorization, the system fails to enforce additional checks for operations that modify privileged configuration, treating writes to .git directories as equivalent to regular project files.
Conceptually, Git hooks and config represent executable policy and code, not just data. By allowing an untrusted component (the AI agent, influenced by prompt injection or malicious instructions) to freely modify these assets, the editor creates an indirect code execution path. The sandbox model assumes file writes are safe but overlooks that some files (Git hooks) are automatically executed later in a different, more trusted context.
Potential impact
- AI-induced modification or creation of Git hook scripts that execute arbitrary commands.
- Sandbox escape when Git runs the malicious hooks outside the original constrained environment.
- Remote code execution in the user's development environment with the user's OS-level privileges.
- Persistent compromise of the repository, where malicious hooks survive editor restarts and continue to execute on future Git operations.
- Potential exfiltration of sensitive data such as SSH keys, access tokens, or source code via the malicious hooks.
- Lateral movement to other repositories or services if compromised hooks interact with external tooling or CI systems.
General mitigation guidance
Effective mitigation focuses on treating Git metadata and configuration as sensitive control surfaces, not ordinary project files, and enforcing strict boundaries around them:
- Introduce explicit authorization layers for any write access to
.gitdirectories, Git config files, and hook scripts from untrusted components. - Segregate AI-generated content from repository control files by design, e.g., limiting the AI to a dedicated working directory that excludes
.gitand other control paths. - Implement path-based allowlists so the AI can only create or modify files in non-sensitive locations, blocking or requiring elevated confirmation for operations targeting
.git/. - Run Git commands and any resulting hooks in a similarly constrained environment, aligning the execution context of hooks with the AI sandbox where feasible.
- Apply least-privilege principles to the AI process and tools it can invoke, minimizing the impact if configuration boundaries are accidentally crossed.
- Treat configuration-as-code surfaces (hooks, CI configs, toolchains) as high-risk and subject them to extra scrutiny compared to ordinary source files.
How teams detect issues like this
Detection can combine both preventative and forensic techniques:
- Static policy enforcement: Implement file-system guards or middleware that log or block writes to
.git/and hook locations from AI or automation processes. - Code review and policy checks: Incorporate checks in review workflows to flag changes to Git hooks and configuration files, especially if initiated by AI tools or automated agents.
- Runtime monitoring: Monitor filesystem events for unexpected modifications under
.git/hooks/or.git/configduring AI-driven sessions and raise alerts on suspicious patterns. - Configuration scanning: Periodically scan repositories for non-standard or newly added Git hooks, anomalous scripts, or unexpected commands embedded in hook files.
- Automated tooling: Use security scanners or internal tools that understand repository structure and can enforce policies (e.g., "no AI process may write to
.git") across development environments.

