Skip to content

fix(core): fail closed when the account has no home to trust - #9768

Open
Kiko0301 wants to merge 1 commit into
crewAIInc:mainfrom
Kiko0301:fix/eval-handshake-no-home-fallback
Open

Kiko0301 wants to merge 1 commit into
crewAIInc:mainfrom
Kiko0301:fix/eval-handshake-no-home-fallback

Conversation

@Kiko0301

Copy link
Copy Markdown
Contributor

Fixes #9764

Summary

eval_handshake promises that a project's .env cannot move the folder its eval token is read from, because the folder comes from the account database and never from HOME. _account_home broke that promise when the account database has no entry for the process's uid: it suppressed the KeyError from pwd.getpwuid(os.getuid()) and fell back to Path.home(), which reads $HOME on POSIX. Running an arbitrary uid without a passwd entry is standard in containers (OpenShift, docker run --user 1001), so a project .env could set HOME (plus CREWAI_EVAL_AWAITING_RUN) and a checked-in token file under it made an ordinary crewai run upload its trace as if crewai eval had started it - with nobody having asked. crewai_cli.crew_run_tui._awaiting_dir, the CLI's copy of the same lookup, had the same fallback.

Changes

  • lib/crewai-core/src/crewai_core/eval_handshake.py
    • _account_home: on POSIX, stop suppressing a failed account-database lookup; raise OSError instead of returning Path.home(). Update its docstring and awaiting_dir's.
  • lib/cli/src/crewai_cli/crew_run_tui.py
    • _awaiting_dir: same change, so crewai eval also never writes its marker under a folder a .env chose.
  • lib/crewai-core/tests/test_eval_handshake.py
    • Add tests for an account the database does not know: awaiting_dir() raises OSError; a token planted under the HOME the process would otherwise read is not read (awaited_evaluation() is None); awaiting_evaluation() yields False and leaves no variable behind.

Both existing call sites already handle OSError (awaited_evaluation returns None, and awaiting_evaluation/evaluating_after_run suppress it), so the failure is fail-closed: no file is read or written.

Verification

  • With the fix: pytest lib/crewai-core/tests/test_eval_handshake.py -> 20 passed, 1 skipped (the skip is the POSIX-only real-home test on Windows); pytest lib/cli/tests/test_crew_run_tui.py -> 144 passed.
  • Against the base revision of eval_handshake.py (new tests kept): all three new tests fail - the first because awaiting_dir() returns the planted home instead of raising, the second because the planted token is read and the run is marked awaited, the third because the context manager reports the mark as taken.

AI assistance

I used an AI coding agent to investigate, implement, and test this change, and reviewed its results. Per CONTRIBUTING.md, please apply the llm-generated label; external contributors cannot add it with my current permissions.

eval_handshake promises that a project's .env cannot move the folder
the eval token is read from, because it comes from the account database
rather than HOME. But _account_home suppressed a missing passwd entry
and fell back to Path.home(), which is $HOME on POSIX: in a container
running an arbitrary uid, a .env that sets HOME and a token file
committed under it made an ordinary crewai run upload its trace as if
crewai eval had started it.

Raise OSError instead when the account database cannot name this
account's home; both call sites already read that as "no evaluation is
waiting". The crew_run_tui copy of the lookup gets the same treatment.
@strix-security

strix-security Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Strix Security Review

✅ No open security findings.

PR summary: When the host has no account-database entry for the process's uid (common in containers), the eval-handshake token folder used to fall back to `$HOME`, which a project's `.env` can set; the PR now fails closed by raising `OSError` from `_account_home` and the CLI's `_awaiting_dir`, with tests for that case.

Review summary

Reviewed the fail-closed change to the eval handshake. The PR stops _account_home (crewai-core eval_handshake.py) and the CLI's _awaiting_dir (crew_run_tui.py) from falling back to Path.home() when the account database has no entry for the process's uid, raising OSError instead, so a project's .env can no longer pick the folder the CREWAI_EVAL_AWAITING_RUN token file is read from. I traced every consumer of both lookups: awaited_evaluation/awaiting_evaluation (core), evaluating_after_run/_an_evaluation_is_waiting (CLI), and the runtime gate in crewai/execution.py, events/listeners/tracing/utils.py and telemetry/tracing/ephemeral.py; in each case the new OSError lands on the closed side (no marker read, no marker written, no environment variable set), so a run that cannot be verified is treated as not started by crewai eval. No exploitable vulnerability was confirmed in the changed code or in the paths it reaches. Two non-blocking hardening notes came out of the analysis but are not vulnerabilities: neither lookup requires the account database's home to be non-empty and absolute (an empty home field would yield a working-directory-relative marker folder, though no project input can produce such an entry), and the tests added only simulate a missing entry, not an unusable one.

Ruled out (6)
  • Can a project still choose the eval-token folder when the account database reports an empty or relative home field?
    The enabling condition is the victim account's passwd home field, which the attacker cannot set and which standard account tooling and images never produce, while the no-entry case the PR targets now fails closed.
  • Can a project shadow the account-database lookup with a checked-in `pwd` module or a `.env`-supplied PYTHONPATH?
    `pwd` is a statically linked builtin C module resolved by BuiltinImporter ahead of any `sys.path` entry, so a project file or path setting cannot substitute it and the genuine passwd home is returned.
  • Does the Windows branch or the leftover `Path.home()` return let the environment move the marker folder?
    `awaiting_dir` returns early via appdirs on Windows (which resolves the known-folder API, not `$LOCALAPPDATA`), and the trailing `Path.home()` in `_account_home` is unreachable from any caller.
  • Does removing the marker now hand the saved AMP login and the run's trace to a project-chosen host?
    That permissive branch predates the PR and is reachable from a plain run without any marker, so the change adds no caller or input to the credential path; an attacker who controls the project's `.env` already controls that project's code.
  • Can a project's `.env` still redirect `crewai eval --run`/`export` to its own AMP host?
    That request path lives in `experimental/eval_crew.py`, which the PR neither changes nor reaches, follows the project's URL by documented design while withholding the saved login, and grants no capability the same attacker lacks from the project's own runnable code.
  • Can a `.env` re-enable inline Python execution for a data-only declarative flow?
    The gate and the `.env` loading live in code the PR does not change or reach, and the same principal authors both the flow definition and the `.env`, so no trust boundary is crossed.

Review 1 on this PR · e725fee · requested Nov 25 05:24 UTC when the PR was opened


Reviewed by Strix
Re-run review · Configure security review settings · Try a deeper review with @strix-security /deep

This branch has not been deployed

No deployments
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.

[BUG] The eval handshake falls back to $HOME when the account has no passwd entry

1 participant