News for hackers. Stuff that matters.
Re:Malicious Rust crate Arrayref runs a build-time payload by jakubadamw on Thursday August 20, 2026 @10:30AM (#49375101)
Cargo desperately needs sandboxing for build.rs scripts. It’s been attempted before, but didn’t go very far¹.

¹ https://rust-lang.github.io/goals/2024h2/sandboxed-build-scr...

Re:Malicious Rust crate Arrayref runs a build-time payload by abhisek on Thursday August 20, 2026 @11:05AM (#49375702)
This is exactly what PMG is designed for ie. install/build time process level sandboxing. It currently doesn't support cargo, but I believe the challenges are same.

Here is my learning building PMG:

Sandboxing is good when the workload is predictable, and the goal of sandbox is to guard against exploitation of vulnerabilities, like sandbox protecting chrome tabs (renderers). But unfortunately build scripts are not predictable, at least not in npm/pypi world and I have seen build scripts doing weirdest of the things which is no different from malware. When popular packages do weird things, build breaks and users end up turning off the sandbox. This is a perpetual problem to deal with while building sandbox (or any least privilege solution) to protect unbounded workloads.

https://github.com/safedep/pmg

Re:Malicious Rust crate Arrayref runs a build-time payload by Asraelite on Thursday August 20, 2026 @11:43AM (#49376225)
The "How PMG Works" section on Github does not actually explain how it works
Re:Malicious Rust crate Arrayref runs a build-time payload by throwawayqqq11 on Friday August 21, 2026 @03:16AM (#49384845)
Then extend the list. We need isolated build envs AND deterministic builds, like nix does.

Id like to add project provided runtime capabilities/permissions (eg. apparmor profiles) to the list to.

Maybe the day will come, where projects not providing these things will be considered broken, like nix does.

Re:Malicious Rust crate Arrayref runs a build-time payload by swiftcoder on Thursday August 20, 2026 @10:50AM (#49375441)
build.rs by design can run absolutely anything. There tons of build.rs scripts that invoke a whole-ass C compiler toolchain to build and link C dependencies...

It isn't so much a question of sandboxing build.rs, as fundamentally changing the way that foreign dependencies are integrated into the rust toolchain (i.e. moving from a rust-centric system like Cargo to something more general like buck2)

Re:Malicious Rust crate Arrayref runs a build-time payload by kibwen on Thursday August 20, 2026 @11:43AM (#49376224)
The vast and overwhelming majority of build scripts are building C code, so the other solution is to move away from integrating with C dependencies to native Rust dependencies, in which case adding friction to build scripts would be less noticeable.
Re:Malicious Rust crate Arrayref runs a build-time payload by thayne on Thursday August 20, 2026 @12:26PM (#49376819)
One of rust's strengths is it's ability to interface relatively easily with existing c code without having to rewrite absolutely everything in rust. I don't think that is something we want to give up.
Re:Malicious Rust crate Arrayref runs a build-time payload by 0x457 on Thursday August 20, 2026 @01:19PM (#49377480)
build.rs changes nothing about how easy it is to integrate with C. What does simplify: figuring out how to supply library you need at build time.

Which is the result of how bad dependency managment is outside (i.e. DLL-hell).

Pretty much all other use cases of build.rs can be sandboxed. Well, there is sqlx that wants to connect to database at expansion time to compile check-queries (yew).

Re:Malicious Rust crate Arrayref runs a build-time payload by __david__ on Thursday August 20, 2026 @03:07PM (#49378784)
sqlx at least has the (optional) offline mode, where you "cargo sqlx prepare" once (which wants access to a db) and then you can build in offline mode which typechecks your queries against local files.

Although I suppose that's still doing a lot of shenanigans at compile time. It could be sandboxed pretty well (theoretically). I'd hate to give it up completely though, getting a compile time error when SELECT query params or return values have type mismatches is extremely nice.

Re:Malicious Rust crate Arrayref runs a build-time payload by 0x457 on Thursday August 20, 2026 @03:29PM (#49379035)
sqlx offline mode being opt-in instead of default is what bothers me. You know what else can validate that your queries return what you expect? Integration tests. Shoutout to sqlx for #[sqlx::test] though.
Re:Malicious Rust crate Arrayref runs a build-time payload by __david__ on Thursday August 20, 2026 @03:45PM (#49379251)
I also wish that it would be the default. Integration tests are fine, but they aren't compile time. Elevating them to compile time and using an LSP enabled editor makes it just underline SQL errors before I've even had a chance to run a manual compile let alone a test...
Re:Malicious Rust crate Arrayref runs a build-time payload by 0x457 on Thursday August 20, 2026 @04:16PM (#49379659)
LSP diagnostics is actually what made me switch from compile time check queries. Whole "is db up? are migrations applied?" dance tired me pretty quickly. Its fine if you use sqlite, but anything else gets annoying.
Re:Malicious Rust crate Arrayref runs a build-time payload by robhlt on Thursday August 20, 2026 @01:03PM (#49377280)
Just denying write access outside the build directory and denying network access would go a long way and won't break pretty much any well-behaved build systems.

Any C library that's also packaged by debian supports being built under these conditions because it's required for everything except non-free packages: https://www.debian.org/doc/debian-policy/ch-source.html#main...

Re:Malicious Rust crate Arrayref runs a build-time payload by cesarb on Thursday August 20, 2026 @03:23PM (#49378962)
> Just denying write access outside the build directory and denying network access

As the link you posted mentions, you need a tiny bit more than that: you also need write access to the temporary directory (/tmp and similar). Many build tools temporarily store files there; for instance, unless things have changed since I last looked, if you don't use the -pipe argument the C compiler stores its temporary intermediate files (preprocessor output, assembler input) there.

Re:Malicious Rust crate Arrayref runs a build-time payload by mike_hearn on Thursday August 20, 2026 @01:17PM (#49377460)
Worth noting that the JVM ecosystem doesn't have this issue because there is no notion of installing dependencies, and the package managers are just downloaders with nothing else. No build.rs equivalent.

To solve the problem of native/C dependencies, they just bundle pre-compiled libraries as data files.

Rust could do the same thing.

Re:Malicious Rust crate Arrayref runs a build-time payload by ChrisSD on Thursday August 20, 2026 @02:12PM (#49378133)
But then that shifts the issue. You've now got an opaque binary blob being injected into programs. What if it is malicious?
Re:Malicious Rust crate Arrayref runs a build-time payload by mike_hearn on Thursday August 20, 2026 @05:21PM (#49380447)
It may or may not be a problem depending on whether it's actually used, which is still better than "gets you instantly the moment you compile the app". A lot of codepaths and even whole libraries aren't invoked just because a program depends on them.

It doesn't really matter anyway, because nobody is reading anything in their dependencies before it gets downloaded. Malware can also be hiding in plain sight in source code, as this attack and many others shows.

Re:Malicious Rust crate Arrayref runs a build-time payload by pie_flavor on Thursday August 20, 2026 @02:24PM (#49378289)
ABI stability is significantly different in a VM language to a native language, and reified generics necessarily require source compilation. Binary-only development for Rust would be exactly as 'sort of not really' as C++, for exactly the same reasons. (There is also no notion of 'installing' dependencies in Rust, and build-time code being malicious isn't much worse than runtime code being malicious.)
Re:Malicious Rust crate Arrayref runs a build-time payload by mike_hearn on Thursday August 20, 2026 @05:24PM (#49380472)
But people say build.rs is used mostly to compile C dependencies, in which case the lack of ABI stability of Rust is neither here nor there.
Re:Malicious Rust crate Arrayref runs a build-time payload by pie_flavor on Sunday August 23, 2026 @12:24AM (#49406053)
It's used to do all sorts of things. Rust version probing, bindings generation, precompiling bundled data, etc. The only reason it isn't used to do more is because proc macros do it instead, with an essentially identical execution model and sandboxing situation (ie build scripts in isolation are a red herring).
Re:Malicious Rust crate Arrayref runs a build-time payload by Panzerschrek on Thursday August 20, 2026 @10:45AM (#49375356)
Sandboxing for build scripts can't work properly. If you sandbox too much, some necessary stuff can't be done. If you sandbox too little, it has no practical value.
Re:Malicious Rust crate Arrayref runs a build-time payload by amluto on Thursday August 20, 2026 @12:18PM (#49376717)
As an easy start, how about letting build scripts read /usr, read and write a temporary build directory, have some /tmp scratch space, and be allowed to write its final output artifact. No network and otherwise isolated from the rest of the system.

I would argue that, if a build script doesn’t work in the setting, then it doesn’t deserve to be installable by a default cargo command.

Re:Malicious Rust crate Arrayref runs a build-time payload by kibwen on Thursday August 20, 2026 @03:18PM (#49378914)
Cargo is a cross-platform tool, so when it ships a sandboxing solution it will need to be a cross-platform solution, and because this is a security feature it needs to be bulletproof, so no half-measures like Docker. Something like a WASM runtime might fit the bill, though that will be much easier to get working for typical proc macros than for typical build scripts. If you only care about Unix, then you can do this yourself today by building code in your sandbox of choice.
Re:Malicious Rust crate Arrayref runs a build-time payload by amluto on Thursday August 20, 2026 @03:50PM (#49379314)
> Cargo is a cross-platform tool, so when it ships a sandboxing solution it will need to be a cross-platform solution

This seems like an excuse, not an actual objection.

Linux can do seccomp or Landlock or gVisor or a combination. Seccomp and gVisor need no privileges. Windows has its internal weird mechanisms. Mac has sandbox-exec.

Cargo could easily pick an appropriate sandbox for each major platform and ship it by default.

> If you only care about Unix, then you can do this yourself today by building code in your sandbox of choice.

This is ridiculous. The sandbox should not have network access, but cargo needs network access to download the package in the first place.

Re:Malicious Rust crate Arrayref runs a build-time payload by kibwen on Thursday August 20, 2026 @11:11PM (#49383292)
> Windows has its internal weird mechanisms.

If you have a serious proposal, then I encourage someone to seriously propose it. Cargo is an understaffed open source project that, like the rest of the Rust project, relies largely on volunteers. However, gesturing to unspecified internal weird mechanisms does not strike me as a serious proposal worthy of consideration by anyone, so I'd suggest working on that first.

> The sandbox should not have network access, but cargo needs network access to download the package in the first place.

Naturally. Use `cargo fetch` to download a package locally without invoking any build step: https://doc.rust-lang.org/cargo/commands/cargo-fetch.html

Re:Malicious Rust crate Arrayref runs a build-time payload by lobofta on Thursday August 20, 2026 @11:30AM (#49376039)
So let each build script define its own level of sandboxing and then users can determine whether they are okay with that level or not, e.g. `cargo build --sandbox-level=...`
Re:Malicious Rust crate Arrayref runs a build-time payload by jurgenburgen on Thursday August 20, 2026 @12:04PM (#49376496)
That’s not solving the problem, that’s avoiding it by making it the users fault if they make a mistake.
Re:Malicious Rust crate Arrayref runs a build-time payload by kibwen on Thursday August 20, 2026 @03:21PM (#49378946)
Rust, like C, C++, and every other systems programming language, is all about giving users the power to make mistakes. The philosophical difference when it comes to Rust is simply that it tries to force the user to flip off the safety on the gun before letting you shoot yourself in the foot. A Cargo config option letting people opt-out of sandboxing would be fully in line with Rust's philosophy.
Re:Malicious Rust crate Arrayref runs a build-time payload by jurgenburgen on Friday August 21, 2026 @01:49AM (#49384265)
Having a dangerous flag as a backwards compatibility flag is okay. I don’t think making users decide between multiple levels of sandboxing is constructive, they will just be trained to ignore it.

This is the kind of decision users likely don’t understand without looking at the source code of a crate and it’s bad UX to push it to be their responsibility.

Re:Malicious Rust crate Arrayref runs a build-time payload by kibwen on Sunday August 23, 2026 @12:10AM (#49405994)
No, the flag would not exist simply for backwards compatibility, it would exist because build scripts are occasionally necessary and there are plenty of legitimate uses for them, even if they should be opt-in.
Re:Malicious Rust crate Arrayref runs a build-time payload by somat on Thursday August 20, 2026 @10:54AM (#49375501)
I mean sure, but anything the build script could do, the build artifact could also do, That is to say, if you don't trust your source why do you trust the thing it compiles into?
Re:Malicious Rust crate Arrayref runs a build-time payload by burnt-resistor on Thursday August 20, 2026 @10:50AM (#49375435)
Never going to work. Crates must be audited for behavior before use.
Re:Malicious Rust crate Arrayref runs a build-time payload by Aeolos on Thursday August 20, 2026 @10:56AM (#49375533)
cargo add + rust-analyzer instantly executes build.rs before you have a chance to audit the code.

Cargo, please PLEASE give me a way to disable third-party build.rs and whitelist the ones I need. And please loudly mark any update that adds a build.rs where there was none before.

Re:Malicious Rust crate Arrayref runs a build-time payload by praseodym on Thursday August 20, 2026 @11:45AM (#49376247)
cargo-deny can audit build scripts, but unfortunately not prevent execution of malicious build scripts exactly for the reason you gave. It could still help if you only ever use cargo add and update in a sandbox.

See https://embarkstudios.github.io/cargo-deny/checks/bans/cfg.h...

Re:Malicious Rust crate Arrayref runs a build-time payload by bigstrat2003 on Thursday August 20, 2026 @01:05PM (#49377299)
So, don't add dependencies before you audit the code? That seems like a pretty reasonable ask to me.
Re:Malicious Rust crate Arrayref runs a build-time payload by Aeolos on Thursday August 20, 2026 @06:21PM (#49381066)
You audit the code, then you run cargo update and you are pwned. Asking the user to not make mistakes is the c++ approach to security - it doesn’t work.
Re:Malicious Rust crate Arrayref runs a build-time payload by burnt-resistor on Saturday August 22, 2026 @03:10PM (#49402813)
You're creating a strawman. Don't run cargo update without verification, duh.

> Asking the user to not make mistakes is the c++ approach to security

Then demand crates.io do better by actually curating every version of every published crate.

Re:Malicious Rust crate Arrayref runs a build-time payload by burnt-resistor on Thursday August 20, 2026 @02:02PM (#49378028)
Safe-ish recommendation: Only add well-known, trusted crates. Failing that, treat unknown crates as malware or containing malware dependencies until proven otherwise. Test untested tools/crates in a VM/dev container to be sure they work properly before trust them. Use Mark I eyeball and Mark III brain too. :)

Audit and limit crates (cargo-deny &| cargo-crev, && --offline) until tools exist to audit build.rs safety semi-automatically ($$ safeguard.sh maybe).

The root problem is two parts:

1. crates.io doesn't do mandatory curation. Lack of curation is fail. It's time-consuming and costly for reviewers without a doubt, but so is letting an ecosystem gain maximum entropy (go to shit) by Tragedy of the Commons depending entirely on the honor system. Name squatting, low-quality, unmaintained, typosquatting, and malware are the consequences of too much self-service / semi-self-service freedom.

2. Many, many cargo subcommands are over-eager to run build.rs because it assumes trusted crates:

In an untrusted/uncurated crates world and a build.rs exists or exists in a selected dependency, it shouldn't run at cargo-add time (unless it must). If it exists, on first run, it should be presented to the user in a viewer for manual review unless a magic CLI flag/env var is specified to accept it.

These 2 factors combined appear to create a Swiss cheese holes failure mode for running arbitrary crate `cargo add`. I have confidence a suitable add-in workflow &| standard command &| repository workflow will be adjusted to reduce the attack surface of the ecosystem.

Re:Malicious Rust crate Arrayref runs a build-time payload by pie_flavor on Thursday August 20, 2026 @02:25PM (#49378309)
You can disable rust-analyzer running build scripts.
Re:Malicious Rust crate Arrayref runs a build-time payload by weinzierl on Thursday August 20, 2026 @10:47AM (#49375398)
Sandboxing just build.rs would be be a minor inconvenience for the attacker but a big pain for many that are in the unfortunate position to really need build scripts.
Re:Malicious Rust crate Arrayref runs a build-time payload by Aurornis on Thursday August 20, 2026 @11:21AM (#49375909)
I imagine it would be sandboxed by default with an escape hatch to run build scripts outside of the sandbox with user verification. It makes people stop and think about what’s happening. Not perfect, but it does help. When working on JS ecosystem projects I manually approve build scripts and spend some time researching dependencies with build scripts to see if I can avoid running the build script. Some people will ignore it and run everything, but it’s a huge step in the right direction to make it operator-decided.
Re:Malicious Rust crate Arrayref runs a build-time payload by insanitybit on Thursday August 20, 2026 @10:52AM (#49375475)
It would be more than a minor inconvenience. I can handle sandboxing my tests and production infra, but I can't handle sandboxing build scripts because I don't own that code in any sense.
Re:Malicious Rust crate Arrayref runs a build-time payload by kibwen on Thursday August 20, 2026 @11:46AM (#49376278)
At the very least, it wouldn't be overly onerous when adding a dependency that requires a build script to require an opt-in via Cargo.toml, e.g. `build-script = true`. You'd make it viral so that any transitive dependency that requires a build script would affect its parent, then add the key as defaulting to `true` so as to not break backwards-compatibility, then switch the default to be more restrictive over a new edition. (This same key could be used to prevent proc-macros from having arbitrary system access as well, where by default proc macros could be compiled to WASM and run in a WASM sandbox and treated as pure functions.)
Re:Malicious Rust crate Arrayref runs a build-time payload by klabb3 on Friday August 21, 2026 @06:47AM (#49386250)
100% agree. Wow I can’t believe how many think sandbox builds is an actually good idea, on a per language basis too. There are completely standard QoL issues in cargo that have been open for years and nobody is working on. Maintaining a sandbox for idk 3 operating systems minimum that have virtually no sandboxing support? For extremely diverse workloads that typically invoke commands? I mean.. good luck.

There are still elephants (or rather mammoths) in the room for supply chain security, such as having 1500 nested deps for a standard project. It’s like we never woke up from the nightmare of leftpad.

If your project had code from 100s of individuals, new versions can be pushed instantly, and nobody wants to review the code, then you have a time bomb. And also other problems.

Re:Malicious Rust crate Arrayref runs a build-time payload by krautsauer on Thursday August 20, 2026 @10:47AM (#49375384)
https://news.ycombinator.com/item?id=49374811

(Oh and btw, proc macros also run arbitrary code.)

Re:Malicious Rust crate Arrayref runs a build-time payload by quotemstr on Thursday August 20, 2026 @10:59AM (#49375602)
There's no good reason a proc macro can't run in a no-IO sandbox by default. None. Doesn't require a language change. Doesn't require some microvmcapabilityeffect BS. It requires looking people straight in the eye and saying "no" when they complain about needing to prompt for privileges.
Re:Malicious Rust crate Arrayref runs a build-time payload by krautsauer on Saturday August 22, 2026 @09:04AM (#49399338)
No good reason? Here's a list: https://github.com/dtolnay/watt#remaining-work

(It mostly boils down to "somebody needs to do it". I'd really like proc macros precompiled to wasm by crates.io…)

Re:Malicious Rust crate Arrayref runs a build-time payload by quotemstr on Saturday August 22, 2026 @05:16PM (#49403961)
WASM is totally unnecessary. Vanilla seccomp is sufficient and runs at full performance. What is it with people trying to stick WASM in places it's not needed?
Re:Malicious Rust crate Arrayref runs a build-time payload by krautsauer on Monday August 24, 2026 @10:48PM (#49428529)
I'd argue that this kind of thing is easier to implement securely and cross-platform with wasm (of course, a performant wasm engine is its own source of complexity).

wasm has the additional benefits of allowing something like pre-compiling binaries once on a central server and thus skipping the CPU cycles for compiling all the macro crate dependencies on every crate compile. So even the people who don't care much about the security benefits have a reason. I'm kind of the "don't care about security" side because (as said elsewhere) it's trivial (https://docs.rs/ctor/latest/ctor/) for any macro to insert code that will run when compiled binaries/tests are run. You need the entire thing in a sandbox anyway, not just the macros, and that's something that can't be provided by cargo by default.

Re:Malicious Rust crate Arrayref runs a build-time payload by IshKebab on Thursday August 20, 2026 @01:15PM (#49377435)
I think it would be a good start if crates at least had to opt in to a build script, and adding one later would require permission from crates that depends on it.

The vast majority of crates don't need build scripts, so it is vaguely feasible to audit the list of crates you use that might need them.

Re:Malicious Rust crate Arrayref runs a build-time payload by bhickey on Thursday August 20, 2026 @02:11PM (#49378131)
I'd like to see a "no-build" option to blocks depending on crates using build.rs
Re:Malicious Rust crate Arrayref runs a build-time payload by sempron64 on Thursday August 20, 2026 @02:26PM (#49378313)
Sandboxing is a mitigation but a very limited one. The library itself can contain a malicious payload -- rust code most often ends up as native code executed on the host.

I think we may need to enter a world where there are fewer, heavily audited, libraries and dependency depth is limited. Allowing unvetted dependencies to be installed by default is not a good way forward. App stores have a similar problem and I think a lot of lessons have been learned there that can be applied.

Re:Malicious Rust crate Arrayref runs a build-time payload by k_roy on Thursday August 20, 2026 @02:50PM (#49378573)
That world can’t exist unfortunately, because the minute someone wants a feature that isn’t in your core libraries, you just create a new library and we’re back to now.
Re:Malicious Rust crate Arrayref runs a build-time payload by 7373737373 on Thursday August 20, 2026 @02:43PM (#49378492)
That's why languages need sandboxing at runtime as well
Re:Malicious Rust crate Arrayref runs a build-time payload by josephg on Thursday August 20, 2026 @06:04PM (#49380874)
Yes, or the compile time equivalents. Rust’s safety gets you most of the way there. We just need a capability model in the language, a more limited std and a way to ban untrusted 3rd party libraries from using unsafe code without explicit permission. I dream of a world where a function with the signature of add(u32, u32) -> u32 can’t burn my house down and steal my wife.

Functions should only have access to their arguments. Nothing more. We need to end ambient authority.

Re:Malicious Rust crate Arrayref runs a build-time payload by nh2 on Friday August 21, 2026 @08:03AM (#49386836)
You have just reinvented "Safe Haskell" from 2012.

It guarantees that pure functions are pure.

https://www.microsoft.com/en-us/research/publication/safe-ha...

https://downloads.haskell.org/ghc/latest/docs/users_guide/ex...

Re:Malicious Rust crate Arrayref runs a build-time payload by josephg on Friday August 21, 2026 @08:17AM (#49386969)
Oooh I didn't know that was a thing!

Yes, I want this but in a fast, compiled systems language like rust.

Re:Malicious Rust crate Arrayref runs a build-time payload by tome on Friday August 21, 2026 @08:47AM (#49387297)
Haskell is a fast, compiled systems language like Rust (or rather, Rust is like Haskell).
Re:Malicious Rust crate Arrayref runs a build-time payload by josephg on Friday August 21, 2026 @09:10AM (#49387561)
Are you sure about that? My understanding is that Haskell programs generally run much more slowly than their C counterparts because of all of Haskell’s magic. Like lazy evaluation and memoisation and however Haskell manages memory.

Rust certainly borrows from Haskell. Like all good languages. But I’m not aware of Haskell beating rust in program performance & memory usage benchmarks.

SeL4 was first written in Haskell and proven correct in Haskell. Then, with a great many years of effort, ported to C and proven correct there. If Haskell were a viable systems language, I suspect the kernel would not have been converted to C.

Re:Malicious Rust crate Arrayref runs a build-time payload by tome on Friday August 21, 2026 @09:30AM (#49387805)
Yes, I'm sure about that. I said that it is a systems language, not that it is as fast as C! I don't mind if your terminology excludes Haskell from being a systems language, as long as it also excludes Go. They are both managed, garbage collected, fast languages.

> Like lazy evaluation and memoisation

Yes, that causes performance impact. If you don't want the performance impact then don't write code that uses those behaviors. Sure, that rules out large parts of the ecosystem, but I said Haskell was a systems language not that its ecosystem was generally suitable for systems programming.

> however Haskell manages memory

No, Haskell's memory manager is world class, with two (at least) tunable garbage collectors.

> But I’m not aware of Haskell beating rust in program performance & memory usage benchmarks

Nor am I!

> If Haskell were a viable systems language, I suspect the kernel would not have been converted to C.

I suspect they converted it to C because you can't write a kernel in a managed language with a garbage collector.

Re:Malicious Rust crate Arrayref runs a build-time payload by 2OEH8eoCRo0 on Thursday August 20, 2026 @03:41PM (#49379192)
How many times do we need to learn that sandboxing won't magically save us.