Skip to main content

installed_version_in

Function installed_version_in 

Source
fn installed_version_in(dir: &Path, npm_package: &str) -> Option<String>
Expand description

Version of a managed provider install, read from the installed package’s own package.json. None for anything unreadable — a missing directory, a partial install, unparseable JSON — all of which mean “we do not know”, which is a distinct answer from “up to date” and must stay distinct.

npm_package becomes a path segment, so the join goes through crate::backend::base::safe_join_within_base rather than an ad-hoc check. An earlier revision hand-rolled the validation (empty / .. / leading / / leading \ / NUL) and missed the Windows drive-letter form: PathBuf::push("C:\\Users\\…") REPLACES the whole path rather than appending, so npm_package = "C:\\Users\\Victim\\AppData" escaped the install dir entirely and read an attacker-chosen package.json (ReAgent P1 on #3350). That helper already rejects drive-letter and drive-relative prefixes, UNC roots, rooted paths and .., and accepts both separators — which is exactly why it exists and why this must not grow a second copy of the same reasoning.

Scoped names (@scope/name) are legitimate and produce one nested directory; the helper splits on / and \ and handles them.

dir is the install whose shim install.check resolved: the version is read from that same install, never from another dir’s leftover manifest — otherwise a shared dir with a manifest but no shim would lend its version to the legacy binary actually in use and hide drift (Codex P2 on #3927).