T09 · Insecure Skill Coding Practices
- Location
scripts/video_gen.js:19- Finding
Arbitrary API Endpoint Overrides Can Exfiltrate WeryAI Credentials and Generation Data
- Content
View full analysis
Vulnerability Details
File Location:
scripts/video_gen.js, lines 19–91
Vulnerability Type: Unrestricted authenticated endpoint configuration
Risk Level: MediumVulnerable Code
js const BASE_URL = (process.env.WERYAI_BASE_URL || 'https://api.weryai.com').replace(/\/$/, ''); const MODELS_BASE_URL = (process.env.WERYAI_MODELS_BASE_URL || 'https://api-growth-agent.weryai.com').replace( /\/$/, '', ); const MODELS_API_PATH = '/growthai/v1/video/models';js async function httpJson(method, fullUrl, body, apiKey) { const headers = { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json', }; const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), 30_000); try { const res = await fetch(fullUrl, { method, headers, body: body != null ? JSON.stringify(body) : undefined, signal: controller.signal, }); clearTimeout(timer); let data; try { data = await res.json(); } catch { data = { status: res.status, msg: `Non-JSON response (HTTP ${res.status})` }; } return { httpStatus: res.status, ...data }; } catch (err) { clearTimeout(timer); if (err.name === 'AbortError') { throw new Error(`Request timeout: ${method} ${fullUrl}`); } throw err; } } async function apiRequest(method, path, body, apiKey) { return httpJson(method, BASE_URL + path, body, apiKey); } async function fetchModelsRegistry(apiKey) { return httpJson('GET', MODELS_BASE_URL + MODELS_API_PATH, null, apiKey); }Technical Analysis
The script allows
WERYAI_BASE_URLandWERYAI_MODELS_BASE_URLto define arbitrary API origins. These values are used without validating their scheme, hostname, port, or authority components.Every request made through
httpJson()includes the user'sWERYAI_API_KEYin an ` ...[truncated 2568 chars]- Remediation
View remediation
Remediation Suggestions
-
Enforce HTTPS
- Parse configured endpoints with the standard
URLclass. - Reject every URL whose protocol is not exactly
https:.
- Parse configured endpoints with the standard
-
Allowlist trusted destinations
- Permit only the documented hosts:
api.weryai.comfor generation and status requests.api-growth-agent.weryai.comfor the model registry.
- Reject userinfo, unexpected ports, IP literals, and unapproved subdomains.
- Permit only the documented hosts:
-
Avoid unrestricted production endpoint overrides
- Remove the override variables if custom endpoints are not required.
- If development overrides are necessary, require an explicit development-only flag and a separate test credential.
- Do not send a production WeryAI credential to custom origins.
-
Harden redirect handling
- Prefer
redirect: 'manual'for authenticated requests. - If redirects must be supported, validate every redirect target against the same HTTPS and hostname allowlist before issuing another authenticated request.
- Prefer
-
Separate credentials by service
- If custom model registries or proxy services are legitimate requirements, use dedicated, narrowly scoped credentials rather than automatically forwarding
WERYAI_API_KEY.
- If custom model registries or proxy services are legitimate requirements, use dedicated, narrowly scoped credentials rather than automatically forwarding
-
Fail closed before constructing authorization headers
- Validate the complete destination URL before creating or attaching the bearer header.
- Return a clear configuration error when validation fails.
A hardened validation pattern could follow this structure:
js function trustedEndpoint(rawUrl, allowedHostname) { const parsed = new URL(rawUrl); if (parsed.protocol !== 'https:') { throw new Error('API endpoint must use HTTPS.'); } if (parsed.hostname !== allowedHostname) { throw new Error(`Untrusted API hostname: ${parsed.hostname}`); } if (parsed.username || parsed.password || parsed.port) { throw new Error('API endpoint must not contain useri ...[truncated 357 chars]-
