Skip to content
Misconfiguration Disclosed report Intermediate CVE-2023-38497

Cargo not respecting umask when extracting crate archives

Cargo extracted crate archives without applying the umask, so files marked as globally writeable in an archive stayed globally writeable on disk. Another local user could then modify a dependency's source code, which would be compiled and run by the victim.

addisoncrump Follow

Originally disclosed on HackerOne

Bounty$4,660 High 7.9 View original
  • Triaged in 4 days
  • Fixed in 12 days
  • Paid in 12 days
  • Disclosed after 12 days

Summary by the program

Cargo not respecting umask when extracting crate archives

Description The Rust Security Response WG was notified that Cargo did not respect the umask when extracting crate archives on UNIX-like systems. If the user downloaded a crate containing files writeable by any local user, another local user could exploit this to change the source code compiled and executed by the current user.

This vulnerability has been assigned CVE-2023-38497.

Overview In UNIX-like systems, each file has three sets of permissions: for the user owning the file, for the group owning the file, and for all other local users. The "umask" is configured on most systems to limit those permissions during file creation, removing dangerous ones. For example, the default umask on macOS and most Linux distributions only allow the user owning a file to write to it, preventing the group owning it or other local users from doing the same.

When a dependency is downloaded by Cargo, its source code has to be extracted on disk to allow the Rust compiler to read as part of the build. To improve performance, this extraction only happens the first time a dependency is used, caching the pre-extracted files for future invocations.

Unfortunately, it was discovered that Cargo did not respect the umask during extraction, and propagated the permissions stored in the crate archive as-is. If an archive contained files writeable by any user on the system (and the system configuration didn't prevent writes through other security measures), another local user on the system could replace or tweak the source code of a dependency, potentially achieving code execution the next time the project is compiled.

Acknowledgments We want to thank Addison Crump for responsibly disclosing this to us according to the Rust security policy.

Full GHSA link: https://github.com/rust-lang/cargo/security/advisories/GHSA-j3xp-wfr4-hx87

The report

Cargo did not properly protect files in the cargo registry. When an archive contained files which were marked as globally writeable, they would be unpacked as-is and retain their global writeability. This is CWE-278 (not available in HackerOne).

This was discovered as part of a (personal) routine file permissions check:

Shell
find / ! -type l -perm -002 -exec ls -alhd {} \;

Impact

A local attacker may inject arbitrary code into the cached files present in the cargo registry. This, in turn, allows for a local attacker to act as the targeted user (when the user compiles the modified code) or to poison prebuilt binaries built by that user and thus have arbitrary code execution against downstream users (supply chain attack).

The original report as published on HackerOne, by addisoncrump. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Impact

A local attacker could inject code into cached crate files, acting as the victim when they compile, or poisoning prebuilt binaries for downstream users; this only works if the archive contains globally writeable files and no other system measure blocks writes.

What the attacker needed

Local access to the same machine; a crate with globally writeable files; no other system write protection

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

On Unix systems, every file has permissions saying who may read or change it, and a setting called the umask trims dangerous permissions when files are created. Cargo, the tool that downloads Rust libraries, unpacked those libraries while keeping whatever permissions were stored inside the archive. If a library's files were marked as changeable by anyone on the machine, another user on that machine could edit them, and the victim would then build and run the altered code.

What is Misconfiguration?

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.

More by addisoncrump

View all

1 more disclosed report, best first.

More from Internet Bug Bounty

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Security misconfiguration

The lesson behind this report.

Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.