T09 · Insecure Skill Coding Practices
- Location
scripts/finddata.py:23- Finding
API Key Exposure Through an Unrestricted Base URL
- Content
View full analysis
Vulnerability Details
File Location:
scripts/finddata.py, lines 23–31 and 38–42
Vulnerability Type: Credential disclosure through an attacker-controlled API origin
Risk Level: MediumVulnerable Code
python def __init__( self, api_key: Optional[str] = None, base_url: Optional[str] = None, ): self.api_key = api_key or os.environ.get("FINDDATA_API_KEY", "") self.base_url = (base_url or os.environ.get("FINDDATA_BASE_URL", self.DEFAULT_BASE_URL)).rstrip("/") self.session = requests.Session() if self.api_key: self.session.headers["X-API-Key"] = self.api_key self.session.headers["Content-Type"] = "application/json" def query(self, question: str, strategy: str = "smart") -> dict: resp = self.session.post( f"{self.base_url}/query", json={"query": question, "strategy": strategy}, )The same credential-bearing session is also used by
catalog()andhealth():python def catalog(self) -> dict: """List all available data sources.""" resp = self.session.get(f"{self.base_url}/catalog") resp.raise_for_status() return resp.json() def health(self) -> dict: """Check API health status.""" resp = self.session.get(f"{self.base_url}/health") resp.raise_for_status() return resp.json()Technical Analysis
The client stores
X-API-Keyas a default session header while allowing the request origin to be selected through either thebase_urlconstructor parameter or theFINDDATA_BASE_URLenvironment variable. It performs no scheme enforcement, hostname allowlisting, or explicit authorization check before forwarding the credential.Consequently, anyone who can influence client construction or the process environment can cause the API key to be transmitted to an arbitrary HTTP or HTTPS server. Allowing plaintext HTTP also permits interception by a network-positioned attacker.
Because the header is configured on the shared session, the issue aff ...[truncated 1339 chars]
- Remediation
View remediation
Remediation Suggestions
- Restrict authenticated requests to an explicit HTTPS origin allowlist, such as
https://finddata.ai. - Parse the URL and reject non-HTTPS schemes, embedded user information, malformed hosts, and unexpected ports.
- Do not attach credentials as global session headers when requests may target configurable origins. Add
X-API-Keyonly after validating each request URL. - If custom endpoints are required, make them an explicit opt-in and require separate credentials rather than reusing the production API key.
- Disable cross-origin redirects for authenticated requests or validate every redirect target before forwarding authentication headers.
- Treat
FINDDATA_BASE_URLas security-sensitive configuration and prevent untrusted users from controlling the process environment. - Add tests confirming that credentials are never sent to plaintext, unapproved, or redirected origins.
- Restrict authenticated requests to an explicit HTTPS origin allowlist, such as
