T09 · Insecure Skill Coding Practices
- Location
scripts/portfolio.py:57- Finding
API Credential Can Be Redirected to an Arbitrary Network Endpoint
- Content
View full analysis
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 application retrieves the sensitive `AISA_API_KEY` credential and supplies it to an OpenAI-compatible client. Although the default endpoint is `https://api.aisa.one/v1`, the destination can be replaced with any value through the undocumented `AISA_BASE_URL` environment variable. The code does not enforce HTTPS, validate the URL scheme, or restrict the hostname to an approved provider. Consequently, a compromised launcher, environment configuration, automation workflow, or wrapper script can redirect authenticated requests to an attacker-controlled server. Sending ticker symbols to the declared pricing service is necessary for the live-pricing feature. Permitting unrestricted redirection of the authentication credential, however, exceeds the minimum destination privilege required by that functionality. ### Attack Path 1. An attacker gains the ability to influence the environment used to launch the Skill, such as a shell profile, task configuration, wrapper, or CI environment. 2. The attacker sets `AISA_BASE_URL` to an endpoint under their control. 3. The user invokes the `show` command for a nonempty portfolio. 4. `fetch_prices()` calls `get_client()`, which constructs the client with the attacker-controlled base URL and the legitimate `AISA_API_KEY`. 5. The client sends an authenticated request to the attacker-controlled endpoint. 6. The attacker captures the API ...[truncated 584 chars]- Remediation
View remediation
