# Credential Exfiltration via User-Controlled Endpoint - ID: python-webhook-credential-exfiltration - Severity: CRITICAL - CWE: CWE-201 (CWE-201) - Languages: Python - Frameworks: flask, django, fastapi ## Description Detects when internal credentials (API keys, secrets, tokens) are sent in HTTP requests to user-controlled endpoints. This allows attackers to exfiltrate server credentials by providing a malicious webhook URL that captures the sensitive headers or body data. Example vulnerable pattern: ```python # User controls 'endpoint' from request endpoint = request.form.get('webhook_url') # Server sends its internal API key to attacker-controlled URL requests.post(endpoint, headers={'X-API-Key': os.environ['INTERNAL_API_KEY']}) ``` This is different from standard SSRF (which accesses internal resources) - here the attacker exfiltrates server credentials to their own controlled endpoint. ## Detection Message User input from {source} controls the destination of an HTTP request at {sink}. If credentials are included in the request headers or body, attackers can exfiltrate them by providing a malicious endpoint URL. ## Remediation 1. Never send internal credentials to user-controlled endpoints 2. Validate webhook URLs against a strict allowlist of trusted domains 3. Use webhook secrets for authentication instead of sending API keys ```python from urllib.parse import urlparse ALLOWED_WEBHOOK_DOMAINS = {'api.slack.com', 'hooks.stripe.com'} def send_webhook(webhook_url, data): parsed = urlparse(webhook_url) if parsed.hostname not in ALLOWED_WEBHOOK_DOMAINS: raise ValueError('Untrusted webhook domain') # Use webhook-specific secret, not internal API key requests.post(webhook_url, json=data, headers={'X-Webhook-Secret': user_webhook_secret}) ``` Learn more: https://shoulder.dev/learn/python/cwe-201/credential-exfiltration ## Documentation [object Object] ## Related Rules - **Credential Exfiltration via User-Controlled Endpoint** [CRITICAL]: - **Credential Exfiltration via User-Controlled Endpoint** [CRITICAL]: