trading_agent.tools.address_guard
¶
Refuses web requests to this machine or the local network.
Without it, web_fetch could be pointed at UBI on 127.0.0.1, at the local databases, or at a router on the home network. Every address a host name resolves to must be a public internet address. Each step of a redirect is checked again, so a public page cannot redirect the fetch to a private one.
Typical usage example:
guard = AddressGuard() await guard.check('https://example.com/page')
AddressRefusedError
¶
Bases: ValueError
The address is not a public web address.
AddressGuard
¶
Checks that a URL points at the public internet.
check
async
¶
Checks one URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to be fetched. |
required |
Raises:
| Type | Description |
|---|---|
AddressRefusedError
|
The scheme is not http or https, the host cannot be resolved, or it resolves to a private, loopback or other non-public address. |