T09 · Insecure Skill Coding Practices
Error
- Location
- index.js:111
- Finding
- Credential Exfiltration Through Attacker-Controlled OpenAPI Specifications<![CDATA[ ## Vulnerability Details **File Location**: `index.js:45-49`, `index.js:111-114`, `index.js:151-173` **Vulnerability Type**: Untrusted credential-to-origin binding **Risk Level**: Critical ### Vulnerable Code ```js if (specPath.startsWith('http')) { const res = await fetch(specPath); if (!res.ok) throw new Error(`Failed to fetch spec: ${res.statusText}`); content = await res.text(); } ``` ```js let url = spec.servers?.[0]?.url || 'http://localhost'; if (!url.startsWith('http')) url = `https://${url}`; // Default to https if relative or missing protocol ``` ```js // Simple Auth Injection (Bearer/API Key from ENV) // This is a heuristic: match security scheme names to ENV vars if (spec.components?.securitySchemes) { for (const [schemeName, scheme] of Object.entries(spec.components.securitySchemes)) { const envVarName = schemeName.toUpperCase().replace(/[^A-Z0-9]/g, '_'); // e.g., api_key -> API_KEY const token = process.env[envVarName] || process.env[`${envVarName}_TOKEN`] || process.env[`${envVarName}_KEY`]; if (token) { if (scheme.type === 'http' && scheme.scheme === 'bearer') { headers['Authorization'] = `Bearer ${token}`; } else if (scheme.type === 'apiKey' && scheme.in === 'header') { headers[scheme.name] = token; } } } } console.error(`Executing ${selectedMethod.toUpperCase()} ${fullUrl}`); // Log to stderr to keep stdout clean for JSON output const res = await fetch(fullUrl, { method: selectedMethod, headers, body: ['POST', 'PUT', 'PATCH'].includes(selectedMethod.toUpperCase()) ? JSON.stringify(body) : undefined, }); ``` ### Technical Analysis The OpenAPI specification controls both the destination in `servers[0].url` and the security-scheme name used to select an environment variable. The implementation converts the scheme name into an environment-variable name and automatically attaches any matching local secre ...[truncated 2069 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove heuristic environment-variable discovery based on untrusted security-scheme names. 2. Require an explicit configuration that binds each credential to: - A fixed environment-variable name. - An exact HTTPS origin. - An expected authentication scheme and header name. 3. Do not send any credential unless the final request origin exactly matches the credential's configured origin. 4. Maintain an explicit allowlist of trusted API hosts. 5. Show the user the destination host and credential identity, without exposing the credential value, before first use. 6. Reject cross-origin redirects and revalidate every redirect target. 7. Treat remotely downloaded OpenAPI documents as untrusted data. 8. Default to unauthenticated requests when a specification has not been explicitly trusted. 9. Consider requiring cryptographic verification or pinned hashes for approved specifications. 10. Add security tests using malicious specifications that attempt to map scheme names to unrelated environment variables. ]]>
