Expand description
Security validation utilities — SSRF prevention, path traversal detection, and tool description sanitization.
These utilities provide defense-in-depth against common input-based attacks targeting agentic AI systems. They map to OWASP LLM05 (Improper Output Handling / SSRF) and LLM01 (Prompt Injection).
Constants§
- MAX_
DESCRIPTION_ LEN - Maximum allowed length for tool descriptions.
- MAX_
TOOL_ NAME_ LEN - Maximum allowed length for tool names.
Functions§
- is_
description_ safe - Check whether a tool description contains prompt injection patterns.
- is_
env_ path_ safe - Validate a path from an env var for safety.
- is_
path_ safe - Check whether a file path is safe from path traversal attacks.
- is_
path_ within_ base - Verify that a resolved path stays within the given base directory.
- is_
private_ ip - Check if an IP address is in a private/reserved range.
- is_
tool_ name_ valid - Validate a tool name — must be alphanumeric with dots, underscores, hyphens.
- is_
url_ safe - Check whether a URL is safe to fetch (SSRF prevention).
- parse_
clamped_ f32 - Parse an f32 from an env var string, clamping to a valid range.
- parse_
clamped_ usize - Parse a usize from an env var string, clamping to a valid range.
- sanitize_
description - Sanitize a tool description by removing injection patterns.
- sanitize_
path - Sanitize a file path by removing dangerous sequences.