fix(security): CWE-22 path traversal in MCP server#211
Merged
Conversation
Add path validation to all MCP tools that accept user-supplied file paths, preventing arbitrary file read/write via directory traversal. Vulnerable functions patched: - tool_backup: db_path and backup_path now validated - tool_create_db: params.path now validated - get_or_open_db: path now validated Implementation: - validate_path() canonicalizes paths and checks they resolve within the configured data_dir (defaults to cwd) - Configurable via mcp.data_dir in config or RUVECTOR_MCP_DATA_DIR env - Rejects absolute paths outside data_dir, ../traversal, and symlink escapes - 8 unit tests covering all POC attack vectors from the report CVSS 3.1: 9.1 (Critical) → Mitigated Closes #207 Co-Authored-By: claude-flow <ruv@ruv.net>
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
vector_db_backup,vector_db_create, and all db path handlingvalidate_path()that canonicalizes user paths and enforces confinement within configureddata_dirmcp.data_dirin config orRUVECTOR_MCP_DATA_DIRenv var (defaults to cwd)Changes
crates/ruvector-cli/src/mcp/handlers.rs:validate_path()method that resolves, canonicalizes, and confines pathstool_backup()(bothdb_pathandbackup_path)tool_create_db()(params.path)get_or_open_db()(used bytool_insert,tool_search,tool_stats)crates/ruvector-cli/src/config.rs:data_dirfield toMcpConfig(configurable path confinement boundary)RUVECTOR_MCP_DATA_DIRenv var overrideTest plan
cargo publish --dry-runsucceedsruvector-cli v2.0.4to crates.io with the fixCloses #207
🤖 Generated with claude-flow