Skip to content

Predictable, PID-based temp paths in vendor/bundle/init scripts (not mktemp) — race/symlink exposure #282

Description

@codeforester

Summary

Several scripts build temp file/dir names from the process PID in the same writable directory as the final target, instead of using mktemp.

Details

  • scripts/vendor:74,95,112,153temporary="${destination}.tmp.$$" / .failed.$$
  • scripts/library-bundle:84
  • bin/base-bash:439 (__base_bash_libs_launcher_init_emit__) — temporary="${output_path}.base-bash-init.$$"

These scripts mkdir -p/redirect into the PID-based path before an atomic mv. This is the classic insecure-temp-file pattern (predictable name, no O_EXCL/noclobber, symlink/race exposure) that lib/bash/std/lib_std.sh deliberately avoids elsewhere via mktemp + base_std_register_cleanup_path (e.g. lib_std.sh:3251-3288) and the noclobber-guarded log sink (lib_std.sh:956-962).

Impact

A local attacker who can pre-create ${destination}.tmp.$$ (or predict/race the PID) can redirect where vendored code lands.

Suggested fix

Use mktemp -d/mktemp for these staging paths, or at minimum plain mkdir (not -p) so a pre-existing path fails closed.

Metadata

Metadata

Assignees

Labels

bugSomething is not workingsecuritySecurity hardening or vulnerability work

Type

No type

Projects

Status
Triage

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions