Skip to content

AAK-SSRF-TOCTOU-001

Validate-then-fetch DNS-rebind / TOCTOU on URL allow-list

Field Value
Severity MEDIUM
Category TRANSPORT_SECURITY
Shipped v0.3.5 (2026-04-25)
Scanner agent_audit_kit/scanners/ssrf_toctou.py
CWE CWE-367 (TOCTOU) + CWE-918 (SSRF)
OWASP MCP MCP05:2025 (Command Injection & Execution)
OWASP Agentic ASI02 (Tool Misuse and Exploitation)
AICM IVS-04, AIS-08
CVE CVE-2026-41488
Advisory GHSA-r7w7-9xr2-qq2r

What it catches

A function validates a URL via an SSRF guard, then performs a separate network fetch that triggers an independent DNS resolution. Between the two resolutions a malicious hostname can rotate from a public IP to a private/localhost/cloud-metadata IP (DNS rebinding), bypassing the allow-list.

CVE-2026-41488 (langchain-openai < 1.1.14's _url_to_size) is the canonical example. The validator did its own DNS resolution to check the IP, then requests.get(url) did a fresh resolution against the same hostname — long enough for the attacker's authoritative DNS server to flip the answer.

Detection

Python AST walk, calls sorted by source line. For each function:

  1. First call to _VALIDATOR_NAMES sets validator_seen.
  2. Subsequent call whose attribute is in _FETCH_NAMES fires the rule unless an IP-pinning marker is reachable in the same function:
  3. socket.getaddrinfo
  4. HTTPAdapter / requests.adapters.HTTPAdapter
  5. session.mount / session.get_adapter
  6. resolved_ip, pinned_ip, resolved_host, resolve_once, dns_pin, host_header_pin

The pin check covers langchain-openai < 1.1.14 across requirements*.txt, pyproject.toml, poetry.lock, Pipfile.lock, uv.lock.

What it does NOT catch

  • Cross-function flow where the validator runs in one helper and the fetch in another — we look only within a single function body. Refactor to consolidate, or, if the cross-function design has its own TTL-bounded DNS pin, list the file under ignore-paths in .agent-audit-kit.yml. AAK reads no per-line suppression comment.
  • Any pattern AAK-LANGCHAIN-SSRF-REDIR-001 already catches — when both rules would fire on the same code, the redirect-bypass rule wins by being CRITICAL-class.

Remediation

Resolve once, pin the IP, reuse the pinned Session:

import socket
import requests
from requests.adapters import HTTPAdapter

def url_to_size(url: str) -> int:
    if not validate_safe_url(url):
        raise ValueError("unsafe url")
    # Resolve ONCE.
    resolved_ip = socket.getaddrinfo(url, 443)[0][4][0]
    # Reuse the resolved IP for the fetch.
    session = requests.Session()
    session.mount("https://", HTTPAdapter())
    response = session.get(
        url,
        headers={"Host": resolved_ip},
        timeout=5,
    )
    return len(response.content)

For langchain-openai, bump to >= 1.1.14.

Sister rule

AAK-LANGCHAIN-SSRF-REDIR-001 covers the redirect-bypass shape: validate-then-fetch-with-redirects (CVE-2026-41481).


Registry reference

This section is generated from the rule registry (agent_audit_kit/rules/builtin.py) when the documentation is built, so it follows the scanner. The rest of the page is hand-written; where the two disagree, the registry is what runs.

Severity
MEDIUM
Category
Transport Security (transport-security)
Scanner
agent_audit_kit/scanners/ssrf_toctou.py
Auto-fixable
No.
SARIF name
UrlAllowListToctou

What it detects

A function validates a URL via an SSRF guard, then performs a separate network fetch that triggers an independent DNS resolution. Between the two resolutions a malicious hostname can rotate from a public IP to a private/localhost/cloud-metadata IP (DNS rebinding) — bypassing the allow-list. CVE-2026-41488 (langchain-openai _url_to_size) is the canonical example; CVE-2026-53708 (mcp-contextforge-gateway < 1.0.3, /admin/gateways/test) is the same bug reached through a guard named after the endpoint rather than after the check, and CVE-2026-55096 (fast-mcp-telegram < 0.30.1) through a module-private guard, _validate_url_security, that checks the literal hostname and never resolves it at all. The fix is to resolve once, pin the IP, and reuse the same Session / HTTPAdapter for the fetch — or drive the allow-list check on the resolved IP instead of the hostname.

How to fix

Resolve the hostname once with socket.getaddrinfo, validate the resolved IP against the allow-list, then make the fetch over a Session / connection pinned to that IP (e.g. via Host: header + explicit IP, custom HTTPAdapter, or pinned_ip-style helper). Pin langchain-openai >= 1.1.14.

To confirm the finding is gone, report only this rule:

agent-audit-kit scan . --rules AAK-SSRF-TOCTOU-001

Limitations

The code check is Python only and looks at one function at a time. A guard is recognised by its name (leading underscores ignored) wherever it is defined, or by its body, a name lookup plus a private-range check, only when it is defined in the same file as the fetch. An IP pin is recognised by name (pinned_ip, resolved_ip, HTTPAdapter, session.mount, socket.getaddrinfo and a few more) anywhere in the calling function, a comment included. The version check covers langchain-openai only, so on fast-mcp-telegram the rule reads code and also fires on 0.30.1's own source: that release resolves inside the guard, but the fetch resolves the name again. A git reference or an archive is judged by the release its tag or file name names, with releases compared on their first three numbers, so a pre-release of the fix (langchain-openai==1.1.14rc1) reads as the fix; a git reference to a commit or a branch (any name holding a / but refs/tags/<tag>) states no version and is reported. Declarations of one install that no release satisfies together (langchain-openai==1.1.14 beside langchain-openai==1.1.13 in one requirements file) admit nothing and are not reported; pip refuses to install them too. A Python file over 1 MB, a pyproject.toml that does not parse and a manifest over 2 MB are not read. A pyproject.toml with a key of more than 64 dotted parts, or holding an integer Python cannot convert (one past 4,300 digits), is refused and reported as AAK-INTERNAL-SCANNER-FAIL. A lockfile over 32 MiB is not read.

References


All rules.