fix: address low-priority review items from Bun→Node migration#991
Conversation
|
4e26519 to
cfac9d3
Compare
There was a problem hiding this comment.
Shell injection in Bun.which() polyfill via unquoted command interpolation
The Bun.which() polyfill builds a shell string by directly interpolating command — command -v ${command} on Unix and where ${command} on Windows — and passes it to execSync, which invokes /bin/sh -c (or cmd.exe). A command value containing shell metacharacters (;, $(...), backticks) would execute arbitrary code. The safe pattern is already in src/lib/which.ts: use execFileSync("/bin/sh", ["-c", 'command -v "$1"', "--", command], ...) so command is never interpolated into the shell string.
Evidence
execSync(cmd, ...)atscript/node-polyfills.ts:93passes a string, which Node.js runs via/bin/sh -con Unix, making it vulnerable to metacharacter injection.cmdis built on line 85 as`command -v ${command}`with no sanitization ofcommand.src/lib/which.ts:51-57shows the correct fix already exists in the codebase:execFileSync("/bin/sh", ["-c", 'command -v "$1"', "--", command])passescommandas a positional arg, never interpolated.globalThis.Bun = BunPolyfill(end of polyfill file) installs this as the globalBun.which, reachable by any future caller in the bundled runtime.- Tests call
Bun.which("node")/Bun.which("realpath")with hardcoded strings only, so no current caller exercises a malicious payload.
Identified by Warden find-bugs
197f251 to
c0d1fea
Compare
Codecov Results 📊✅ 7014 passed | Total: 7014 | Pass Rate: 100% | Execution Time: 1ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 85.71%. Project has 14253 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 77.11% 77.09% -0.02%
==========================================
Files 322 322 —
Lines 62167 62211 +44
Branches 0 0 —
==========================================
+ Hits 47938 47958 +20
- Misses 14229 14253 +24
- Partials 0 0 —Generated by Codecov Action |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c0d1fea. Configure here.
c0d1fea to
9d5d998
Compare
1. Remove dead SQLite polyfill code (NodeDatabasePolyfill + bunSqlitePlugin) — replaced by src/lib/db/sqlite.ts 2. Fix which polyfill: use 'command -v' (POSIX builtin) instead of 'which' binary, add 5s timeout to prevent indefinite blocking 3. Add stream cleanup to bspatch BufferedStreamReader: cancel() method + cleanup in applyPatch finally block 4. Fix scanner TOCTOU: use single fs.promises.open() file handle for atomic read + stat (content and mtime from same handle) 5. Add CI check (check:patches) to detect when pnpm patchedDependencies target versions diverge from installed versions Closes #990
9d5d998 to
2e73b04
Compare

Context
Addresses all 5 cleanup items from #990 — low-priority review items deferred during the Bun → Node.js migration.
Changes
1. Remove dead SQLite polyfill code
NodeDatabasePolyfill,NodeStatementPolyfill, andbunSqlitePolyfillfromscript/node-polyfills.tsbunSqlitePluginfromscript/bundle.tssrc/lib/db/sqlite.tswhich handles both runtimes directly2. Fix
whichpolyfill — timeout +command -vwhichbinary tocommand -v(POSIX shell builtin) on Unix — works with restricted PATHtimeout: 5000toexecSynccall to prevent indefinite blockingwhere(nocommand -vequivalent)3. Add stream cleanup to bspatch
BufferedStreamReadercancel()method toBufferedStreamReaderthat callsreader.cancel()andreader.releaseLock()applyPatchfinally block to clean updiffReaderandextraReaderon error pathsDecompressionStreamstate4. Fix scanner TOCTOU
readFile()thenstat()calls with a singlefs.promises.open()file handleisRegularFile()pre-check to avoid blockingopen()on FIFOs (1Password guard)5. Add CI check for patched dependency versions
script/check-patches.ts— compares patch file target versions against installed versionscheck:patchesscript topackage.json.github/workflows/ci.ymlAlso updated
.lore.mdto fix a stale reference to the non-existentsrc/lib/which.ts.Closes #990