T09 · Insecure Skill Coding Practices
- Location
diagnose.py:106- Finding
Tencent Ads access token transmitted in URL query parameters
- Content
View full analysis
Vulnerability Details
File Location:
diagnose.py, lines 106-122
Vulnerability Type: Credential exposure through URL query parameters
Risk Level: MediumVulnerable Code
python url = 'https://api.e.qq.com/v1.1/daily_reports/get' params = { 'access_token': token, 'account_id': account_id, 'level': 'REPORT_LEVEL_ADGROUP', 'date_range': json.dumps({'start_date': start_date, 'end_date': end_date}), 'filtering': json.dumps([{'field': 'adgroup_id', 'operator': 'EQUALS', 'values': [str(adgroup_id)]}]), 'fields': json.dumps(['adgroup_id', 'cost', 'view_count', 'valid_click_count', 'conversions_count']), 'page': 1, 'page_size': 10 } resp = requests.get(url, params=params)Technical Analysis
The Tencent access token is included in the
paramsdictionary passed torequests.get. The Requests library serializes these parameters into the request URL. Although HTTPS protects the request while it is in transit, query strings are commonly retained by HTTP servers, reverse proxies, network monitoring products, application performance monitoring systems, debugging tools, and exception-reporting systems.Any component that records the complete URL may therefore persist the access token beyond the execution of the diagnostic command. This increases the credential's exposure compared with transmission through an authorization header.
Attack Path
- A user configures a valid
TENCENT_ACCESS_TOKENin the local.envfile. - The user invokes Tencent Ads diagnosis.
- The script constructs a GET request whose URL contains
access_token=<token>. - An API gateway, proxy, monitoring product, debugging system, or remote server records the complete request URL.
- A party with unauthorized or overly broad access to those records extracts the token.
- The party reuses the token against Tencent Ads APIs before it expires or is revoked.
Exploitation d ...[truncated 527 chars]
- A user configures a valid
- Remediation
View remediation
Remediation Suggestions
- If supported by the Tencent Ads API, transmit the token in an authorization header rather than the URL:
python headers = {"Authorization": f"Bearer {token}"} resp = requests.get(url, headers=headers, params=non_secret_params, timeout=(5, 30)) - If the API contract requires a query parameter, configure application, proxy, gateway, and monitoring logs to redact
access_token. - Prevent complete request URLs from appearing in error messages and debug logs.
- Grant the token only the minimum scopes required for report retrieval.
- Retain tokens only for their necessary lifetime and rotate any token suspected of appearing in logs.
- Restrict access to
.envand relevant infrastructure logs using filesystem and role-based access controls.
- If supported by the Tencent Ads API, transmit the token in an authorization header rather than the URL:
