T09 · Insecure Skill Coding Practices
- Location
scripts/portfolio.py:63- Finding
API Credential Can Be Redirected to an Arbitrary Network Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/portfolio.py, lines 63–96
Vulnerability Type:T09: Insecure Skill Coding Practices
Risk Level: MediumAffected code:
python 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) def fetch_prices(tickers: list[str]) -> dict[str, float]: """Fetch current prices for a list of tickers via AIsa API.""" if not tickers: return {} client = get_client() model = os.environ.get("AISA_MODEL", "gpt-4o") ticker_str = ", ".join(tickers) prompt = ( f"Fetch the current live price for each of these tickers: {ticker_str}\n\n" "Return ONLY a JSON object with ticker symbols as keys and current prices (numbers) as values.\n" "Example: {\"AAPL\": 195.50, \"BTC-USD\": 67234.10}\n" "No explanation. JSON only." ) try: response = client.chat.completions.create( model=model, messages=[ {"role": "system", "content": "You are a financial data fetcher. Use your tools to get current prices and return only JSON."}, {"role": "user", "content": prompt}, ], temperature=0, )Technical Analysis
The application reads the sensitive
AISA_API_KEYcredential from the environment and passes it to an OpenAI-compatible client. However, the destination used by that client is independently controlled through theAISA_BASE_URLenvironment variable.The code does not require HTTPS, validate the configured hostname, restrict the destination to an approved AISA domain, or warn the user when the default service has b ...[truncated 1954 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the runtime endpoint override if custom AISA-compatible services are not a documented requirement:
python return OpenAI( api_key=api_key, base_url="https://api.aisa.one/v1", ) - If endpoint customization is required, parse the URL and enforce:
- HTTPS only.
- An explicit hostname allowlist.
- No embedded username or password.
- An approved port and path.
- Require explicit user confirmation before sending an AISA credential to any nondefault endpoint.
- Use a separate credential for custom endpoints rather than forwarding
AISA_API_KEY. - Document exactly which portfolio information leaves the local system.
- Treat remote price data as untrusted: validate that the response is a JSON object containing only requested tickers and finite, nonnegative numeric prices.
- Remove the runtime endpoint override if custom AISA-compatible services are not a documented requirement:
