Skip to content

API Reference parrot.tools.egress

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.tools.egress

View source

Egress guard for the HTTP sessions tools open themselves (PA-13, defence in depth).

A host that lets tenants offer tools which fetch URLs (RSS item links, Word documents, wiki sources) enables the guard with app[STUDIO_EGRESS_GUARD] = True (parrot.handlers.studio copies it to this process on startup). While it is off every factory here returns a plain aiohttp.ClientSession: behaviour is unchanged.

When it is on, :func:egress_session returns a session whose connector

  • resolves names itself (:class:GuardedResolver), REFUSES every address that is not globally routable (private, loopback, link-local incl. the cloud metadata address, unspecified, reserved, multicast) and hands aiohttp only the vetted addresses, so the socket connects to the address that was checked (no second lookup, no DNS rebinding);
  • checks literal IP hosts (which aiohttp never resolves) and localhost names on the first request and on EVERY redirect hop, through trace hooks.

This does not cover browser-driven tools (Selenium/Playwright resolve and follow redirects on their own); for those the cluster NetworkPolicy / egress proxy is the only control.

Class EgressBlocked

A fetch was refused because its target is not a public address (a transport error to callers: ClientError).

Attribute FEATURES

Class GuardedResolver

Resolve with the system resolver and drop (or refuse) every non-public answer.

aiohttp connects to the addresses returned here and never looks the name up again. A name that has ANY non-public answer is refused outright (a mixed answer is how rebinding tricks try to slip a private address in).

Parameter Type Default Description
inner Optional[AbstractResolver] None

Method GuardedResolver.resolve

Resolved addresses of host, all public; :class:EgressBlocked otherwise.

resolve(host: str, port: int = 0, family: int = socket.AF_INET) -> list[ResolveResult]

Parameter Type Default Description
host str
port int 0
family int socket.AF_INET

Returns: list[ResolveResult]

Method GuardedResolver.close

Close the wrapped resolver.

close() -> None

Attribute STUDIO_EGRESS_GUARD

Function check_url

Raise :class:EgressBlocked when url names localhost, an internal-only name or a non-public IP literal.

The host is canonicalised first (trailing dots, full-width digits, 127.1/octal/hex IPv4 spellings), and names under internal-only suffixes (.internal, .local, .svc, .localhost …) are refused outright. Other hostnames are NOT resolved here (the connector's :class:GuardedResolver does that, once, for the real connect; browser callers use :func:resolve_check).

check_url(url: Any) -> None

Parameter Type Default Description
url Any

Function configure

Turn the guard on or off for this process (the host's app[STUDIO_EGRESS_GUARD]).

configure(enabled: bool) -> None

Parameter Type Default Description
enabled bool

Function egress_session

The one factory tools use for their own HTTP sessions: guarded when the host enabled it, plain otherwise.

egress_session(**kwargs: Any) -> aiohttp.ClientSession

Parameter Type Default Description
**kwargs Any {}

Returns: aiohttp.ClientSession

Function guarded_session

A guarded ClientSession regardless of the host switch (used by :func:egress_session and tests).

trust_env=True is refused: it would route the request through the environment's proxy, so the connector would resolve the PROXY and never the target and the guard would see nothing.

guarded_session(**kwargs: Any) -> aiohttp.ClientSession

Parameter Type Default Description
**kwargs Any {}

Returns: aiohttp.ClientSession

Function is_enabled

Whether :func:egress_session currently returns guarded sessions.

is_enabled() -> bool

Returns: bool

Function is_public_address

True only for a globally routable IP literal; anything unparsable is refused.

is_public_address(address: str) -> bool

Parameter Type Default Description
address str

Returns: bool

Function resolve_check

:func:check_url, then resolve a NAME and refuse it when any answer is non-public (for browser navigation).

A browser resolves the name again on its own, so this is a check, not a pin (the cluster NetworkPolicy remains the real control); it still stops the plain cases (metadata.google.internal, a name pointing at 10.x).

resolve_check(url: Any, resolver: Optional[AbstractResolver] = None) -> None

Parameter Type Default Description
url Any
resolver Optional[AbstractResolver] None

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally