/

CVE-2026-27704

Severity:

HIGH RISK

(7.5)

Path Traversal in Dart and Flutter SDKs

CVE-2026-27704

Analyzed

Vulnerability type

Category:

Path Traversal / Directory Traversal

CWE:

CWE-22

Impact:

File System Manipulation within PUB_CACHE

Severity:

HIGH RISK

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

A path traversal vulnerability in the Dart and Flutter pub client allows a crafted package archive to extract files outside the intended package directory in the PUB_CACHE.

Under specific conditions involving malicious archives with symlinks, an attacker may overwrite or create files elsewhere in the cache hierarchy, potentially impacting the development environment.

Affected context

This issue affects environments using vulnerable versions of the Dart SDK (prior to 3.11.0) and Flutter SDK (prior to 3.41.0) when interacting with package archives that contain symlinks leading outside the intended extraction directory.

The risk is primarily relevant when:

  • Packages are obtained from untrusted or unvetted sources, or
  • An attacker can influence the package archive content before it is extracted by dart pub or flutter pub.

Users who rely exclusively on packages from pub.dev or from trusted repositories that do not host malicious content are significantly less exposed to this issue.

Exploit preconditions

  • Attack surface: The pub package extraction process (dart pub / flutter pub) when unpacking package archives into the PUB_CACHE.
  • Required access: Ability to supply or control a malicious package archive (e.g., via a compromised third-party repository, local file replacement, or tampered dependency source).
  • Trigger point: Running a pub operation (such as pub get, pub upgrade, or dependency resolution) that downloads and extracts the crafted package containing symlink-based paths.
  • Why exploitation is possible: The extraction logic previously trusted archive paths and symlinks without fully normalizing and verifying the final resolved path, allowing files to be written outside the target extraction directory through directory traversal via symlinks.

Why this happens

The underlying bug class is path traversal (CWE-22) arising from incomplete validation of file system paths during archive extraction.

The pub client resolved entries from a package archive and wrote them into the PUB_CACHE based on their declared paths, but did not robustly normalize and constrain the resolved destination path to the intended package directory before writing.

Malicious archives could exploit symlinks combined with upward path components so that, once resolved, the actual write target pointed outside the package directory.

This pattern reflects an insecure assumption that archive entries and symlinks are benign, rather than treating them as untrusted input that must be resolved against a strict root and verified before file I/O.

Potential impact

  • Overwriting or creating files in directories adjacent to the intended package directory within PUB_CACHE.
  • Injecting unexpected files that may influence future package resolution, caching, or build behavior.
  • Potentially altering local development tooling configuration files located within or near the cache hierarchy.
  • Enabling follow-on attacks if overwritten files are later executed, interpreted, or trusted by other tools.

General mitigation guidance

Effective mitigation focuses on enforcing strict path handling and minimizing trust in archive content:

  • Normalize and resolve archive entry paths (including symlinks) against a fixed root directory and reject any that attempt to escape this root.
  • Disallow or tightly restrict symlinks in package archives, or treat them as plain files with duplicated content instead of honoring link semantics.
  • Introduce central abstractions for safe extraction that encapsulate path normalization, canonicalization, and boundary checks, and reuse them across all unpacking code paths.
  • Reduce the impact of any miswrites by running development tooling with the least privileges necessary and ensuring file permissions in cache and tooling directories are constrained.
  • Encourage teams to consume packages only from vetted sources and to review third-party package intake processes for potential supply-chain risks.

How teams detect issues like this

Detection can combine code-level checks with operational monitoring:

  • Use static analysis rules or code scanning to flag file extraction logic that joins user-controlled or archive-controlled paths without canonicalizing and verifying them against an allowed base directory.
  • During code review, look for archive extraction loops that:
  • Directly concatenate paths,
  • Honor symlinks from untrusted archives, or
  • Omit explicit checks that realpath/canonical paths remain under an expected root.
  • Add unit and integration tests that attempt to extract deliberately malformed archives containing symlinks and .. segments, verifying that files are not written outside the target directory.
  • Employ security-focused CI tooling or SAST products that understand filesystem traversal patterns and can flag directory traversal risks in extraction utilities.

Sources

SourceLink
github.comgithub.com/dart-lang/pub/commit/26c6985c742593d081f8b58450f463a584a4203a
github.comgithub.com/dart-lang/sdk/security/advisories/GHSA-q739-79rh-vmvp

Frequently asked

questions

It can be, if the developer environment or build system automatically downloads and extracts packages from a source that an attacker can control or influence (for example, a compromised repository or tampered package feed). If all package sources are trusted and vetted, practical exploitability is significantly reduced.

The attacker must be able to provide or modify a package archive that will be processed by dart pub or flutter pub. This could be via a malicious package in an untrusted registry, a man-in-the-middle scenario affecting downloads, a compromised internal mirror, or local tampering with package files before extraction.

The most robust fix is to canonicalize every target path (including symlink resolution) and enforce that the final path remains inside a predefined root directory, rejecting any entry that attempts to escape that root. Additionally, either prohibit symlinks in archives altogether or handle them in a way that does not allow redirection outside the extraction boundary.

Teams can adopt secure file-handling abstractions for all archive and package extraction operations, enforce mandatory code review for any path or filesystem utility logic, and add regression tests with malicious archives. Combining these practices with supply-chain hygiene—such as relying on vetted registries, verifying package integrity, and monitoring dependency sources—helps prevent recurrence of directory traversal and related file system vulnerabilities.

Find out what's already
exploitable in your codebase.