T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/main.py:154
- Finding
- NCBI API Key Embedded and Repeated in Request URLs<![CDATA[ ## Vulnerability Details **File Location**: `scripts/main.py:154-168` **Vulnerability Type**: API credential exposure through URL query parameters and unbounded recursive retries **Risk Level**: Medium ### Vulnerable Code ```python if self.api_key: url = f"{url}&api_key={self.api_key}" if "?" in url else f"{url}?api_key={self.api_key}" try: req = urllib.request.Request( url, headers={ "User-Agent": "VariantAnnotator/1.0 (academic research)", "Accept": "application/json" } ) with urllib.request.urlopen(req, timeout=30) as response: return json.loads(response.read().decode('utf-8')) except urllib.error.HTTPError as e: if e.code == 429: time.sleep(1) return self._ncbi_request(url) ``` ### Technical Analysis The NCBI API key is appended directly to the URL query string. HTTPS protects the request in transit, but full URLs are commonly retained by proxies, network-monitoring products, debugging tools, exception telemetry, and application logs. Any such retention may expose the credential. The HTTP 429 retry path recursively passes the already modified URL back to `_ncbi_request()`. Because that method appends the API key on every invocation, repeated rate-limit responses produce a URL containing the credential multiple times. The retry has no maximum attempt count, so a sustained 429 response can also cause excessive recursion and eventual process failure. Network access to `eutils.ncbi.nlm.nih.gov` is necessary for the declared live ClinVar and dbSNP functionality. The problem is therefore not the network request itself, but avoidable credential handling and unbounded retry behavior. ### Attack Path 1. A user invokes the Skill with `--api-key`. 2. The key is appended to every NCBI request URL. 3. A proxy, monitoring service, debugger, or URL-level telemetry system records the full request URL. 4. An actor with access to those records obtains the API key and ...[truncated 694 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Prefer an NCBI-supported authentication mechanism that does not place credentials in URLs, if available. - If NCBI requires the API key as a query parameter, construct the request from immutable base parameters and add the key exactly once. - Ensure URLs are redacted before being logged, included in exceptions, or sent to telemetry. - Never include the API key in user-visible error messages. - Replace recursive retries with a bounded iterative retry loop. - Use exponential backoff with jitter and honor the `Retry-After` response header. - Set a maximum retry count and return a controlled error when it is exceeded. - Consider accepting the key through a protected environment variable or secret manager rather than a command-line argument, since command-line values may be visible in process listings. ]]>
