/

CVE-2026-41082

Severity:

HIGH RISK

(7.3)

Path Traversal (CWE-22) in OCaml opam .install handling

CVE-2026-41082

Analyzed

Vulnerability type

Category:

Path Traversal

CWE:

CWE-24, CWE-22

Impact:

Arbitrary File Overwrite / Filesystem Modification

Severity:

HIGH RISK

(7.3)

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

OCaml opam before version 2.5.1 improperly allows .install files to specify destination paths containing ../, enabling writes outside the intended installation directory.

When a package or repository is malicious or compromised, this can be abused to overwrite files in parent directories on the host system, leading to privilege escalation or environment compromise.

Affected context

The vulnerability occurs in environments where OCaml opam is used to install packages that provide .install files describing where built artifacts should be copied.

It becomes relevant when opam processes an .install field whose destination path includes parent directory traversal sequences such as ../, and opam does not normalize or constrain the resulting target path to a trusted installation root.

The issue is most concerning when users install packages from untrusted sources, third-party repositories, or when source integrity controls are weak, since opam runs under the permissions of the invoking user.

Exploit preconditions

  • Attack surface: The opam package installation mechanism, specifically the handling of .install file destination entries.
  • Required access: Ability to cause opam to process a crafted package, repository, or .install file (e.g., publishing a malicious package, compromising a repository, or convincing a user to install from a custom source).
  • Trigger point: Execution of opam install (or similar commands) that reads and applies the .install directives for file placement.
  • Why exploitation is possible: Opam lacks strict path normalization and enforcement for .install destinations, allowing ../ segments to escape the intended installation root and target arbitrary parent directories within the privileges of the running user.

Why this happens

At its core, this is a classic path traversal flaw in filesystem path handling.

The .install file format allows package authors to specify destination paths for installed artifacts, but opam versions prior to 2.5.1 do not adequately sanitize or canonicalize these paths before using them.

As a result, sequences such as ../ are interpreted by the filesystem as legitimate parent directory navigations, matching CWE-22: Improper Limitation of a Pathname to a Restricted Directory.

Because the vulnerable code trusts relative paths from an untrusted metadata file, it effectively breaks the boundary between the logical installation prefix and the rest of the filesystem.

Potential impact

  • Malicious packages may overwrite files in directories above the intended opam installation path.
  • An attacker could place or replace shell configuration files, scripts, or binaries in user-controlled locations, potentially enabling command hijacking.
  • Local privilege abuse where a user's development environment, PATH, or editor configuration can be manipulated.
  • In multi-user systems, compromise of shared environments or build directories that reside near opam installation roots.
  • Facilitation of further attacks such as credential theft, backdoored tooling, or tampering with application configuration files.

General mitigation guidance

Mitigation typically focuses on constraining file operations initiated from untrusted metadata and reinforcing directory boundaries.

Recommended defensive patterns include:

  • Canonicalizing and normalizing destination paths from .install files before use, resolving . and .. segments and symbolic links.
  • Enforcing strict checks that all computed destination paths remain within a designated installation root or prefix.
  • Treating package metadata (including .install) as untrusted input and applying validation rules that reject absolute paths or parent directory traversal.
  • Running package management and build tooling with least privilege, using dedicated, isolated prefixes where possible.
  • Introducing configuration options or policies that disallow non-standard installation destinations from package metadata.

How teams detect issues like this

Organizations can detect this class of issue by:

  • Implementing static analysis or linting rules for package metadata that flag .install entries containing ../ or absolute paths.
  • Reviewing opam-related code paths for filesystem operations that directly concatenate user-controlled or metadata-derived paths without normalization and boundary checks.
  • Using policy enforcement in CI pipelines to scan repositories and opam packages for suspicious path constructs in .install and similar manifest files.
  • Employing file integrity monitoring on critical directories near opam installation prefixes to detect unexpected modifications tied to package installations.

Sources

SourceLink
github.comgithub.com/ocaml/opam/pull/6897
github.comgithub.com/ocaml/opam/releases/tag/2.5.1
osv.devosv.dev/vulnerability/OSEC-2026-03
lists.debian.orglists.debian.org/debian-lts-announce/2026/04/msg00021.html
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-41082
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2459003
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-41082.json

Frequently asked

questions

It is not remotely exploitable in isolation; exploitation requires a user or automated system to install or process a crafted opam package or repository that includes a malicious .install file.

The attacker must be able to provide or influence the .install file processed by opam, such as by publishing a malicious package, tampering with a repository, or persuading a user to install from an untrusted source. The impact is limited to the filesystem locations writable by the user running opam.

The robust fix is to normalize all destination paths, reject entries that attempt to leave the intended installation root, and treat all metadata-defined paths as untrusted data that must pass strict validation before any file operations occur.

Teams can adopt defensive path-handling APIs, codify directory boundary checks, add automated tests for path traversal attempts, and integrate metadata validators or linters into their package publishing and CI workflows to catch risky path constructs early.

Find out what's already
exploitable in your codebase.