Skip to main content

graphify_security/
lib.rs

1//! URL, path, and label validation/sanitization for graphify.
2//!
3//! Ensures all URLs, file paths, and graph labels are safe and well-formed
4//! before use. Port of Python `security.py`.
5
6pub mod label_validator;
7pub mod path_validator;
8pub mod url_validator;
9
10pub use label_validator::sanitize_label;
11pub use path_validator::safe_path;
12pub use url_validator::validate_url;
13
14use thiserror::Error;
15
16/// Security validation errors.
17#[derive(Debug, Error)]
18pub enum SecurityError {
19    #[error("Invalid URL scheme: {0}")]
20    InvalidScheme(String),
21
22    #[error("URL resolves to private IP: {0}")]
23    PrivateIp(String),
24
25    #[error("Path traversal detected: {0}")]
26    PathTraversal(String),
27
28    #[error("Invalid path: {0}")]
29    InvalidPath(String),
30
31    #[error("URL parse error: {0}")]
32    UrlParse(#[from] url::ParseError),
33}