How to remove absolute paths from debug strings in release binary

I just noticed the release builds contain lots of absolute file paths in debug strings, like /home/tuxmain/.cargo/registry/src/github.com-1ecc6299db9ec823/yew-0.18.0/src/virtual_dom/vnode.rs.

This leaks information about the build environment, which can be problematic for example in the case the builder wants to stay anonymous when distributing a binary.

The absolute path is not even helpful for debugging if the person who reads the error message is not on the system on which the binary was built. Having the path beginning with .cargo would be enough, or even just yew-0.18.0/src/virtual_dom/vnode.rs. The absolute path would only be used in debug builds or with an option.

Is there a way to do that without stripping all the debug data?

3 Likes

You can use remap-path-prefix.

See also issue 40552 and Cargo issue 5505 for requests to make this the default. They're still open but perhaps there are some other workarounds in the conversation; I didn't read through to check. It's also an area of interest for those who want reproducible builds (e.g. distros), so you could see what they do too.

However, you may want to just set up your development under a dedicated account or other type of sandbox that doesn't have access to your personal information as a general precaution. Even if rustc gets to the point where it never embeds your path, typical Rust development involves automatically fetching dependencies and compiling them (which includes running their build scripts). I.e. there will still be the possibility of information leakage (or other unpleasantness).

3 Likes

Thanks! This works: RUSTFLAGS="--remap-path-prefix $HOME=~"

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.