fix(home): fail loud instead of falling back to os.tmpdir in getUserHome - #310
Merged
Conversation
Follow-up to #309. That PR ended getUserHome()'s fallback chain with `|| os.tmpdir()` to guarantee a non-empty path. But callers join the result onto `.teamai/...` to write credentials (api-key.ts) and to resolve and execute a node binary (builtin-hooks.ts resolveCodebuddyNode/resolveWorkbuddyNode), so falling back to a world-writable shared directory is a code-execution and credential-exposure vector: an attacker who can write /tmp/.codebuddy-server/.../node would get their binary run. Throw when none of HOME, USERPROFILE, or os.homedir() resolves instead. The empty-string case os.tmpdir() was guarding against (cwd-relative paths) is also covered by throwing. On any real machine at least one of the three is set, so this path is only reached in pathological contexts (passwd-less uid, `env -i`) where refusing to run is the correct, safe behavior. Update the regression test to assert the throw. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Follow-up to #309
#309 ended
getUserHome()'s fallback chain with|| os.tmpdir()to guarantee a non-empty path. A post-merge security review flagged this as exploitable:builtin-hooks.ts(resolveCodebuddyNode/resolveWorkbuddyNode) scansgetUserHome()for anodebinary and executes it. If the fallback returnsos.tmpdir()(world-writable), an attacker who can drop/tmp/.codebuddy-server/.../nodegets their binary run.api-key.tswrites the API key undergetUserHome()/.teamai/apikey; a/tmpfallback would place credentials in a shared directory.Fix
getUserHome()now throws when none ofHOME,USERPROFILE, oros.homedir()resolves, instead of falling back toos.tmpdir(). The empty-string case thetmpdir()fallback was guarding against (cwd-relative paths) is likewise covered by throwing. On any real machine at least one of the three is set, so this branch is only reached in pathological contexts (passwd-less uid,env -i) where refusing to run is the safe behavior.Test Plan
npx tsc --noEmit— cleannpx vitest run— 2142 passednpm run build— successgetUserHome()throws whenos.homedir()is mocked to''🤖 Generated with Claude Code