Skip to content

fix(artifacts): ensure monotonic versioning and isolate extensions in LocalArtifactStore - #9600

Open
Rishabh Bafna (RishabhIIITD) wants to merge 1 commit into
crewAIInc:mainfrom
RishabhIIITD:fix/local-artifact-store-version-isolation
Open

Rishabh Bafna (RishabhIIITD) wants to merge 1 commit into
crewAIInc:mainfrom
RishabhIIITD:fix/local-artifact-store-version-isolation

Conversation

@RishabhIIITD

Copy link
Copy Markdown

Related issue

Fixes #9599

Summary

LocalArtifactStore.save previously computed the next version number as len(list(directory.glob("v*.*"))) + 1.

When earlier artifact versions were pruned or removed (e.g., v1.html was deleted to retain only v2.svg), and a subsequent artifact was saved with a different file extension (e.g. .png), path.open("xb") did not raise FileExistsError because the existing file had a different extension. As a result, two different files were written with the identical version number (e.g., v2.svg and v2.png), causing load() to overwrite and lose access to one of the versions.

This fix:

  1. Derives the next version number monotonically using max(existing_versions, default=0) + 1 from parsed integer versions (path.stem[1:].isdigit()).
  2. Checks that version does not collide with ANY existing extension (any(directory.glob(f"v{version}.*"))) before attempting to write.
  3. Adds unit test test_local_store_version_isolation_with_pruned_versions_and_extension_changes.

Verification

  • Tests added or updated for the changed behavior

  • Relevant tests and quality checks pass locally

  • Added test_local_store_version_isolation_with_pruned_versions_and_extension_changes in lib/crewai/tests/test_artifacts.py.

  • All 76 tests in test_artifacts.py pass (100% pass rate).

  • ruff format and ruff check verified.

Additional context

None

… LocalArtifactStore

- Parse numeric versions monotonically to avoid collisions when earlier versions are pruned
- Check for existing version numbers across all file extensions before writing
- Add unit test verifying version isolation when prior versions are removed
@strix-security

strix-security Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Strix Security Review

✅ No open security findings.

PR summary: `LocalArtifactStore.save` now picks the next artifact version from the highest surviving integer version plus one and skips any number already taken by another file extension, instead of counting files in the directory; a regression test covers pruned versions combined with an extension change.

Review summary

The PR replaces the file-count-based version number in LocalArtifactStore.save with max(existing integer versions) + 1 and adds a pre-write check that no file with that number exists under any extension, plus a regression test. I reviewed the whole changed module and its callers (save_artifact, SaveArtifactTool._run, Task._save_artifact, load_artifact) and traced the new parsing, the collision loop, the exclusive create, and the load() lookup. No security vulnerability was confirmed: the change narrows rather than introduces version aliasing, the new int() parse can only fail on filenames the store itself cannot produce, and the residual gaps (number reuse after an explicit delete, a non-atomic check-then-create across different extensions) stay inside a single run's own artifact directory with no attacker or cross-user boundary.

Ruled out (4)
  • Can a pruned highest version number be handed out again, so a previously returned version reference silently resolves to different bytes?
    Reuse requires first deleting a file inside the artifact root, which already lets that same principal overwrite the very version whose identity is at stake, and no cross-user or cross-tenant consumer of execution id plus version exists.
  • Can two concurrent saves of one identifier with different extensions both claim the same version number and make one version unreachable?
    The non-atomic glob check and exclusive create are real, but both writers and the only reader are the same run, `open("xb")` never overwrites the other file's bytes, and the pre-change code had the same count-then-write window.
  • Can a filename with non-ASCII or over-long digits make every later save and load raise ValueError?
    The `isdigit()`/`int()` mismatch reproduces in isolation, but the store always writes `v<int>.<suffix>` names, no other code writes into that directory, filenames are bounded far below the digit-conversion limit, and every caller catches the failure and logs it.
  • Can an unvalidated execution id in LocalArtifactStore.save write artifact versions outside the artifacts root?
    That path join sits on unchanged lines; the new code only enumerates entries inside the directory the join already produced, and the execution id is supplied by the embedding host's own code rather than untrusted remote input.

Review 1 on this PR · 5bc591e · requested Nov 20 10:09 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] LocalArtifactStore assigns duplicate version numbers when earlier versions are pruned or extensions differ

1 participant