T09 · Insecure Skill Coding Practices
- Location
scripts/watchlist.py:51- Finding
Arbitrary API Endpoint Override Can Disclose the AISA API Key
- Content
View full analysis
Vulnerability Details
File Location:
scripts/watchlist.py, lines 51–57
Vulnerability Type: Unrestricted authenticated API endpoint configuration
Risk Level: Mediumpython def get_client() -> OpenAI: api_key = os.environ.get("AISA_API_KEY") if not api_key: print("❌ Error: AISA_API_KEY environment variable is not set.", file=sys.stderr) sys.exit(1) base_url = os.environ.get("AISA_BASE_URL", "https://api.aisa.one/v1") return OpenAI(api_key=api_key, base_url=base_url)Technical Analysis
The code reads
AISA_BASE_URLfrom the process environment without validating its scheme or hostname. It then creates an OpenAI client that usesAISA_API_KEYto authenticate requests to that endpoint.The endpoint override may be useful in a controlled development environment, but unrestricted redirection is not necessary for the Skill's declared production functionality. A malicious or accidentally unsafe value can cause authenticated requests to be sent to an untrusted server. The code does not require HTTPS, enforce an approved-host allowlist, or prevent the production credential from being attached to custom endpoints.
When the
checkcommand runs,fetch_watchlist_data()submits the user's watchlist ticker symbols in a chat-completions request through this client. Therefore, the endpoint can receive both the authentication credential carried by the client and the submitted ticker data.Attack Path
- An attacker gains the ability to influence the Skill's runtime environment, deployment configuration, shell profile, or invocation wrapper.
- The attacker sets
AISA_BASE_URLto an endpoint under their control, such ashttps://attacker.example/v1. - The user or Agent invokes
python3 scripts/watchlist.py check. get_client()constructs an OpenAI client using the attacker-controlled base URL and the legitimateAISA_API_KEY.fetch_watchlist_data()sends a chat-completions request containing t ...[truncated 909 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the
AISA_BASE_URLoverride if alternate API endpoints are not required for the declared functionality. - If endpoint customization is necessary, parse the URL and require an approved scheme and hostname:
- Require
https. - Reject embedded credentials.
- Allowlist trusted hosts such as
api.aisa.one. - Reject loopback, link-local, private-network, and unapproved hosts where applicable.
- Require
- Never automatically attach the production
AISA_API_KEYto an arbitrary custom endpoint. Require a separate credential variable for development or custom endpoints. - Fail closed when URL validation fails and provide a clear error without printing credential material.
- Document all permitted endpoints and explain that API requests disclose ticker data to the selected provider.
- Use narrowly scoped, revocable API credentials and rotate any key suspected of having been exposed.
- Validate the API response against a strict schema before using it for alerts, including ticker keys, numeric price fields, bounded RSI values, and an allowlist of signal values.
- Remove the
