T09 · Insecure Skill Coding Practices
- Location
scripts/qianfanclawhub.py:132- Finding
Baidu API Key Disclosure Through a User-Controlled API Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/qianfanclawhub.py, lines 14–15, 46–47, 75–78, 132, and 153
Vulnerability Type: Credential disclosure through an unrestricted network destination
Risk Level: HighVulnerable Code
python def __init__(self, endpoint=None, api_key=None, workdir=None): self.endpoint = endpoint or 'https://appbuilder.baidu.com' self.api_key = api_keypython headers = { 'Content-Type': 'application/json', 'Authorization': f'Bearer {self.api_key}' } response = requests.post( f"{self.endpoint}/v2/skills/search", json=params, headers=headers )python url = f"{self.endpoint}/v2/skills/download" params = {"slugName": slug_name} headers = {'Authorization': f'Bearer {self.api_key}'} response = requests.get( url, params=params, headers=headers, timeout=60 )python parser.add_argument( '--endpoint', type=str, default=None, help='指定 API 服务器地址' )python client = QianfanClawhubClient( endpoint=args.endpoint, api_key=api_key, workdir=args.workdir )Technical Analysis
The command-line
--endpointoption permits the caller to replace the trusted default Baidu endpoint with an arbitrary URL. The selected endpoint is used directly for both search and download requests, and the value of theBAIDU_API_KEYenvironment variable is attached as an HTTP Bearer credential.The implementation does not validate:
- The URL scheme.
- Whether TLS is required.
- Whether the destination hostname belongs to Baidu.
- Whether the destination is a local, private, or attacker-controlled server.
- Whether the supplied endpoint is authorized to receive the Baidu credential.
Consequently, an endpoint such as
https://attacker.examplereceives the API key when either supported operation is invoked. A plaintexthttp://endpoint ...[truncated 1893 chars]- Remediation
View remediation
Remediation Suggestions
- Remove
--endpointfrom production builds if alternative endpoints are not required for the declared functionality. - If endpoint customization is required, parse the URL and enforce:
- An
httpsscheme. - An exact allowlist of approved Baidu hostnames.
- An expected port.
- No embedded user information.
- An
- Do not rely on substring or suffix checks that can be bypassed with hostnames such as
baidu.com.attacker.example. - Refuse to attach
BAIDU_API_KEYto localhost, private-network, link-local, or unapproved destinations. - Use separate, low-privilege test credentials for development endpoints rather than forwarding the production API key.
- Apply least privilege to the Baidu credential and rotate any key that may have been exposed.
- Add connection and read timeouts to every request, including the search request.
- Add automated tests proving that credentials are never sent when the endpoint is not an explicitly approved HTTPS origin.
- Remove
