Skip to main content

Module security

Module security 

Source
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.