T09 · Insecure Skill Coding Practices
- Location
scripts/api_client.js:8- Finding
API token can be transmitted to an arbitrary non-TLS endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/api_client.js, lines 8–91
Vulnerability Type: Unrestricted credential destination and plaintext token transmission
Risk Level: MediumVulnerable Code
js const BASE_URL = process.env.API_BASE_URL || 'https://api.igent.net/api'; function _httpRequest(reqUrl, headers = {}) { return new Promise((resolve, reject) => { const parsed = new URL(reqUrl); const mod = parsed.protocol === 'https:' ? https : http; const options = { hostname: parsed.hostname, port: parsed.port, path: parsed.pathname + parsed.search, method: 'GET', headers: { 'User-Agent': USER_AGENT, ...headers }, }; const req = mod.request(options, (res) => { let body = ''; res.on('data', (chunk) => (body += chunk)); res.on('end', () => resolve({ status: res.statusCode, body })); }); req.on('error', reject); req.end(); }); } async function getToken() { const token = _loadToken(); if (token) return token; return _fetchNewToken(); } async function get(endpoint, params) { let token; try { token = await getToken(); } catch (e) { return { error: e.message }; } const parsed = new URL(`${BASE_URL}${endpoint}`); if (params) { for (const [key, value] of Object.entries(params)) { parsed.searchParams.set(key, value); } } const headers = { accept: 'application/json', 'X-API-Token': token, }; try { const { status, body } = await _httpRequest(parsed.toString(), headers);Technical Analysis
The API destination is controlled by the
API_BASE_URLenvironment variable without protocol or hostname validation. The request helper explicitly supports both HTTPS and unencrypted HTTP. After loading a valid cached token,get()attaches it to theX-API-Tokenheader and sends it to the configured de ...[truncated 1661 chars]- Remediation
View remediation
Remediation Suggestions
- Require
https:for every authenticated request and reject all other protocols before loading or attaching a token. - Restrict authenticated destinations to an explicit hostname allowlist, preferably only
api.igent.net. - Remove the
API_BASE_URLoverride in production if alternate endpoints are not required. - If configurability is necessary, separate trusted development configuration from production execution and validate the complete origin, including protocol, hostname, and port.
- Do not attach
X-API-Tokenwhen the destination differs from the approved API origin. - Ensure redirects are either disabled or revalidated before forwarding credentials.
- Invalidate or rotate any token suspected of having been sent to an untrusted destination.
- Require
