Skip to main content
Menu
Advisories

AutoGPT Classic: SSRF in llamafile setup script via unvalidated download URL and redirects

GHSA-VM4V-5HGJ-RQ77Published Updated GitHub

Description

SSRF Vulnerability in AutoGPT's serve.py via Unvalidated URL in urlretrieve

Summary

A Server-Side Request Forgery (SSRF) vulnerability exists in classic/original_autogpt/scripts/llamafile/serve.py at line 148. The code passes a URL derived from configurable or user-influenced input directly to urllib.request.urlretrieve() without validating the scheme, host, or destination. An attacker who can influence the URL value (via environment variables, config files, or other input vectors) can cause the AutoGPT process to issue HTTP requests to arbitrary internal or external hosts.

Affected Version

Vulnerability Details

Vulnerable Code

# serve.py, line 148
request.urlretrieve(url, ...)

The url variable is constructed from a host and/or path value that is configurable at runtime (e.g., sourced from environment variables or a settings file) rather than being a fixed, trusted constant.

Root Cause

The root cause is the absence of any allowlist validation before the URL is passed to urlretrieve(). Specifically:

  1. The URL's scheme is never checked — allowing file://, http://, https://, or other schemes.
  2. The URL's hostname is never compared against an expected value (e.g., localhost or 127.0.0.1).
  3. The URL's port is never validated against the expected llamafile server port.

Because the URL value can be influenced by environment-level configuration, an attacker with write access to the environment (e.g., via a compromised .env file, CI/CD pipeline injection, or a path traversal in a config loader) can redirect this request to an arbitrary destination — including internal cloud metadata endpoints, internal services, or external attacker-controlled servers.

Proof of Concept

import urllib.request as request
import os

# Attacker sets or influences the URL (e.g., via environment variable or config)
# Targeting AWS EC2 metadata endpoint as a realistic internal target
attacker_controlled_url = "http://169.254.169.254/latest/meta-data/iam/security-credentials/"

# This mirrors the vulnerable call at serve.py:148
# No validation occurs before the request is issued
response_path, _ = request.urlretrieve(attacker_controlled_url, "/tmp/ssrf_output")

with open("/tmp/ssrf_output") as f:
    print("[SSRF] Response from internal endpoint:")
    print(f.read())

Expected result: The AutoGPT process fetches the cloud metadata endpoint and writes the response (potentially including IAM credentials) to disk — demonstrating that the request was issued to an unintended internal host.

Impact

  • Exfiltration of cloud instance metadata (e.g., AWS IMDSv1 IAM credentials) if running in a cloud environment.
  • Probing of internal network services not exposed to the public internet.
  • Potential credential theft if internal services (e.g., databases, Vault, Kubernetes API) are reachable from the host.

The severity is High in cloud-hosted deployments. The exploitability is contingent on an attacker's ability to influence the URL value, which is a realistic threat in misconfigured or multi-tenant environments.

Fix

Before calling urlretrieve, validate the URL against a strict allowlist of expected values:

# One-line fix: assert the URL matches the expected local llamafile download source
assert url.startswith("https://huggingface.co/Mozilla/"), f"Blocked untrusted URL: {url}"

For a more robust fix, parse the URL with urllib.parse.urlparse() and explicitly validate that the scheme is https and the hostname matches the expected download host before proceeding.

Release references

The patched-version metadata for this advisory points to the following release(s):

Affected versions

References

GitHub · Significant-Gravitas/AutoGPT