/

CVE-2026-39942

Severity:

HIGH RISK

(8.5)

Improper Access Control in Directus File PATCH Endpoint

CVE-2026-39942

Analyzed

Vulnerability type

Category:

Improper Access Control

CWE:

CWE-284, CWE-639

Impact:

Unauthorized File Overwrite and Data Tampering

Severity:

HIGH RISK

(8.5)

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

Directus versions prior to 11.17.0 contain an access control flaw in the PATCH /files/{id} endpoint that allows attackers to control the filename_disk value for stored files.

By pointing this value at the storage path of another user's file, an attacker may overwrite that file's contents and manipulate metadata like uploaded_by, potentially hiding evidence of tampering.

Affected context

This vulnerability arises in Directus deployments where the file management API is exposed and users can call PATCH /files/{id} on file records they can edit.

The issue is most relevant when:

  • Multiple users or tenants share the same file storage backend
  • Filenames and storage paths are not fully isolated per user or tenant
  • Application logic trusts client-controlled filename_disk values to determine on-disk file locations

Under these circumstances, a malicious user can influence where a file is stored on disk and target paths used by other users' files.

Exploit preconditions

  • Attack surface: HTTP API, specifically the PATCH /files/{id} endpoint in Directus.
  • Required access: Ability to authenticate or otherwise gain permission to update at least one file record (or any context in which PATCH /files/{id} is allowed).
  • Trigger point: Sending a crafted PATCH request where filename_disk is set to the storage path used by another user's file, along with optional metadata changes (e.g., uploaded_by).
  • Why exploitation is possible: The server-side implementation does not sufficiently validate or constrain filename_disk relative to the authenticated user or the original file, allowing users to redirect writes to arbitrary file paths within the storage scope and overwrite existing content they do not own.

Why this happens

The core issue is insufficient authorization on a critical file attribute that maps directly to storage paths.

Rather than deriving the storage location on the server from trusted state, the implementation allows a user-controlled parameter (filename_disk) to influence where the file is stored or updated.

This maps to CWE-284: Improper Access Control, as the system fails to enforce ownership or authorization checks when modifying storage paths, and to CWE-639: Authorization Bypass Through User-Controlled Key, because a client-controlled key-like attribute determines access to another user's resource.

Abstractly, the insecure pattern is: exposing an identifier or path that selects a resource in shared storage and letting untrusted clients modify it directly, without re-checking whether the caller is allowed to affect the underlying resource or its metadata.

Potential impact

  • Overwriting another user's file content, potentially destroying important data.
  • Tampering with shared assets such as images, documents, or configuration-like files stored in Directus.
  • Manipulating metadata (e.g., uploaded_by) to obscure who performed the change and hinder forensic analysis.
  • Undermining data integrity guarantees across tenants or user groups sharing the same storage.
  • Facilitating more complex attacks that rely on replacing trusted content (e.g., malicious documents or swapped media assets).

General mitigation guidance

Effective mitigation focuses on tightening authorization around file attributes and removing trust from client-controlled storage identifiers.

Recommended design patterns include:

  • Deriving physical storage paths exclusively on the server side, based on immutable properties (such as file IDs or server-generated random names), rather than accepting filename_disk or similar fields from clients.
  • Treating any identifier that maps to shared storage as sensitive, and validating that changes cannot cause cross-user or cross-tenant collisions.
  • Enforcing strict ownership and permission checks whenever a file's location or underlying content is updated, not just when metadata is changed.
  • Separating user-facing metadata (e.g., display filenames) from internal storage identifiers, and ensuring only metadata fields are user-modifiable.
  • Applying least-privilege principles so that users can only modify files they own or are explicitly granted access to, and ensuring that privileged operations are not exposed to regular users.

These patterns reduce the chance that a single misvalidated field can redirect writes to another user's file.

How teams detect issues like this

Detecting this type of issue typically involves reviewing both code paths and runtime behavior around file handling:

  • Static analysis and code review:
  • Search for API endpoints that allow clients to set or modify storage-related fields such as filename_disk, path, or similar identifiers.
  • Flag patterns where client input is concatenated or directly mapped to file system or object-storage keys without server-side derivation.
  • Examine access control logic around file update handlers to ensure authorization is enforced at the resource level, not just at the request level.
  • Policy and architectural review:
  • Establish design guidelines that internal storage identifiers must be immutable and server-controlled.
  • Introduce security review checklists for file upload, update, and delete endpoints to verify ownership checks and path isolation.
  • Runtime monitoring and logging:
  • Log file updates with both logical file IDs and underlying storage paths, and monitor for unexpected cross-user or cross-tenant changes.
  • Use anomaly detection or simple heuristics to identify frequent over-writes of the same path from different users.

Automated review tools and linters configured with custom rules for file access patterns can help surface similar issues early in development.

Sources

SourceLink
github.comgithub.com/directus/directus/releases/tag/v11.17.0
github.comgithub.com/directus/directus/security/advisories/GHSA-393c-p46r-7c95

Frequently asked

questions

Yes. Any remote caller with the ability to reach the Directus API and perform PATCH /files/{id} on at least one file can potentially exploit this, assuming other environmental protections (like network segmentation) do not block access.

The attacker typically needs authenticated access with permission to update file records. They do not need direct access to the underlying storage system; the exploit is carried out through the legitimate API.

The strongest fix is to remove client control over internal storage identifiers such as filename_disk, and ensure that all storage paths are generated and managed solely on the server. Any change that can affect where or how a file is stored should be tightly coupled to ownership checks and server-side logic.

Treat any field that selects or locates a resource (IDs, paths, keys) as sensitive and server-controlled. Implement strict authorization checks on resource updates, keep storage identifiers separate from user-editable metadata, and incorporate security reviews for file and object storage features into your development lifecycle.

Find out what's already
exploitable in your codebase.