Security advisory for Cargo

41 points by freddyb


mk12

I was recently working on a program that writes out a bunch of directories and files, and learned how tricky it is to avoid following symlinks on files that already exist in the destination (which would make you write to an arbitrary location). You want to follow symlinks for the initial path the user gives, but never after that, using O_NOFOLLOW (or RESOLVE_NO_SYMLINKS if you’re passing an entire subpath instead of just one more component). But there is no way to replace an existing symlink in one step, so to do that atomically you need to create a temporary file and then rename it.

Just checked the CVE now and, yup, it’s symlink related. I sometimes wonder if symlinks were a mistake.

cmcaine

Tar is kind of notorious for this. I remember the Julia tar package was written carefully to avoid these surprising behaviours (and it deliberately does not support all the features of the format)