T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/search_knowledge.py:34
- Finding
- Hard-Coded API Bearer Credential## Vulnerability Details **File Location**: `scripts/search_knowledge.py`, lines 34–38 **Vulnerability Type**: Hard-coded authentication secret **Risk Level**: High ### Vulnerable Code ```python url = "https://chat2.orientlaw.cn/api/v1/embedding/search" headers = { "Authorization": "Bearer akmHjUkJfrqhLE2v3dXBN9YCM896kL5y", "Content-Type": "application/json" } ``` ### Technical Analysis The source code contains a bearer credential used to authenticate requests to the remote legal knowledge API. Any person with access to the project package or source repository can extract this credential without authorization or specialized tooling. A bearer token grants access based solely on possession. Because the secret is distributed with the Skill, the API cannot reliably distinguish legitimate Skill requests from requests made directly by a party who copied the credential. The token also cannot be rotated independently of the deployed source unless external configuration is introduced. ### Attack Path 1. An attacker downloads the Skill package or obtains read access to its source. 2. The attacker opens `scripts/search_knowledge.py` and copies the bearer token from the `Authorization` header. 3. The attacker constructs requests to `https://chat2.orientlaw.cn/api/v1/embedding/search` using the copied header. 4. The attacker submits arbitrary authenticated queries without invoking the Skill. 5. The attacker consumes API resources or exercises any other capabilities granted to that token until it is revoked or expires. ### Impact Assessment Successful exploitation provides unauthorized access to the remote API under the identity and permissions associated with the embedded token. This can enable quota consumption, service or billing abuse, resource exhaustion, and loss of attribution between authorized and unauthorized callers. The demonstrated scope is authenticated access to the configured embedding-search endpoint. Access to additional endpoints or data ...[truncated 105 chars]
- Remediation
- ## Remediation Suggestions 1. Revoke and rotate the exposed bearer token immediately. 2. Remove the credential from source code and repository history. 3. Load the credential at runtime from an environment variable or managed secret store, and terminate safely when it is unavailable. 4. Use short-lived, narrowly scoped credentials dedicated to this endpoint rather than a shared static token. 5. Assign separate credentials to different users, deployments, or service identities to preserve attribution and permit selective revocation. 6. Enforce server-side authorization, request quotas, and rate limits independently of client behavior. 7. Audit historical API activity for unauthorized use of the exposed token. 8. Add automated secret scanning to development and release pipelines to prevent recurrence. A safer configuration pattern is: ```python import os api_token = os.environ.get("ORIENTLAW_API_TOKEN") if not api_token: return { "success": False, "error": "API credential is not configured" } headers = { "Authorization": f"Bearer {api_token}", "Content-Type": "application/json" } ```
