Skip to content

Bug : Path Traversal CWE-22, CWE-23 #120

Closed

Description

@muhammad-hassnain

Hi, and thanks for the crate.

I think pact-plugin-driver is vulnerable to a path traversal (CWE-22 / CWE-23) when it installs a plugin from a remote release: fields from the downloaded pact-plugin.json are joined onto the plugin directory with no .. check, so a malicious plugin repo can create directories and write files outside PACT_PLUGIN_DIR.

Where

1. Directory name — src/plugin_manager.rs (around the create_plugin_dir call, ~line 1082):

// manifest.name / manifest.version come from the remote pact-plugin.json
let plugin_dir = plugins_dir.join(format!("{}-{}", manifest.name, manifest.version));
fs::create_dir(&plugin_dir)?;                          // <- no `..` check
File::create(plugin_dir.join("pact-plugin.json"))?;   // <- manifest written here

A name of ../foo_pwned makes plugin_dir resolve to a sibling of PACT_PLUGIN_DIR, so the directory (and the copied manifest) land outside the directory you configured as the trust boundary.

2. Executable path — src/download.rs (~line 234):

// manifest.entry_point is also attacker-controlled and unvalidated
let path = plugin_dir.join(&manifest.entry_point);    // <- Path::join
let mut file = File::create(&path)?;                  // <- arbitrary write

Because Path::join lets an absolute entry_point replace plugin_dir entirely (and .. escapes it), this sink is the more serious of the two: it is an arbitrary write of attacker-chosen bytes to any path the process can write.

Impact

Installing a plugin from an untrusted or compromised URL can:

  • create a plugin directory outside PACT_PLUGIN_DIR (sink 1), and
  • write an executable to an arbitrary, attacker-chosen location (sink 2) — e.g.
    dropping into ~/.bashrc, a cron file, or a .git/hooks/ entry, which is
    escalatable to code execution.

How to reproduce

I have a small self-contained PoC that drives the real published crate (it depends on pact-plugin-driver = "=1.2.6" and calls the real public install_plugin_from_url; a tiny loopback HTTP server stands in for the release host, so no external network is used). Happy to share it.

It configures PACT_PLUGIN_DIR = sandbox/pact/plugins and serves a manifest whose name is ../foo_pwned:

Before:

pact/
├── plugins/                         <- PACT_PLUGIN_DIR (the only allowed location)
│   └── csv-1.0.0/
│       └── pact-plugin.json
└── victim_config.txt

After install_plugin_from_url(...):

pact/
├── foo_pwned-1.0.0/     <-- ESCAPED (outside plugins/)
│   └── pact-plugin.json
├── plugins/
│   └── csv-1.0.0/
│       └── pact-plugin.json
└── victim_config.txt

Suggested fix

Before building any path from manifest fields, reject name, version, and entry_point whose path contains a Component::ParentDir, RootDir, or Prefix component (or canonicalize the final path and verify it still starts with a canonicalized PACT_PLUGIN_DIR). Validating entry_point is the important one, since that sink allows absolute paths.

Coordination

If this looks right to you I'm happy to open a PR. If I don't hear back I plan to file a RustSec advisory so downstream users get flagged via cargo audit, glad to coordinate timing for when a fix lands.

  • Affected OS: Windows, macOS, Linux

Activity

  1. YOU54F commented on Oct 30, 2026

    @YOU54F
    Member

    Hey,

    Thanks for the report, feel free to raise a pull request, the fix sounds sensible

  2. muhammad-hassnain commented on Nov 6, 2026

    @muhammad-hassnain
    Author
  3. muhammad-hassnain commented on Nov 18, 2026

    @muhammad-hassnain
    Author

    Hi, thanks for accepting my PR #121 , please let me know when you release a new version, so that we can raise an advisory for vulnerable version.

  4. YOU54F commented on Nov 19, 2026

    @YOU54F
    Member

    Not sure yet. I don't think it is a high severity issue, as users are downloading known, vetttable plugins, only from github releases, as those we have pre-specified in a pact plugin index via a pull request. Users can download plugins themselves from any github release, but I would expect them to vet the code first before pulling in plugins. That is as per design, so users can create and publish their own plugins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions