Skip to content

doctor.sh --json writes stderr to a predictable temp path instead of mktemp #427

Closed

Description

@fdaviddpt

Found by the round-one release audit of v0.23.0..9f3269e. The auditor reported it unranked -- it classified the finding and no row in the ranking table fits. unranked is not the same as minor, and the missing row is worth weighing separately from the fix.

Symptom

doctor.sh --json writes its stderr to a path an attacker can predict and pre-seed, so a symlink at that name truncates an attacker-chosen file as the invoking user.

Location

scripts/doctor.sh:102-106:

_JSON_RESOLVE_ERR_FILE="${TMPDIR:-/tmp}/remember-doctor-json-resolve-$$"

then 2>"$_JSON_RESOLVE_ERR_FILE".

Mechanism

The shell opens a redirection target following symlinks. On Linux, where TMPDIR is commonly unset, /tmp is shared and the name is $$ -- guessable. A pre-seeded symlink there redirects the write and truncates the target; the rm -f afterwards removes only the symlink.

Provenance, stated rather than absorbed: this is a duplication, not a new introduction. git show v0.23.0:scripts/doctor.sh carries the identical pattern at its line 107, so it predates this delta. The rest of the codebase does it correctly -- save-session.sh uses mktemp "${TMPDIR:-/tmp}"/remember-...-XXXXXX in five places.

Why no row fits

The auditor's reasoning, kept because it is the useful half: containment (write)'s fix sends a reviewer to "which repository did the caller mean", and the target here is not an argument. destroys's fix sends them to a destructive call with an unvalidated argument, and there is none. misreports does not apply -- nothing is misreported. The fix this actually invites is "route every temp file through mktemp", which no existing row sends a reviewer to.

What would settle it

Replace both sites with mktemp, matching save-session.sh. A guard test that no script under scripts/ builds a temp path from $$ would pin the class rather than the instance. Separately: whether the ranking table wants a row for predictable-temp-path, which is a decision about the table and not about this file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority:medium

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions