Repository navigation
Conversation
`${TMPDIR:-/tmp}/remember-doctor-*-resolve-$$` is predictable and shared;
a pre-seeded symlink at that name let an attacker truncate an arbitrary
file the moment the redirection opened it, before doctor.sh wrote or read
a byte. Both sites now use mktemp, matching save-session.sh own
convention (#427).
Co-Authored-By: Max <noreply>
…ass-pin test, and let it run on Windows Two independent reviewers of the #427 commit found the same real gap: scripts/lib-memory-dir.sh:274 and scripts/lib-env-cache.sh:80,195 carry the identical predictable-shared-tempfile-plus-$$ class this fix closed in doctor.sh, and the new class-pin test's literal-text regex cannot see either (both go through an intermediate variable rather than spelling ${TMPDIR:-/tmp} and $$ on the same line). Those two files are outside this issue's assigned scope (doctor.sh and its tests only) and are reported to the maintainer for filing rather than fixed here -- fixing them would double this diff and touches files this task was not given. Two review findings that ARE in scope, fixed here: - changelog.d/427.fixed.md miscounted save-session.sh's existing mktemp uses as five; it is six. Also softened the "pins the class" claim to state plainly that the guard is a text scan, not a dataflow check, and points at the two sites it cannot see. - test_no_script_builds_a_shared_tmpdir_path_from_pid is a pure regex/text scan with nothing platform-specific in it, but the module-level `pytestmark` skipped it on Windows too, alongside the genuinely-POSIX symlink-race test. Split the skip so only the symlink test carries it; the class-pin test now runs (and reports) on all three CI OSes. Co-Authored-By: Max <noreply>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #427.
scripts/doctor.sh built the stderr-capture path for resolve-paths.sh's own errors as
${TMPDIR:-/tmp}/remember-doctor-*-resolve-$$, at two sites (originally lines 102 and 195). That name is predictable from the PID and lives in a shared, often world-writable directory -- TMPDIR is commonly unset on Linux, so this is plain /tmp there. The shell's>redirection follows a symlink and truncates its target on open, before doctor.sh writes or reads a byte, so a pre-seeded symlink at that exact name let an attacker truncate an arbitrary file as the invoking user; the laterrm -fremoved only the symlink, never the already-truncated victim.This predates the current delta -- the identical pattern is already in v0.23.0's own scripts/doctor.sh:107 -- and was surfaced by the round-one release audit of v0.23.0..9f3269e, which reported it
unrankedbecause no row in the ranking table's fix-mechanism list fits a bare predictable-path TOCTOU.Both sites now use mktemp, matching the unpredictable-name convention scripts/save-session.sh already uses in six places elsewhere in this repo.
Tests
tests/test_doctor_predictable_tmp_427.py adds two tests:
Both passed together with the existing doctor.sh test files (49 passed total) after the fix.
Docs
README.md (the repo's only docs_targets entry) was read against this change and needs no update: this is an internal hardening fix to an unpredictable-name choice inside doctor.sh's error-capture plumbing, and nothing about doctor.sh's documented behavior, usage or --json output shape changes.
Diagnostic
The plugin's own doctor.py (the /oss:doctor diagnostic, distinct from this repo's scripts/doctor.sh) has no reference to resolve-paths.sh, mktemp or TMPDIR -- confirmed by grep -- so nothing there needed updating for this change.
Self-review findings
Two independent spawns (an Explore reviewer and oss:auditor) reviewed the first commit and both, independently, found the same real gap: scripts/lib-memory-dir.sh:274 and scripts/lib-env-cache.sh:80,194-195 carry the identical predictable-shared-tmpdir-plus-$$ class this fix closed in doctor.sh, and the new class-pin test's regex cannot see either because both go through an intermediate variable (SYS_TMPDIR, _REMEMBER_ENV_CACHE_FILE) rather than spelling${TMPDIR:-/tmp} and $ $ on the same line. lib-memory-dir.sh's file in particular can hold a live OAuth token per its own adjacent comment, raising this past plain truncation into possible credential disclosure if the planted symlink points somewhere attacker-readable. These two files are outside this issue's assigned lane (scripts/doctor.sh and its tests only, per this session's brief, which named two sibling lanes holding other files) and fixing them here would roughly double this diff with a second, separately-reviewable security fix -- filing them for a follow-up issue instead of bundling them in. Full reproduction is in the agent report's adjacent items.
Two review findings that were in scope got fixed in a second commit: the changelog fragment's off-by-one count of save-session.sh's existing mktemp uses (five, corrected to six), and the new class-pin test's module-level pytest.mark.skipif(win32), which had been skipping the pure regex/text-scan test alongside the genuinely-POSIX symlink-race test -- split so the class-pin test now runs on the Windows CI leg too.
One review finding was judged below the bar for action here: a below-bar reason is that if mktemp itself fails (unwritable TMPDIR, full disk) at either fixed doctor.sh site, the resulting empty redirect target produces the same could_not_resolve/"unknown error" JSON a genuine resolver failure with no stderr would also produce -- a pre-existing ambiguity this fix widens only slightly, with no reachable caller today that needs to tell the two apart, and disambiguating doctor.sh's own error taxonomy is a design decision outside this issue's scope.
Verified by the maintainer
tests/test_doctor_predictable_tmp_427.pyagainstmainat 9f3269e: 2 failed — the symlink race truncates the victim, and the class pin fires ondoctor.sh:102anddoctor.sh:195. Neither test is vacuous.$$.scripts/lib-env-cache.sh:80builds${TMPDIR:-/tmp}/remember-env-${_key}— predictable, in the same shared directory, and not$$-derived, so this pin does not see it. That is not a defect in this pull request: the fix and both tests do what they say. It means the pin should not be read as "no script underscripts/can be raced this way". lib-memory-dir.sh and lib-env-cache.sh carry the same predictable-tmp truncation class #427 fixed, and one of them writes a config that can hold an OAuth token #429 carries that file and the trace that decides how it ranks.git show v0.23.0:scripts/doctor.shcarries the same pattern, so this predates the 0.24.0 delta and is not a regression from anything merged tonight.