T09 · Insecure Skill Coding Practices
- Location
scripts/query_product_knowledge.py:13- Finding
Reusable API Credential Embedded in Source Code
- Content
View full analysis
Vulnerability Details
File Location:
scripts/query_product_knowledge.py, lines 13-20
Vulnerability Type: Hard-coded API credential
Risk Level: HighVulnerable Code
python API_URL = "https://ihealth.zhongan.com/api/support/api/outer/v1/product/knowledge/recall" API_KEY = "bfa9daba4a904448b23320596ce23c15" def query(msg: str, product_name: str) -> dict: payload = json.dumps({ "msg": msg, "apiKey": API_KEY, "productName": product_name }).encode("utf-8")Technical Analysis
A reusable API credential is stored as a plaintext constant and distributed with the project. Anyone who can read the package can recover the credential without executing the script.
The credential is placed directly into each JSON request. There is no runtime secret injection, credential scoping, expiration mechanism, or access-control boundary preventing another program from reusing it. Although the audited code only submits product-knowledge queries, the exact permissions granted to the credential are controlled by the remote service and cannot be determined from this repository.
Attack Path
- An attacker obtains a copy of the publicly or internally distributed Skill package.
- The attacker reads
scripts/query_product_knowledge.py. - The attacker extracts the value assigned to
API_KEY. - The attacker constructs requests to the hard-coded API endpoint with the extracted value in the
apiKeyfield. - The remote service processes those requests with whatever authority, quotas, or access rights are associated with the exposed credential.
No additional local privileges are required to extract the secret.
Impact Assessment
An attacker may obtain unauthorized access to the API functionality associated with this credential. Potential consequences include:
- Unauthorized consumption of API resources.
- Quota exhaustion or increased operating costs.
- Au ...[truncated 435 chars]
- Remediation
View remediation
Remediation Suggestions
- Immediately revoke or rotate the exposed credential.
- Remove the credential from the source tree and relevant version-control history.
- Load credentials from a protected environment variable or managed secret store:
python import os API_KEY = os.environ["ZHONGAN_API_KEY"] - Fail securely when the secret is missing rather than falling back to a built-in value.
- Use short-lived, narrowly scoped tokens instead of a long-lived shared key.
- Enforce server-side authorization, rate limits, request quotas, and abuse monitoring.
- Restrict the credential to the required endpoint and operation where supported.
- Add automated secret scanning to continuous integration and pre-commit checks.
- Review remote-service logs for unauthorized use of the exposed credential.
