# GHSA-H9Q5-C59C-3HF5: SSRF via Unvalidated Image Download — No Internal IP Filtering in dl\_image()

- Database: GitHub
- Severity: CVSS 6.8 (Medium)
- Published: 2026-08-13
- Modified: 2026-08-13

## Affected versions

- maloja (PyPI): through 3.2.4

## Description

## Summary

The `dl_image()` function downloads images from third-party metadata APIs (Last.fm, MusicBrainz) using `requests.get()` without any URL validation. There is no filtering of private IP ranges, loopback addresses, or cloud metadata endpoints. An attacker who can influence the image URLs returned by these APIs (e.g., by editing artist metadata on Last.fm) can cause the Maloja server to make requests to arbitrary internal services.

## Vulnerable Code

**File:** `maloja/images.py`, lines 147-160

```python
def dl_image(url):
    try:
        r = requests.get(url)          # No URL validation
        mime = r.headers.get('content-type') or 'image/jpg'
        data = io.BytesIO(r.content).read()
        # ...
```

The URL comes from the call chain:
```
resolve_image(url)
  → set_image_in_cache(url)
    → dl_image(url)
      → requests.get(url)  ← SSRF
```

The URLs originate from third-party API responses (Last.fm/MusicBrainz artist metadata), which can be edited by any user with an account on those platforms.

**What's missing:**
- ❌ No private IP range filtering (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16)
- ❌ No loopback blocking (127.0.0.0/8)
- ❌ No link-local / cloud metadata blocking (169.254.0.0/16)
- ❌ No redirect-following restriction
- ❌ No DNS rebinding protection

## Proof of Concept

```bash
# Verify the vulnerable code has no URL filtering:
grep -rn "requests.get" maloja/images.py
# Output: r = requests.get(url)  — no pre-validation

grep -rn "validat\|whitelist\|blacklist\|allowlist\|localhost\|127.0.0\|169.254\|private\|internal" maloja/images.py
# Output: (empty) — no URL safety checks exist

# The SSRF can be triggered by:
# 1. Editing an artist's image URL on Last.fm to point to:
#    http://169.254.169.254/latest/meta-data/iam/security-credentials/
# 2. Maloja's periodic metadata sync fetches the URL via dl_image()
# 3. requests.get("http://169.254.169.254/...") executes
# 4. Response body stored in image cache, accessible via Web UI
```

## Attack Scenario

1. Attacker edits artist metadata on Last.fm or MusicBrainz, setting the image URL to:
   - `http://169.254.169.254/latest/meta-data/iam/security-credentials/` (AWS IAM theft)
   - `https://attacker.com/callback` (network reconnaissance)

2. Maloja's scheduled sync fetches the metadata, calls `dl_image(url)`

3. Server makes the request to the attacker-controlled URL or internal service

4. For image URLs: response stored in cache, readable at `/cacheimages/<hash>`

## Impact

| Target | Attack |
|--------|--------|
| `http://169.254.169.254/latest/meta-data/iam/security-credentials/` | Steal AWS IAM credentials |
| `http://127.0.0.1:6379/` | Probe internal Redis |
| `http://10.0.0.1/admin` | Access internal admin panels |
| `https://attacker.com/capture` | Confirm server IP / network position |

## Suggested Fix

```python
import ipaddress
import urllib.parse
import socket

def validate_safe_url(url):
    parsed = urllib.parse.urlparse(url)
    if parsed.scheme not in ("http", "https"):
        return False
    try:
        ip_str = socket.gethostbyname(parsed.hostname)
        ip = ipaddress.ip_address(ip_str)
        if ip.is_private or ip.is_loopback or ip.is_link_local:
            return False
    except (socket.gaierror, ValueError):
        return False
    return True

def dl_image(url):
    if not validate_safe_url(url):
        import logging
        logging.warning(f"dl_image: Blocked SSRF attempt to {url}")
        return None
    try:
        r = requests.get(url, timeout=10, allow_redirects=False)
        # ...
```

## References

- https://github.com/krateng/maloja/security/advisories/GHSA-h9q5-c59c-3hf5

Page: https://cve.now/GHSA-H9Q5-C59C-3HF5

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
