Nous.Tools.UrlGuard (nous v0.15.4)
View SourceSSRF protection for outbound HTTP from tools and providers.
Prevents prompt-injected agents from reaching cloud-metadata
(169.254.169.254), internal services on private networks, loopback,
and link-local ranges. By default only http:// and https:// schemes
are accepted; other schemes (file://, gopher://, ftp://, etc.)
are rejected.
Usage
case Nous.Tools.UrlGuard.validate("https://example.com/foo") do
{:ok, uri} -> proceed_with(uri)
{:error, reason} -> {:error, reason} # human-readable
endOpt-in: allowing private hosts
For local dev / Docker dev-loop you can pass allow_private_hosts: true:
Nous.Tools.UrlGuard.validate(url, allow_private_hosts: true)Do NOT enable this in production. It re-opens the SSRF channel.
Summary
Functions
Validate a URL string. Returns {:ok, %URI{}} or {:error, reason}.