/

CVE-2026-51568

Severity:

HIGH RISK

(8.1)

Path Traversal (CWE-22) in Agentscope write_text_file

CVE-2026-51568

Deferred

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Unauthorized File Write and File Overwrite

Severity:

HIGH RISK

(8.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

A path traversal vulnerability in modelscope Agentscope's write_text_file function may allow an attacker to write or overwrite files outside the intended directory. The issue becomes risky when attacker-controlled file paths reach this function without adequate canonicalization and boundary checks.

Affected context

This issue may occur in Agentscope deployments that expose write_text_file to untrusted or semi-trusted inputs. Risk depends on whether supplied paths are used directly, whether the process has write access to sensitive locations, and whether the application confines file operations to an approved directory.

Exploit preconditions

  • Attack surface: The write_text_file file-writing functionality
  • Required access: Ability to influence the path supplied to the function, directly or through an exposed agent or application workflow
  • Trigger point: File creation or overwrite during text-writing operations
  • Why exploitation is possible: Insufficient path validation may allow a supplied path to resolve outside the intended storage directory

Why this happens

The underlying bug is improper limitation of filesystem paths provided to a file-writing operation. When an application accepts path components without reliably normalizing them and verifying that the resolved destination remains within an approved directory, traversal sequences or equivalent path representations may escape the intended boundary. This behavior maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

Potential impact

  • An attacker may create or overwrite files outside the intended workspace.
  • Sensitive application, configuration, or user files could be modified or damaged.
  • File-based access controls or startup behavior could potentially be affected.
  • The application or host may experience data loss, service disruption, or broader compromise depending on process privileges.

General mitigation guidance

Mitigation generally focuses on reducing trust in caller-supplied paths and enforcing a strong filesystem boundary.

Common defensive patterns include:

  • Resolve and canonicalize candidate paths before use, then verify they remain under an approved base directory.
  • Prefer generated filenames or opaque identifiers over user-controlled paths.
  • Reject traversal components, absolute paths, unexpected separators, and symlink escapes where relevant.
  • Apply allowlisted path policies and constrain file-writing operations to dedicated directories.
  • Run the process with only the filesystem permissions required for its function.
  • Use isolated storage and avoid placing writable workspaces near sensitive application files.

How teams detect issues like this

Organizations commonly detect path traversal risks through:

  • Static analysis for file APIs receiving request, agent, or tool-controlled path values.
  • Code review checks for missing canonicalization, prefix-boundary validation, or symlink handling.
  • Runtime monitoring of writes outside approved directories and unexpected modifications to sensitive files.
  • Policy enforcement requiring allowlisted storage roots and least-privilege filesystem access.

Automated security review tools can help identify untrusted data flows into file-writing functions, but findings should be validated against the deployment's actual path and permission controls.

Sources

SourceLink
gist.github.comgist.github.com/Ro1ME/6f26878766be5712ed504857c54492d7
github.comgithub.com/agentscope-ai/agentscope/issues/1508

Frequently asked

questions

It may be remotely exploitable when an agent, API, or application workflow allows an attacker to influence the path passed to write_text_file. If the function is only used with trusted, fixed paths, practical exposure may be more limited.

The attacker generally needs a way to submit or influence file path values and a reachable execution path that invokes the file-writing function. The impact also depends on the operating system permissions of the running process.

Canonicalize the destination, verify it remains within a dedicated approved directory, reject unsafe path forms, and use least-privilege filesystem permissions.

Treat file paths as untrusted input, use allowlisted storage locations, add path-boundary tests to CI, monitor unexpected filesystem writes, and review all agent or tool interfaces that expose file operations.

Find out what's already
exploitable in your codebase.