T09 · Insecure Skill Coding Practices
- Location
scripts/recall_radar.py:95- Finding
OpenFDA API Key Exposed in Verbose Logs
- Content
View full analysis
Vulnerability Details
File Location:
scripts/recall_radar.py, lines 95–103
Vulnerability Type: Plaintext sensitive-data exposure through logging
Risk Level: MediumVulnerable Code:
python def fetch_recalls(api_key=None, limit=1000, verbose=False): q = urllib.parse.quote('status:"Ongoing"') url = f"{OPENFDA}?search={q}&limit={limit}" if api_key: url += f"&api_key={api_key}" if verbose: print(f"# fetching {url}", file=sys.stderr) req = urllib.request.Request(url, headers={"User-Agent": "food-recall-radar/1.0"}) with urllib.request.urlopen(req, timeout=30) as r:Technical Analysis
The optional openFDA API key is appended to the request URL. When
--verboseis enabled, the complete URL is printed to standard error without redacting theapi_keyquery parameter.Consequently, the credential can be copied into redirected logs, CI output, terminal captures, monitoring systems, or AI Agent execution transcripts. HTTPS protects the network request in transit but does not protect the key after the application emits it locally. Query-string credentials may also be retained in server or intermediary access logs.
The outbound request itself is consistent with the Skill's declared live-recall functionality. Pantry brands, products, UPCs, lots, notes, and local files are not included in the request. The vulnerability is the unnecessary disclosure of the authentication credential in verbose output, not undisclosed pantry-data exfiltration.
Attack Path
- A user supplies an openFDA key through
--api-keyor theOPENFDA_API_KEYenvironment variable. - The user, an automation system, or an Agent invokes
matchorauditwith--verbose. get_recalls()passes the key tofetch_recalls().fetch_recalls()inserts the key into the URL query string.- The complete URL is written to standard error.
- An attacker with access to colle ...[truncated 672 chars]
- A user supplies an openFDA key through
- Remediation
View remediation
Remediation Suggestions
-
Never print the complete authenticated URL. Log only non-sensitive request metadata, such as the endpoint, search expression, and result limit.
-
Redact the key before logging:
python if verbose: safe_url = f"{OPENFDA}?search={q}&limit={limit}" if api_key: safe_url += "&api_key=***" print(f"# fetching {safe_url}", file=sys.stderr) -
Prefer an authentication header instead of a query parameter if openFDA supports that authentication method.
-
Discourage command-line key submission because arguments can appear in shell history and process listings. Prefer
OPENFDA_API_KEYor a protected configuration source. -
Add an automated test asserting that verbose output never contains the supplied API key.
-
If exposure has already occurred, rotate the affected key and remove or restrict access to retained logs and transcripts containing it.
-
