Skip to content

fix(cd): search CDPATH for empty OLDPWD to match POSIX and Bash 5.3 - #790

Open
privatenumber wants to merge 2 commits into
mainfrom
fix/cd-oldpwd-cdpath
Open

privatenumber wants to merge 2 commits into
mainfrom
fix/cd-oldpwd-cdpath

Conversation

@privatenumber

@privatenumber privatenumber commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

comparison-tests has been failing on main and all PRs since ubuntu-latest rolled from ubuntu-24.04 (Bash 5.2) to ubuntu-26.04 (Bash 5.3) between Nov 16 and Nov 20:

FAIL src/comparison-tests/cd.comparison.test.ts
  uses the live OLDPWD value: cd /; CDPATH=/tmp; OLDPWD=; cd -; pwd
  Expected (recorded bash): "/tmp\n/tmp\n"
  Received (BashEnv):       "\n/\n"

In Bash 5.3 (builtins/cd.def), cd - searches CDPATH when $OLDPWD is not an absolute pathname (matching POSIX cd step 5 and dash), whereas Bash <= 5.2 skipped CDPATH on cd -. cd.ts had a target !== "" guard added in #439 for Bash <= 5.2.

Changes

  • packages/just-bash/src/interpreter/builtins/cd.ts: remove the target !== "" guard from the CDPATH lookup so cd - with an empty OLDPWD searches CDPATH (while keeping cwd unchanged and printing an empty line when CDPATH is unset or does not match).
  • packages/just-bash/src/interpreter/builtins/cd.test.ts: cover both CDPATH=/tmp (/tmp\n/tmp\n) and unset CDPATH (\n/home/user\n) with empty OLDPWD.
  • packages/just-bash/src/comparison-tests/fixtures/cd.comparison.fixtures.json: re-record the fixture on Bash 5.3.

Verification

  • RECORD_FIXTURES=1 pnpm --filter just-bash test:comparison src/comparison-tests/cd.comparison.test.ts (10 passed)
  • pnpm --filter just-bash test:comparison src/comparison-tests/cd.comparison.test.ts (10 passed)
  • pnpm --filter just-bash test:run src/interpreter/builtins/cd.test.ts (13 passed)
  • pnpm typecheck (passed)
  • pnpm lint (passed)

@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
just-bash-website Ready Ready Preview, v0 Dec 3, 2026 1:25pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
just-bash Ignored Ignored v0 Dec 3, 2026 1:25pm UTC

@vercel vercel Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional findings

  1. packages/just-bash/src/interpreter/builtins/cd.ts:57-62 — With an empty OLDPWD and CDPATH=:/tmp, the newly enabled lookup skips the current-directory entry and incorrectly makes cd - change to /tmp.

    Fix on Vercel

  2. packages/just-bash/src/interpreter/builtins/cd.ts:57-62 — Removing the empty-target guard also makes CDPATH=/tmp; cd "" change directory to /tmp, although Bash 5.3 rejects an explicit empty operand without changing directory.

    Fix on Vercel

@privatenumber privatenumber changed the title fix(cd): search CDPATH for empty OLDPWD and pin comparison CI runner fix(cd): search CDPATH for empty OLDPWD to match POSIX and Bash 5.3 Dec 3, 2026
@auto-maintain

auto-maintain Bot commented Dec 3, 2026

Copy link
Copy Markdown

🤖 auto-maintain review

Automated, advisory triage for @privatenumber's PR. Facts below are read from the GitHub API.

Check Result
Author's merged PRs (this repo) 28
Account established ✅ (age 5549d · 3993 followers · 162 public repos)
Commits signed/verified ✅ 2/2
Changeset included ⚠️

Review panel: 🟡 medium highest severity

just-bash maintainer code review: 🟢 low

No actionable issues found in the complete base-to-head diff.

General code review: 🟡 medium

The empty-OLDPWD fix mishandles ordered CDPATH lists containing empty entries.

  • packages/just-bash/src/interpreter/builtins/cd.ts:66 — Empty CDPATH entries are discarded, so with an empty OLDPWD, `CDPATH=:/tmp; cd -` skips the leading current-directory match and incorrectly changes to `/tmp`. Preserve empty entries as `.` so CDPATH ordering matches POSIX/Bash.

Adversarial security: 🟡 medium

The new path mishandles empty CDPATH entries and can change into a lower-priority directory.

  • packages/just-bash/src/interpreter/builtins/cd.ts:66 — CDPATH parsing drops empty entries, so the new empty-OLDPWD path skips the required current-directory candidate: `CDPATH=:/tmp; OLDPWD=; cd -` selects `/tmp`, while POSIX/Bash treat the leading empty field as `.`. This can redirect subsequent relative filesystem operations; preserve empty fields as current-directory entries.

Adversarial security (second opinion): 🟢 low

Benign three-file change: removing the `target !== ""` guard in cd.ts only widens CDPATH lookup to empty targets, which matches real bash behavior (verified `cd ""` with CDPATH set does search CDPATH and print the resolved dir), and introduces no new trust-boundary crossing since CDPATH/OLDPWD are already shell-controlled and all paths still go through the sandboxed ctx.fs component checks. The fixture edit changes only one stdout value with the SHA-keyed fixture id and command string untouched, and the CI runner pin from the intermediate commit was reverted so the net diff touches no workflow, dependency, install-script, network, or process-execution surface. No backdoor, obfuscation, or intent/behavior discrepancy found.

Standard Bash and host portability: 🟢 low

No actionable Bash or host-portability issues found.

Posted by auto-maintain. This automated code review is advisory; a human maintainer makes the call.

This branch was successfully deployed

1 active deployment
Preview – just-bash-website — 268de7c5 Deployed Dec 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant