Python Basic Auth Header Used
Description
Detects insecure usage of HTTP Basic Authentication headers in Python applications. Basic Authentication transmits credentials in a weakly encoded format that can expose usernames and passwords if not used over HTTPS/TLS, creating a risk of credential theft.
Detection Strategy
• Identifies function calls that set or manipulate HTTP Basic Authentication headers
• Checks if the authentication headers are being used in potentially insecure contexts (e.g. non-HTTPS connections)
• Verifies if the code explicitly enforces secure transport requirements when using basic authentication
• Reports a vulnerability when basic auth headers are used without proper security controls
Vulnerable code example
import os
import aiohttp
async def vulnerable_request():
# Insecure: Direct use of environment variable in auth header without validation
auth_header = f"Basic {os.environ['API_TOKEN']}"
async with aiohttp.ClientSession() as session:...✅ Secure code example
import os
import aiohttp
from urllib.parse import urlparse
from typing import Optional
async def secure_request() -> Optional[str]:
# Validate API token exists and is non-empty
api_token = os.getenv('API_TOKEN')...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.