logoalt Hacker News

jakubadamwtoday at 2:30 PM7 repliesview on HN

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...


Replies

abhisektoday at 3:05 PM

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

show 1 reply
swiftcodertoday at 2:50 PM

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)

show 1 reply
Panzerschrektoday at 2:45 PM

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.

show 2 replies
weinzierltoday at 2:47 PM

Sandboxing just build.rs would only be be a minor inconvenience for the attacker, nothing more. The attacker can always as easily compromise the binary you build and as soon as you run it (e.g. in a test) you are owned.

It would be a big pain for many that are in the unfortunate position to really need build scripts, though.

show 3 replies
krautsauertoday at 2:47 PM

https://news.ycombinator.com/item?id=49374811

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

show 1 reply
somattoday at 2:54 PM

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?

burnt-resistortoday at 2:50 PM

Never going to work. Crates must be audited for behavior before use.

show 1 reply