Skip to content

Reject file keys that escape the workspace in inject_files - #1476

Open
Tech Guy (lukiod) wants to merge 1 commit into
microsoft:mainfrom
lukiod:fix/inject-files-path-traversal
Open

Reject file keys that escape the workspace in inject_files#1476
Tech Guy (lukiod) wants to merge 1 commit into
microsoft:mainfrom
lukiod:fix/inject-files-path-traversal

Conversation

@lukiod

@lukiod Tech Guy (lukiod) commented Sep 2, 2026

Copy link
Copy Markdown

Fixes #1473

FBWorkspace.inject_files joined the caller's file keys directly onto
workspace_path and wrote/deleted the result with no containment
check, so a key such as "../escape.txt" (or an absolute path)
resolved to a location outside the workspace.

Resolves the workspace root once, resolves each candidate path against
it, and raises ValueError before either the write or the delete
branch runs if the resolved path is not inside the workspace root.

Added test_inject_files_rejects_paths_outside_workspace to the
existing test/utils/test_ws.py (rather than a new top-level test
file) since that is already this class's real home. It covers ordinary
and nested relative files still working, a ../ key, an absolute-path
key, and the DEL_KEY delete branch against a file that already
exists outside the workspace.

Verified: the new test fails with AssertionError: ValueError not raised against the code on main (reverted the fix locally, kept the
test, reran it) and passes with the fix applied. test/utils/test_ws.py
(2 tests, including the pre-existing checkpoint-roundtrip test) passes
in full: 2 passed in 0.04s. ruff check on both changed files is
clean relative to main — the only pre-existing lint items in
test_ws.py (unittest-style assertions, os.readlink) are unrelated
and already present before this change, left untouched.

Not in scope here: FBWorkspace.remove_files has the identical
self.workspace_path / file_name pattern with no containment check.
Flagging it since it's the same root cause, but leaving it out of this
PR since the issue is scoped to inject_files — happy to send a
follow-up if that's wanted.


📚 Documentation preview 📚: https://RDAgent--1476.org.readthedocs.build/en/1476/

FBWorkspace.inject_files joined keys supplied by the caller onto
workspace_path with no containment check, so a key like "../escape.txt"
(or an absolute path) wrote or deleted outside the workspace once
resolved. Resolve the workspace root once, resolve each candidate path
against it, and reject anything not relative to the root before either
the write or delete branch runs.

Fixes microsoft#1473
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: FBWorkspace.inject_files can write files outside workspace_path

1 participant