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 puborflutter 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
pubpackage extraction process (dart pub/flutter pub) when unpacking package archives into thePUB_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
puboperation (such aspub 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.

