[WRONG BRANCH] fix(config): avoid untrusted process lookup in PID validation - #174
[WRONG BRANCH] fix(config): avoid untrusted process lookup in PID validation#174luvs01 wants to merge 1 commit into
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
This pull request currently targets @luvs01 Please retarget this PR to Its title has been prefixed with This pull request is being kept as a draft automatically. Once every issue above is resolved, it will be marked ready for review again. |
📝 WalkthroughWalkthrough
ChangesProcess lookup hardening
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/config.test.ts`:
- Around line 1713-1717: Ensure the PATH mutation in the test setup is always
covered by the existing try/finally cleanup: move writePid(process.pid) before
assigning process.env.PATH, or move the PATH assignment and writePid call
together inside the try block. Preserve restoration of the previous PATH on
every setup failure path.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: c2701915-a897-44a7-99db-38f1d1ac2ee7
📒 Files selected for processing (2)
src/config.tstests/config.test.ts
| const previousPath = process.env.PATH; | ||
| process.env.PATH = `${attackerDir}:${previousPath ?? ""}`; | ||
| writePid(process.pid); | ||
|
|
||
| try { |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Keep PATH cleanup around all setup that follows the mutation.
Line [1714] changes the process-wide PATH, but Line [1715] calls writePid before the try at Line [1717]. If writePid throws, the finally block does not run and later Bun tests inherit the attacker directory in PATH. Move writePid before the PATH assignment or place both operations inside the try.
Proposed fix
const previousPath = process.env.PATH;
-process.env.PATH = `${attackerDir}:${previousPath ?? ""}`;
-writePid(process.pid);
-
try {
+ process.env.PATH = `${attackerDir}:${previousPath ?? ""}`;
+ writePid(process.pid);
expect(readPid()).toBeNull();As per path instructions, tests are flat Bun tests under tests/, so process-wide PATH state must be restored on every setup path.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const previousPath = process.env.PATH; | |
| process.env.PATH = `${attackerDir}:${previousPath ?? ""}`; | |
| writePid(process.pid); | |
| try { | |
| const previousPath = process.env.PATH; | |
| try { | |
| process.env.PATH = `${attackerDir}:${previousPath ?? ""}`; | |
| writePid(process.pid); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@tests/config.test.ts` around lines 1713 - 1717, Ensure the PATH mutation in
the test setup is always covered by the existing try/finally cleanup: move
writePid(process.pid) before assigning process.env.PATH, or move the PATH
assignment and writePid call together inside the try block. Preserve restoration
of the previous PATH on every setup failure path.
Source: Path instructions
Motivation
Description
readProcessCommandLineinsrc/config.ts./proc/<pid>/cmdlineinstead of spawningps.SystemRoot\System32\wbem\WMIC.exepath and fall back to PowerShell atSystemRoot\System32\WindowsPowerShell\v1.0\powershell.exerather than invokingpowershell.exeby name./bin/psby absolute path instead ofpsto avoid PATH resolution.tests/config.test.tsthat injects a fakepsearlier inPATHand assertsreadPid()does not execute it, and importreadPidfor the test.Testing
bun test tests/config.test.ts; the focused suite passed (117 tests passed).bun run typecheck(bun x tsc --noEmit) which succeeded.bun run privacy:scanwhich succeeded.bun run testand observed unrelated pre-existing failures intests/server-management-auth.test.ts(HTTP expectations returned 403); the failures are not introduced by this focused change.Codex Task
Summary by CodeRabbit
PATHfrom being used during process identification.