1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! Safety Layer - Tool Call Validation
//!
//! Validates tool calls before execution to prevent dangerous operations.
//! Checks include:
//! - Path traversal prevention
//! - Protected path enforcement
//! - Command blacklisting
//! - Symlink attack prevention
pub use SafetyChecker;
use ;
/// Normalize a filesystem path for cross-platform safety comparisons.
///
/// On Linux/macOS this canonicalizes the path (resolving symlinks and `..`/`.`)
/// when the path exists; on Windows it additionally strips the `\\?\`
/// extended-length prefix that `Path::canonicalize` produces, so the result
/// matches the form returned by `current_dir()` and user-supplied paths.
///
/// If canonicalization fails (e.g. the path does not yet exist) we fall back
/// to `p.to_path_buf()` — also with the UNC prefix stripped on Windows — so
/// the function is safe to call on prospective output paths.
///
/// This is the single source of truth used by `PathValidator` so that the
/// path being checked AND every allow-list / deny-list entry is normalized
/// the same way. macOS canonicalizes `/var/folders/...` to
/// `/private/var/folders/...`; Windows produces `\\?\C:\...`. Without
/// symmetric normalization the comparison silently fails.
/// Strip the Windows `\\?\` extended-length path prefix from a `PathBuf`.
///
/// On non-Windows targets this is a no-op.
/// Convert OS-native path separators to forward slashes for glob matching.
///
/// The `glob` crate treats `\` as an escape character on every platform, so a
/// Windows path like `C:\foo\bar` cannot be matched by a pattern such as
/// `**/bar`. We normalize both the pattern and the input path to forward
/// slashes before invoking `glob::Pattern::matches` — this is a no-op on
/// Unix where paths already use `/`.