[rajarshidattapy] fix: resolve workspace paths with realpath to block symlink escape (#135)#138
Open
rajarshidattapy wants to merge 1 commit into
Conversation
…symlink escape (openswarm-ai#135) The Output file endpoints (serve/seed/write/delete) gated paths with a lexical os.path.normpath prefix check, which does not resolve symlinks — a symlink inside a workspace redirected the read/write/delete outside it. - Add safe_workspace_path(): one realpath-based containment helper (both sides realpath'd, `+ os.sep` boundary), returning None on escape. - Route serve_workspace_file, the seed writer, write_workspace_file, and delete_workspace_file through it, replacing the three divergent normpath checks. Also closes the sibling-prefix collision (abc vs abc-evil) the serve/seed paths lacked. - Add tests/test_outputs_workspace_path_traversal.py (symlink cases skip where the OS forbids symlink creation). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Fixes #135.
The Output workspace file endpoints (
serve,seed,write, anddelete) validated paths using a lexicalos.path.normpath()prefix check. Becausenormpath()does not resolve symbolic links, a symlink placed inside a workspace could cause read, write, or delete operations to follow the link outside the workspace root.Changes
safe_workspace_path()helper that:os.path.realpath()os.sepboundary checknormpath-based validation implementations.abcvs.abc-evil) that previously affected theserveandseedpaths by enforcing proper directory-boundary checks.Validation
tests/test_outputs_workspace_path_traversal.py.