/

CVE-2026-25722

Severity:

CRITICAL RISK

(9.1)

Improper Input Validation in Claude Code Directory

CVE-2026-25722

Analyzed

Vulnerability type

Category:

Improper Input Validation

CWE:

CWE-20, CWE-78

Impact:

Unauthorized File Creation and Modification in Protected Directories

Severity:

CRITICAL RISK

(9.1)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Claude Code contained an input validation flaw that allowed directory changes into protected folders (such as .claude) to be combined with write operations, bypassing the usual write protection and user confirmation requirements.

If an attacker could inject untrusted commands or content into a Claude Code context window, they could cause the tool to create or modify files in sensitive directories without explicit user approval.

Affected context

This vulnerability appears in Claude Code's handling of filesystem operations when acting as an agentic coding tool that can run commands like cd and perform write actions on behalf of the user.

It becomes relevant when:

  • The tool is configured to allow file system edits and command-like interactions.
  • Protected or special-purpose directories (e.g., .claude) exist and are intended to be guarded by confirmation prompts or policy checks.
  • User or external content in the context window can influence sequences of navigation (cd) and write operations.

Exploit preconditions

  • Attack surface: Claude Code's command and file-edit interface, including automated or semi-automated agent actions.
  • Required access: Ability to introduce untrusted content or instructions into the Claude Code context window (e.g., via shared code snippets, pasted instructions, or collaborative inputs).
  • Trigger point: A sequence where the tool executes a cd into a protected directory followed by a write or file-creation operation that should normally be blocked or confirmed.
  • Why exploitation is possible: The protection logic validated write operations in isolation but did not robustly validate or re-check the effective directory context after cd, allowing write policies to be bypassed in certain navigation-plus-write sequences.

Why this happens

The core issue is improper input validation (CWE-20) around directory changes and subsequent write operations.

The system treated navigation commands (cd) and file writes as loosely coupled, validating write operations against expected paths without consistently enforcing or re-evaluating the actual working directory and its protection status.

This created a gap where an attacker-controlled instruction flow could move into a protected directory and then perform writes that bypassed the intended protection or confirmation mechanisms.

While CWE-78 (OS Command Injection) is related at the platform level, the specific behavior here is best characterized as insufficient validation and enforcement of path and directory constraints in the agent's command execution pipeline.

Potential impact

  • Creation of new files inside protected or internal configuration directories.
  • Modification of existing files in sensitive folders without user confirmation.
  • Potential alteration of Claude Code's local configuration, state, or cache files, which may influence future behavior.
  • Indirect integrity issues, such as poisoning project metadata or internal tool artifacts stored under protected paths.
  • In some environments, possible escalation of the tool's capabilities by modifying scripts or helper files it later executes or reads.

General mitigation guidance

Mitigation generally focuses on strictly enforcing directory and path safety across all file-related operations and ensuring consistent validation of the effective working directory:

  • Treat navigation (cd) and filesystem write operations as part of a single security boundary, and re-validate the actual target path at the time of every write, rename, or delete.
  • Maintain an explicit allowlist or denylist of directories, and enforce policies using normalized, absolute paths (e.g., resolving symlinks, .. segments, and environment variables before checking).
  • Require explicit, context-rich user confirmation for any operation targeting protected or internal directories, regardless of how the working directory was reached.
  • Design file APIs as higher-level, safe operations (e.g., "edit this known project file") instead of raw shell-like command streams where possible.
  • Run tooling with the principle of least privilege, ensuring that the effective account and process do not have broader filesystem access than necessary for normal operation.

How teams detect issues like this

Detection can focus on both source-level patterns and behavioral signals:

  • Static analysis / code review:
  • Look for places where the working directory is updated separately from path validation, especially where security decisions depend on a presumed location.
  • Identify direct use of shell-style commands (cd, touch, echo > file) that are not wrapped by a central, policy-enforcing file API.
  • Flag logic that checks directory permissions only at the start of a sequence, without re-checking at the time of the actual write.
  • Runtime and logging:
  • Enable detailed logging of file operations in protected directories, including when they occur, what command sequence caused them, and whether a user confirmation was recorded.
  • Monitor for anomalous writes to internal folders (e.g., .claude and similar) initiated via automated agent actions.
  • Policy enforcement:
  • Use centralized helpers or middleware that intercept all file operations, enforcing directory protections irrespective of higher-level tool logic.
  • Integrate automated security tests that attempt navigation plus write sequences to confirm that protections cannot be bypassed.

Sources

SourceLink
github.comgithub.com/anthropics/claude-code/security/advisories/GHSA-66q4-vfjg-2qhh

Frequently asked

questions

Exploitation depends on how Claude Code is used and integrated. An attacker must be able to influence the content or instructions within the Claude Code context window (for example, via shared snippets, malicious prompts, or integrations) so that the tool executes a crafted sequence of cd and write operations.

The attacker needs logical access to shape what Claude Code sees or executes—typically the ability to contribute text, commands, or code to the session. They do not need direct shell access, but they do rely on the tool executing filesystem-affecting operations on their behalf.

The most robust fix is to centralize all file operations behind a strict policy layer that:

  • Always resolves and normalizes target paths.
  • Enforces allow/deny rules on the final resolved location.
  • Requires explicit user confirmation for protected directories,

regardless of how the working directory was set or what prior commands were executed.

Future prevention involves designing agentic tooling with defense-in-depth around filesystem access: avoid raw command execution where possible, model file edits as high-level operations, enforce path checks on every operation, adopt least privilege for the executing environment, and include security-focused tests and reviews for navigation-plus-write scenarios.

Find out what's already
exploitable in your codebase.