Repository navigation
security: fix path injection CodeQL alerts (#1721) - #2101
Conversation
- Extend autobot-shared/security/path_validator.py with validate_relative_path() - Validates user-controlled paths resolve within allowed base directories - Prevents directory traversal attacks (../../etc/passwd) Foundation for fixing 64 path injection CodeQL alerts in #1721
- Add path validation to files.py, data_storage.py, filesystem_mcp.py, logs.py, session.py, git_mcp.py - Validate user-controlled paths against allowed base directories Resolves 47 of 64 path injection CodeQL alerts for #1721
- Add path validation to terminal_secrets_service, vnc_manager, reports, prompts, chat_sessions, chat_knowledge, ownership, environment, fast_document_scanner, secure_sandbox_executor Resolves remaining 17 of 64 path injection CodeQL alerts for #1721
✅ SSOT Configuration Compliance: Passing🎉 No hardcoded values detected that have SSOT config equivalents! |
Code Review: security: fix path injection CodeQL alerts (#1721)Good approach centralizing path validation via CRITICAL: Incomplete coverage in
|
…th (#1721) Convert 7 endpoints from is_path_allowed() (bool check on raw path) to _validated_path() (returns resolved safe path for all fs operations): - _read_single_file_for_batch: preserves error-dict contract - create_directory_mcp: os.makedirs uses safe_path - list_directory_mcp: os.listdir + os.path.join use safe_path - move_file_mcp: validates both source + destination - search_files_mcp: os.walk uses safe_path - directory_tree_mcp: recursive walk uses safe_path - get_file_info_mcp: os.stat uses safe_path No remaining is_path_allowed() call sites in any endpoint.
Re-Review: path injection fixes after feedback (#1721)All 3 critical/high findings from the original review are resolved:
Minor remaining nitThe Verdict: Approve (with minor nit). The blocking security issues are resolved. |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. Note: An earlier version of this PR had Generated with Claude Code |
* security: add validate_relative_path to shared path validator (#1721) - Extend autobot-shared/security/path_validator.py with validate_relative_path() - Validates user-controlled paths resolve within allowed base directories - Prevents directory traversal attacks (../../etc/passwd) Foundation for fixing 64 path injection CodeQL alerts in #1721 * security: fix path injection in core file/data APIs (#1721) - Add path validation to files.py, data_storage.py, filesystem_mcp.py, logs.py, session.py, git_mcp.py - Validate user-controlled paths against allowed base directories Resolves 47 of 64 path injection CodeQL alerts for #1721 * security: fix path injection in remaining backend files (#1721) - Add path validation to terminal_secrets_service, vnc_manager, reports, prompts, chat_sessions, chat_knowledge, ownership, environment, fast_document_scanner, secure_sandbox_executor Resolves remaining 17 of 64 path injection CodeQL alerts for #1721 * fix(security): fix path leakage in validator + CWD-dependent base (#1721) - Restructure validate_path() exception handler to separate relative_to() failure from must_exist check, preventing internal path leakage in error messages - Replace Path(".") with PROJECT_ROOT in reports.py to ensure deterministic path containment regardless of CWD at runtime * security: convert remaining filesystem_mcp endpoints to _validated_path (#1721) Convert 7 endpoints from is_path_allowed() (bool check on raw path) to _validated_path() (returns resolved safe path for all fs operations): - _read_single_file_for_batch: preserves error-dict contract - create_directory_mcp: os.makedirs uses safe_path - list_directory_mcp: os.listdir + os.path.join use safe_path - move_file_mcp: validates both source + destination - search_files_mcp: os.walk uses safe_path - directory_tree_mcp: recursive walk uses safe_path - get_file_info_mcp: os.stat uses safe_path No remaining is_path_allowed() call sites in any endpoint.
Summary
Fixes all 64
py/path-injectionCodeQL alerts from issue #1721.Approach
autobot-shared/security/path_validator.pywithvalidate_relative_path()utilityFiles Modified (18 files):
autobot-shared/security/path_validator.py(enhanced with new utility)autobot-shared/security/__init__.py(exports)autobot-backend/api/files.py(16 fixes)autobot-backend/api/data_storage.py(10 fixes)autobot-backend/chat_history/session.py(6 fixes)autobot-backend/api/filesystem_mcp.py(6 fixes)autobot-backend/api/logs.py(5 fixes)autobot-backend/api/git_mcp.py(4 fixes)autobot-backend/services/terminal_secrets_service.py(3 fixes)autobot-backend/api/vnc_manager.py(2 fixes)autobot-backend/project_state_tracking/reports.py(2 fixes)autobot-backend/api/prompts.py(2 fixes)autobot-backend/api/chat_sessions.py(2 fixes)autobot-backend/api/chat_knowledge.py(1 fix)autobot-backend/api/codebase_analytics/endpoints/ownership.py(1 fix)autobot-backend/api/codebase_analytics/endpoints/environment.py(1 fix)autobot-backend/services/fast_document_scanner.py(1 fix)autobot-backend/secure_sandbox_executor.py(1 fix)Part of #1721
Test plan