context_creator/mcp_server/
rmcp_handlers.rs1use anyhow::{bail, Result};
4use std::path::Path;
5
6pub fn validate_path(path: &Path) -> Result<()> {
8 let path_str = path.to_string_lossy();
10 if path_str.contains("..") || path_str.contains('~') {
11 bail!("Path traversal attempt detected");
12 }
13
14 if !path.exists() {
16 bail!("Path does not exist: {}", path.display());
17 }
18
19 if !path.is_dir() && !path.is_file() {
21 bail!("Path is not a file or directory: {}", path.display());
22 }
23
24 Ok(())
25}
26
27pub fn validate_url(url: &str) -> Result<()> {
29 if !url.starts_with("https://") && !url.starts_with("http://") {
31 bail!("Invalid URL: must start with http:// or https://");
32 }
33
34 if url.contains("github.com") && !url.contains("/") {
36 bail!("Invalid GitHub URL format");
37 }
38
39 Ok(())
40}