Details
2. Redirect-Based SSRF Amplification
Both requests and aiohttp follow HTTP redirects by default. The CCIP handlers use the final response without validating the final resolved URL.
- Sync:
web3/utils/exception_handling.py--session.get()with defaultallow_redirects=True - Async:
web3/utils/async_exception_handling.py--session.get()with default redirect following
A contract-supplied URL can point to an attacker-controlled server that issues a 302 redirect to http://169.254.169.254/... or any internal endpoint. This defeats naive URL-prefix checks that an application might add, expanding the SSRF surface.
3. Internal Network Probing
By varying the URLs supplied in the OffchainLookup revert payload, an attacker can:
- Probe internal network topology (open ports, reachable hosts) based on response timing and error behavior
- Trigger side effects on internal APIs that accept GET or POST requests without authentication
- Map cloud infrastructure by querying metadata endpoints
4. POST-Based SSRF
When the contract-supplied URL does not contain both {sender} and {data} placeholders, the handler switches to session.post() with a JSON body. This means the attacker can cause the victim to issue POST requests with a controlled JSON body ({"data": ..., "sender": ...}) to arbitrary destinations, increasing the potential for triggering state-changing operations on internal services.
---
Proof of Concept
Prerequisites
- Python environment with
web3installed - No network access or blockchain connection required (the PoC calls the handler function directly)
Step 1: Start a local HTTP listener
python -m http.server 9999
Step 2: Run the reproduction script
python repro_ssrf.py
Step 3: Observe
The HTTP server logs will show an inbound request to a path like /SSRF_DETECTION_SUCCESS?sender=...&data=..., confirming that handle_offchain_lookup() issued an outbound HTTP request to the contract-supplied URL without any destination validation.
The script will then print an error (the local HTTP server does not return the expected JSON), but the request has already been sent -- the SSRF occurs before any response validation.
Reproduction script (repro_ssrf.py)
from web3.types import TxParams
from web3.utils.exception_handling import handle_offchain_lookup
def reproduce_ssrf():
target_address = "0x0000000000000000000000000000000000000001"
payload = {
"sender": target_address,
"callData": "0x1234",
"callbackFunction": "0x12345678",
"extraData": "0x90ab",
"urls": [
"http://127.0.0.1:9999/SSRF_DETECTION_SUCCESS?sender={sender}&data={data}"
],
}
transaction: TxParams = {"to": target_address}
print(f"Triggering CCIP Read handler with URL: {payload['urls'][0]}")
try:
handle_offchain_lookup(payload, transaction)
except Exception as e:
print(f"Expected failure after request was sent: {e}")
if __name__ == "__main__":
reproduce_ssrf()
Real-world attack scenario
In a production setting, the attacker would:
- Deploy a malicious contract that reverts with
OffchainLookup, supplying URLs pointing to internal services (e.g.,http://169.254.169.254/latest/meta-data/iam/security-credentials/). - Cause a backend service (indexer, API, bot) to call that contract via
eth_call/.call(). - web3.py automatically triggers CCIP Read, issuing the HTTP request from the backend's network context.
No special permissions or contract interactions beyond a standard eth_call are required.
---
Suggested Remediation
1. Restrict URL schemes (safe default)
Allow only https:// by default. Provide an explicit opt-in flag (e.g., ccip_read_allow_http=True) for http://.
2. Block private/reserved IP destinations by default
Before issuing the request, resolve the hostname and reject connections to:
127.0.0.0/8(loopback)169.254.0.0/16(link-local / cloud metadata)10.0.0.0/8,172.16.0.0/12,192.168.0.0/16(RFC1918)::1,fe80::/10(IPv6 loopback / link-local)0.0.0.0/8
3. Disable or validate redirects
Either:
- Set
allow_redirects=Falseon the HTTP requests, or - Validate each redirect target against the same destination policy before following it
4. Provide a URL validator hook
Allow users to supply a custom URL validation callback for CCIP Read URLs (e.g., a hostname allowlist, gateway pinning, or custom policy). This enables advanced users to configure CCIP Read for their specific trust model.
5. Consider stronger default safety signaling (or default-off in server-side contexts)
EIP-3668 encourages keeping CCIP Read enabled for calls, so this may not be desirable as a universal default change. However, for server-side deployments, consider either:
- a clearly documented “safe mode” preset (destination validation + redirect checks + private-range blocking), or
- stronger warnings / examples showing how to disable CCIP Read (
ccip_read_enabled=Falseorglobal_ccip_read_enabled=False) when calling untrusted contracts.
At minimum, document the SSRF risk prominently in the CCIP Read docs.