Testing API Authentication Weaknesses
When to Use
- Assessing REST API authentication mechanisms for bypass vulnerabilities before production deployment
- Testing JWT token implementation for common weaknesses (none algorithm, key confusion, missing expiration)
- Evaluating whether all API endpoints enforce authentication or if some are unintentionally exposed
- Testing API key generation, storage, and rotation mechanisms for predictability or leakage
- Validating session management including token expiration, revocation, and refresh token security
Do not use without written authorization. Authentication testing involves attempting to bypass security controls.
Prerequisites
- Written authorization specifying target API and authentication mechanisms in scope
- Valid test credentials for at least two user roles (regular user, admin)
- Burp Suite Professional with JWT-related extensions (JSON Web Tokens, JWT Editor)
- Python 3.10+ with
requests, PyJWT, and jwt libraries
- Wordlists for credential testing (SecLists authentication wordlists)
- API documentation or OpenAPI specification
Workflow
Step 1: Authentication Mechanism Identification
import requests
import json
BASE_URL = "https://target-api.example.com/api/v1"
# Probe the API to identify authentication mechanisms
auth_indicators = {
"jwt_bearer": False,
"api_key_header": False,
"api_key_query": False,
"basic_auth": False,
"oauth2": False,
"session_cookie": False,
"custom_token": False,
}
# Test 1: Check unauthenticated access
resp = requests.get(f"{BASE_URL}/users/me")
print(f"Unauthenticated: {resp.status_code}")
if resp.status_code == 200:
print("[CRITICAL] Endpoint accessible without authentication")
# Test 2: Check WWW-Authenticate header
if "WWW-Authenticate" in resp.headers:
scheme = resp.headers["WWW-Authenticate"]
print(f"Auth scheme advertised: {scheme}")
if "Bearer" in scheme:
auth_indicators["jwt_bearer"] = True
elif "Basic" in scheme:
auth_indicators["basic_auth"] = True
# Test 3: Login and examine tokens
login_resp = requests.post(f"{BASE_URL}/auth/login",
json={"username": "testuser@example.com", "password": "TestPass123!"})
if login_resp.status_code == 200:
login_data = login_resp.json()
# Check for JWT tokens
for key in ["token", "access_token", "jwt", "id_token"]:
if key in login_data:
token = login_data[key]
if token.count('.') == 2:
auth_indicators["jwt_bearer"] = True
print(f"JWT found in response field: {key}")
# Check for refresh tokens
for key in ["refresh_token", "refresh"]:
if key in login_data:
print(f"Refresh token found in field: {key}")
# Check for session cookies
for cookie in login_resp.cookies:
print(f"Cookie set: {cookie.name} = {cookie.value[:20]}...")
if "session" in cookie.name.lower():
auth_indicators["session_cookie"] = True
print(f"\nAuthentication mechanisms detected: {[k for k,v in auth_indicators.items() if v]}")
Step 2: Unauthenticated Endpoint Discovery
> 📎 Detailed content (full examples / references / data tables) has been split into `reference.md` in the same directory; use Read to load the relevant section on demand.
1---2name: testing-api-authentication-weaknesses3description: "Tests API authentication mechanisms for weaknesses. Signals: API attacks, interface testing, GraphQL."4zh-signals: "Tests API authentication mechanisms for weaknesses including broken 信号:api攻击,接口测试,graphql。"5when-to-use: 'Tests API authentication mechanisms for weaknesses including broken6 token validation, missing authentication on endpoints, weak password policies, credential7 stuffing susceptibility, token leakage in URLs or logs, and session management flaws.8 The tester evaluates JWT implementation, API key handling, OAuth flows, and session9 token entropy to identify authentication bypasses. Maps to OWASP API2:2023 Broken10 Authentication. Activates for requests involving API authentication testing, token11 validation assessment, credential security testing, or API auth bypass.1213 '14domain: cybersecurity15subdomain: api-security16tags:17- api-security18- owasp19- authentication20- jwt21- session-management22- credential-security23version: 1.0.024author: mahipal25license: Apache-2.026nist_csf:27- PR.PS-0128- ID.RA-0129- PR.DS-1030- DE.CM-0131mitre_attack:32- T119033- T1059.00734- T1552.00135- T100336- T111037metadata:38 source: https://skillmd.com/skills/dangeroussong/testing-api-authentication-weaknesses39---4041# Testing API Authentication Weaknesses4243## When to Use4445- Assessing REST API authentication mechanisms for bypass vulnerabilities before production deployment46- Testing JWT token implementation for common weaknesses (none algorithm, key confusion, missing expiration)47- Evaluating whether all API endpoints enforce authentication or if some are unintentionally exposed48- Testing API key generation, storage, and rotation mechanisms for predictability or leakage49- Validating session management including token expiration, revocation, and refresh token security5051**Do not use** without written authorization. Authentication testing involves attempting to bypass security controls.5253## Prerequisites5455- Written authorization specifying target API and authentication mechanisms in scope56- Valid test credentials for at least two user roles (regular user, admin)57- Burp Suite Professional with JWT-related extensions (JSON Web Tokens, JWT Editor)58- Python 3.10+ with `requests`, `PyJWT`, and `jwt` libraries59- Wordlists for credential testing (SecLists authentication wordlists)60- API documentation or OpenAPI specification6162## Workflow6364### Step 1: Authentication Mechanism Identification6566```python67import requests68import json6970BASE_URL = "https://target-api.example.com/api/v1"7172# Probe the API to identify authentication mechanisms73auth_indicators = {74 "jwt_bearer": False,75 "api_key_header": False,76 "api_key_query": False,77 "basic_auth": False,78 "oauth2": False,79 "session_cookie": False,80 "custom_token": False,81}8283# Test 1: Check unauthenticated access84resp = requests.get(f"{BASE_URL}/users/me")85print(f"Unauthenticated: {resp.status_code}")86if resp.status_code == 200:87 print("[CRITICAL] Endpoint accessible without authentication")8889# Test 2: Check WWW-Authenticate header90if "WWW-Authenticate" in resp.headers:91 scheme = resp.headers["WWW-Authenticate"]92 print(f"Auth scheme advertised: {scheme}")93 if "Bearer" in scheme:94 auth_indicators["jwt_bearer"] = True95 elif "Basic" in scheme:96 auth_indicators["basic_auth"] = True9798# Test 3: Login and examine tokens99login_resp = requests.post(f"{BASE_URL}/auth/login",100 json={"username": "testuser@example.com", "password": "TestPass123!"})101102if login_resp.status_code == 200:103 login_data = login_resp.json()104 # Check for JWT tokens105 for key in ["token", "access_token", "jwt", "id_token"]:106 if key in login_data:107 token = login_data[key]108 if token.count('.') == 2:109 auth_indicators["jwt_bearer"] = True110 print(f"JWT found in response field: {key}")111 # Check for refresh tokens112 for key in ["refresh_token", "refresh"]:113 if key in login_data:114 print(f"Refresh token found in field: {key}")115 # Check for session cookies116 for cookie in login_resp.cookies:117 print(f"Cookie set: {cookie.name} = {cookie.value[:20]}...")118 if "session" in cookie.name.lower():119 auth_indicators["session_cookie"] = True120121print(f"\nAuthentication mechanisms detected: {[k for k,v in auth_indicators.items() if v]}")122```123124### Step 2: Unauthenticated Endpoint Discovery125126```python127128> 📎 Detailed content (full examples / references / data tables) has been split into `reference.md` in the same directory; use Read to load the relevant section on demand.