fix(server): restrict HTTP file read/list to allowed paths#46
Open
y4sol wants to merge 1 commit intoAgentFlocks:mainfrom
Open
fix(server): restrict HTTP file read/list to allowed paths#46y4sol wants to merge 1 commit intoAgentFlocks:mainfrom
y4sol wants to merge 1 commit intoAgentFlocks:mainfrom
Conversation
Validate paths only at GET /api/file/content and /api/file/list via resolve_path_for_http_file_access. - Add http_file_read_guard: project root (no unsafe cwd fallback), data, workspace, allowReadPaths, small safe system file allowlist; block config, ~/.ssh, /proc|/sys|/dev; use assert_sandbox_path for symlink-safe containment. - ConfigInfo.allow_read_paths with alias allowReadPaths. - find_flocks_project_root() for strict discovery; find_project_root() delegates for backward compat. - Map PermissionError to HTTP 403.
972b351 to
e8a493b
Compare
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.
Summary
Restricts filesystem access through
GET /api/file/contentandGET /api/file/listby validating paths only in the HTTP routes. InternalFile.read()callers (e.g. memory under user data directories) are unchanged.Problem
Clients that could reach the API could read arbitrary local files the server process could open.
Solution
flocks/utils/http_file_read_guard.pywithresolve_path_for_http_file_access():.flocks/, without falling back to cwd as a project root when none exists), configured data directory, workspace directory, optionalallowReadPathsentries (validated), and a small built-in allowlist for common safe host files (e.g./etc/hostswhen they exist).~/.ssh, and on POSIX/proc,/sys,/dev.assert_sandbox_pathfor containment and symlink checks.flocks/server/routes/file.pyfor/contentand/list;PermissionError→ HTTP 403.ConfigInfo.allow_read_pathswith Pydantic aliasallowReadPathsfor JSON config.find_flocks_project_root()(returnsNoneif no.flocksancestor);find_project_root()keeps backward-compatible behavior for non-security callers.Configuration
Optional extra paths in user config, e.g.
~/.flocks/config/flocks.json:{ "allowReadPaths": ["/opt/myapp/config"] }