T09 · Insecure Skill Coding Practices
- Location
sports-pronostics.js:6- Finding
Environment-Controlled Request Host Can Expose the RapidAPI Credential
- Content
View full analysis
Vulnerability Details
File Location:
sports-pronostics.js, lines 6–8 and 14–21
Vulnerability Type: Unvalidated credential destination
Risk Level: HighVulnerable Code
js const RAPIDAPI_KEY = process.env.RAPIDAPI_KEY; const RAPIDAPI_HOST = process.env.RAPIDAPI_HOST || "free-api-live-football-data.p.rapidapi.com"; const BASE_URL = `https://${RAPIDAPI_HOST}`; async function fetchFootball(endpoint, params = {}) { const url = new URL(`${BASE_URL}/${endpoint}`); Object.entries(params).forEach(([k, v]) => url.searchParams.append(k, v)); const res = await fetch(url.toString(), { headers: { "X-RapidAPI-Key": RAPIDAPI_KEY, "X-RapidAPI-Host": RAPIDAPI_HOST } });Technical Analysis
The
RAPIDAPI_HOSTenvironment variable controls the outbound request destination without hostname validation or an allowlist. The same function unconditionally attaches the sensitiveRAPIDAPI_KEYheader to requests made to that destination.Network access and use of a RapidAPI credential are consistent with the Skill's declared real-time football-data functionality. However, allowing configuration to redirect that credential to an arbitrary HTTPS server is not necessary for that functionality and violates least-privilege credential handling.
An attacker must be able to influence the process environment or deployment configuration. If that prerequisite is met, no code modification is needed to redirect the credential.
Attack Path
- An attacker with control over deployment configuration sets
RAPIDAPI_HOSTto an attacker-controlled HTTPS hostname. - The Skill starts and constructs
BASE_URLfrom the malicious hostname. - A user or Agent invokes any exported football-data tool, such as
getUpcomingMatchesorgetLiveScores. fetchFootball()sends the request to the attacker-controlled server.- The request includes the victim's
RAPIDAPI_KEYin the ...[truncated 484 chars]
- An attacker with control over deployment configuration sets
- Remediation
View remediation
Remediation Suggestions
- Hard-code the approved API origin when only one provider is supported:
js const RAPIDAPI_HOST = "free-api-live-football-data.p.rapidapi.com"; const BASE_URL = `https://${RAPIDAPI_HOST}`; - If multiple hosts are required, validate the configured value with an exact allowlist before constructing the URL:
js const ALLOWED_HOSTS = new Set([ "free-api-live-football-data.p.rapidapi.com" ]); const configuredHost = process.env.RAPIDAPI_HOST || "free-api-live-football-data.p.rapidapi.com"; if (!ALLOWED_HOSTS.has(configuredHost)) { throw new Error("Unapproved RapidAPI host"); } - Verify the final URL's protocol and hostname immediately before attaching credentials. Require HTTPS and exact hostname equality; do not rely on suffix matching.
- Fail closed when
RAPIDAPI_KEYis absent rather than sending an undefined credential. - Prevent redirects from forwarding the credential to another origin. Disable automatic redirects or manually validate every redirect destination before resending sensitive headers.
- Restrict who can modify the Skill's environment variables and deployment configuration.
- Rotate the RapidAPI key if the Skill has previously run with an untrusted
RAPIDAPI_HOSTvalue, and review provider logs for unauthorized use.
- Hard-code the approved API origin when only one provider is supported:
