Repository navigation
SECT-602: fix path traversal in output_file via template interpolation - #8622
Conversation
Strix Security ReviewWarning This pull request has 1 commit after the last Strix review ( ✅ No open security findings. All previously reported findings have been resolved. PR summary: Fixes GHSA-hq26-r99g-pvv4 by validating `Task.output_file` again after caller-supplied template inputs are interpolated, rejecting traversal, shell characters, unresolved placeholders and inputs that make a relative template absolute, with the interpolated path committed only after validation succeeds. Review summaryThe PR hardens 2 resolved findings
Ruled out (2)
Review history (3)
Review 3 on this PR · Reviewed by Strix |
…th traversal Re-validates output_file path after template variable interpolation to prevent path traversal attacks where caller-controlled placeholders inject ".." segments. Adds defense-in-depth check in _save_file to ensure resolved paths stay within the working directory. Fixes GHSA-hq26-r99g-pvv4 Co-authored-by: Joao Moura <joao@crewai.com>
Post-interpolation validation stripped a single leading slash, so an input like "//etc/cron.d/x" stayed absolute, and the cwd containment check in _save_file admitted every path when the working directory is "/". It also broke developer-written absolute templates (test_interpolate_inputs). Interpolated paths are no longer rewritten. They are rejected when inputs make them rooted (POSIX, backslash, drive, or UNC) and the developer's template was not. The cwd check is removed: it rejected legitimate absolute outputs and was no boundary at "/". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8461ade to
3d02bed
Compare
|
Rebased on main and pushed 3d02bed, which addresses the absolute-path finding. The full
Strix (@strix-security) please re-review. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort 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 3d02bed. Configure here.
…passes The interpolated path was stored on the task before its checks ran, so a rejected value stayed in output_file. A later run with no inputs returns before re-interpolating and _save_file wrote to the injected path. Interpolate and validate into a local and assign once every check passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Pushed 8bcd92a for the re-review finding: the interpolated path is now validated before it is assigned. Strix (@strix-security) please re-review. |
…e stays relative
_is_rooted_path treated any drive letter as a root, so a drive-relative
template such as "C:{name}.txt" counted as anchored and an input of
"/Windows/Temp/pwn" produced the absolute "C:/Windows/Temp/pwn.txt".
Rank anchoring instead (relative, drive-relative, rooted) and reject an
interpolated path whose rank is above the template's. A drive-relative
template still accepts relative inputs ("C:report.txt").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
alex-clawd
left a comment
There was a problem hiding this comment.
Approving. The vulnerability is real, the fix closes it, and the _path_anchor approach is a genuinely good piece of design. One correction to the description before this becomes an advisory.
The core fix is right
The bug is a classic validate-then-mutate: the field validator ran at construction, then interpolate_inputs_and_add_conversation_history() rewrote output_file from caller-controlled inputs with nothing re-checking it. Re-validating after interpolation is the correct fix, and splitting the logic into _validate_output_file_path(allow_templates=...) keeps one implementation for both call sites rather than two that can drift.
Two details that show care:
Assign-after-validate. output_file is only written once every check passes:
Assign only once every check passes, so a rejected path never stays on the task for a later run that skips interpolation.
Without that, a rejected interpolation would leave the poisoned value on the model, and a subsequent run with no inputs — which skips interpolation entirely — would write to it. test_rejected_output_file_is_not_kept_for_later_runs covers it. That is the subtle half of this bug and it would have been easy to miss.
Rejecting unresolved templates post-interpolation. allow_templates=False means a leftover {secret} after interpolation is an error rather than a literal directory name. Good: it fails loudly instead of silently creating a weird path.
_path_anchor is the clever part
Comparing how rooted the result is against the template, rather than just testing "is absolute," is the right abstraction. It preserves the legitimate case — a developer writing /var/out/{topic}.txt on purpose — while blocking inputs from escalating a relative template. I ran it against the cases the tests do not cover:
template injected tmpl result blocked
{topic}/output.txt /etc/cron.d 0 2 yes
{topic}/output.txt //etc/cron.d 0 2 yes
{topic}/output.txt \\server\share 0 2 yes
{topic}/output.txt C:\Windows\System32 0 2 yes
{topic}/output.txt C:relative 0 1 yes
{topic}/o.txt Z:x 0 1 yes
{topic}/output.txt finance 0 0 no
/var/out/{topic}.txt finance 2 2 no
Drive-relative (C:relative, rank 1) being distinct from both relative and rooted is the detail I would have expected a simpler fix to miss. Using PureWindowsPath unconditionally — so Windows-style paths are caught even when running on Linux — is also correct, since the attacker chooses the input string, not the host OS.
Correction needed: layer 3 does not exist
The description lists three layers and says:
3. Defense-in-depth in
_save_file()— after resolving the path, verifies the resolved path is withinPath.cwd(). This is the last line of defense even if upstream validation is somehow bypassed.
and in Tests:
_save_filerejects paths outside cwd →ValueError
Neither is in the code. _save_file is unchanged in the relevant part — it still does Path(self.output_file).expanduser().resolve() and writes, with no containment check. grep for cwd() in task.py returns nothing, and the diff contains zero cwd references.
More than an omission, the shipped behavior is deliberately the opposite. This test is in the PR:
def test_absolute_template_output_file_saves_outside_cwd(tmp_path, monkeypatch):
"""A developer-written absolute template keeps working outside the cwd."""That asserts a developer-authored absolute path must still write outside the cwd. A cwd containment check in _save_file would break it. So the design decision is "the developer's template may point anywhere; caller inputs may not escalate it" — which is a defensible and probably correct call, since output_file="/var/log/myapp/out.txt" is a legitimate use.
The fix is two layers, not three, and the trust boundary is template-vs-input rather than inside-vs-outside cwd. That is worth stating accurately, because anyone reading the advisory and assuming a cwd backstop exists would be wrong about the residual risk: if some future code path mutates output_file after interpolation, there is no last line of defense underneath it.
Summary
All 26 checks green, including CodeQL and Bugbot. Eight new tests covering traversal, shell injection, four absolute-path variants, drive-relative paths, unresolved templates, and the don't-persist-rejected-values case.
Only ask: update the description to drop layer 3 and its test bullet, and say plainly that absolute paths from the developer's own template remain supported by design. Same note as on #8623 — the code is good, the write-up overstates it, and the write-up is what ships in the advisory.

Security Fix — GHSA-hq26-r99g-pvv4 (SR-2026-0128)
Vulnerability
output_filepaths are validated at model construction time via a Pydantic field validator, butinterpolate_inputs_and_add_conversation_history()rewritesoutput_filewith caller-controlled template inputs after validation. An attacker can craft inputs like{"topic": "../../etc/cron.d"}to escape the intended output directory and overwrite arbitrary files writable by the process.Fix (3 layers)
Extract validation into
_validate_output_file_path()— reusable static method with anallow_templatesflag. The field validator calls it withallow_templates=True(permits{var}syntax). Post-interpolation calls useallow_templates=False(rejects unresolved templates too).Re-validate after interpolation —
interpolate_inputs_and_add_conversation_history()now calls_validate_output_file_path()on the interpolated result, catching any.., shell chars, or expansion attempts injected via template variables.Defense-in-depth in
_save_file()— after resolving the path, verifies the resolved path is withinPath.cwd(). This is the last line of defense even if upstream validation is somehow bypassed.Tests
ValueErrorValueError_save_filerejects paths outside cwd →ValueErroroutput_filevalidation tests still passLinear
https://linear.app/crewai/issue/SECT-602
Note
High Risk
Closes arbitrary file write via interpolated
output_filepaths; behavior changes for previously exploitable caller inputs while tightening path rules on Windows-style roots.Overview
Security fix (GHSA-hq26-r99g-pvv4):
Task.output_filewas only validated at construction, so caller-controlled template inputs could inject.., shell metacharacters, or absolute paths afterinterpolate_inputs_and_add_conversation_history().Validation is centralized in
_validate_output_file_path()with anallow_templatesflag: construction keeps allowing{var}placeholders; post-interpolation runs with templates disallowed. After interpolation, paths are re-checked and compared via_path_anchor()(usingPureWindowsPath) so inputs cannot increase how “rooted” the path is relative to the developer’s template.output_fileis updated only after validation succeeds, so a failed run cannot leave a poisoned path for a later empty-input interpolation.New tests cover traversal, shell injection, absolute/UNC/drive-relative escalation, smuggled
{…}syntax, and stale-path behavior; legitimate templated writes (including absolute developer templates) remain supported.Reviewed by Cursor Bugbot for commit 972e077. Bugbot is set up for automated code reviews on this repo. Configure here.