fix(sidecar): prevent path traversal in asset materialization#3316
Merged
danielaskdd merged 2 commits intoJun 24, 2026
Conversation
VectorPeak
force-pushed
the
fix/sidecar-asset-name-boundary
branch
from
June 24, 2026 01:42
32f2d1c to
02c9cbf
Compare
VectorPeak
force-pushed
the
fix/sidecar-asset-name-boundary
branch
from
June 24, 2026 01:54
02c9cbf to
9052859
Compare
Collaborator
|
@codex review |
Contributor
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
VectorPeak
marked this pull request as ready for review
June 24, 2026 02:35
Regression tests for PR #3316: assert parser-suggested asset names are collapsed to a contained basename and that the relative_to containment guard skips any target resolving outside the assets dir. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.
Description
This fixes a path traversal risk in sidecar asset materialization, where parser-provided asset names were used to build filesystem output paths before copying or writing asset bytes.
The vulnerable path is built from an asset directory plus a parser/adaptor-controlled suggested name:
AssetSpec.suggested_nameis not itself a trusted filesystem boundary. If a current or future parser/adaptor supplies a path-like name such as../evil.png,..\evil.png, or an absolute path, the filesystem path resolver can interpret that value as path structure rather than a plain filename. Since the sametarget_pathis then passed toshutil.copyfile()orwrite_bytes(), crafted asset metadata could cause LightRAG to copy or write asset bytes outside the intended<base>.blocks.assets/directory.The concrete impact is file creation or overwrite within the LightRAG process permissions when the target parent directories already exist. That can corrupt generated sidecar output, replace adjacent files, or place attacker-controlled asset bytes in another reachable location. The issue is therefore a path traversal / output path boundary bug at the final sidecar asset write sink.
The sidecar writer is the correct place to enforce this boundary because it is the component that materializes parser-produced assets on disk. Relying on every parser/adaptor to always provide a basename leaves the final write path too permissive.
Changes Made
Checklist
Additional Notes
Evidence:
The issue can be reproduced at the path-construction layer with crafted asset names. This local console reproduction only resolves paths; it does not write files.
Possible call chain / impact:
This PR only changes the final asset output-name boundary in the sidecar writer. It does not change document parsing, chunking, embedding, retrieval, or normal sidecar asset paths for basename-only asset names.
Validation:
.\.venv\Scripts\python.exe -m ruff check lightrag\sidecar\writer.py- passedpre-commit run --files lightrag\sidecar\writer.py- passedgit diff --check upstream/main...HEAD- passed