T09 · Insecure Skill Coding Practices
Error
- Location
- src/index.ts:1716
- Finding
- API Key Disclosure Through Arbitrary Runtime API Endpoint Switching<![CDATA[ ## Vulnerability Details **File Location**: `src/index.ts:348-351`, `src/index.ts:1716-1773`, and `src/index.ts:2064-2090` **Vulnerability Type**: Arbitrary credential destination and production credential reuse **Risk Level**: Critical ### Vulnerable Code ```typescript const DEFAULT_PRODUCTION_BASE_URL = normalizeBaseUrl( process.env.LISTER_PRODUCTION_BASE_URL || 'https://api.mylister.dev' ); const DEFAULT_STAGING_BASE_URL = process.env.LISTER_STAGING_BASE_URL || process.env.LISTER_STAGING_URL; const DEFAULT_PRODUCTION_API_KEY = process.env.LISTER_PRODUCTION_API_KEY || process.env.LISTER_API_KEY || ''; const DEFAULT_STAGING_API_KEY = process.env.LISTER_STAGING_API_KEY || process.env.LISTER_API_KEY || ''; ``` ```typescript let runtimeBaseUrl = normalizeBaseUrl(CONFIG.baseUrl); const runtimeApiKeys: Record<ApiEnvironment, string> = { production: DEFAULT_PRODUCTION_API_KEY, staging: DEFAULT_STAGING_API_KEY, custom: CONFIG.apiKey, }; let runtimeApiEnvironment = resolveRuntimeApiEnvironment(runtimeBaseUrl); let runtimeApiKey = runtimeApiKeys[runtimeApiEnvironment]; let client = new ListerClient(runtimeBaseUrl, runtimeApiKey); function getConfiguredApiKey(targetEnvironment: ApiEnvironment): string { return runtimeApiKeys[targetEnvironment]; } function switchApiEnvironment(targetBaseUrl: string, note?: string): string { const normalizedBaseUrl = normalizeBaseUrl(targetBaseUrl); try { new URL(normalizedBaseUrl); } catch { return `❌ Could not switch API environment because "${targetBaseUrl}" is not a valid URL.`; } runtimeBaseUrl = normalizedBaseUrl; runtimeApiEnvironment = resolveRuntimeApiEnvironment(runtimeBaseUrl); runtimeApiKey = getConfiguredApiKey(runtimeApiEnvironment); client = new ListerClient(runtimeBaseUrl, runtimeApiKey); const environment = runtimeApiEnvironment; const suffix = note ? ` ${note}` : ''; if (!runtimeApiKey) { return `✅ API ${environment} environment set to ${environment === ' ...[truncated 3760 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove arbitrary runtime API URL switching unless it is essential to the supported functionality. 2. Enforce an exact allowlist of trusted HTTPS origins, such as the documented production and staging MyLister origins. 3. Initialize the custom-environment key as empty. Never inherit `LISTER_API_KEY`, production keys, or staging keys for custom origins. 4. Bind each credential to a specific origin and refuse to send it when the request origin differs. 5. Reject: - Plain HTTP URLs. - URLs containing usernames or passwords. - Unsupported schemes. - Loopback, link-local, private-network, and metadata-service destinations. 6. Require explicit user confirmation that displays the complete destination origin before changing environments. 7. Do not permit untrusted Agent content to set credentials or endpoints without a trusted user-approval step. 8. Add tests proving that production credentials are never sent to custom hosts and that unapproved origins are rejected. ]]>
