T09 · Insecure Skill Coding Practices
- Location
scripts/linkmind_interaction.py:122- Finding
Overbroad credential discovery can transmit unrelated secrets to LinkMind
- Content
View full analysis
Vulnerability Details
File Location:
scripts/linkmind_interaction.py:28-40, 122-168, 171-212, 271-275
Vulnerability Type: Overbroad secret discovery and unintended credential disclosure
Risk Level: HighVulnerable Code
python CONFIG_FILENAMES = ( "linkmind.key", "linkmind_api_key.txt", "config.json", "config.txt", "config.md", ".env", ) API_KEY_ENV_NAMES = ( "LINKMIND_API_KEY", "LAGI_LINKMIND_API_KEY", "LAGI_API_KEY", )python def extract_api_key_from_json(value: object) -> str | None: if isinstance(value, str): trimmed = value.strip() return trimmed or None if isinstance(value, dict): for key in ("apiKey", "api_key", "apikey", "key", "LINKMIND_API_KEY"): candidate = value.get(key) if isinstance(candidate, str) and candidate.strip(): return candidate.strip() for candidate in value.values(): found = extract_api_key_from_json(candidate) if found: return found if isinstance(value, list): for item in value: found = extract_api_key_from_json(item) if found: return found return None def extract_api_key_from_text(text: str) -> str | None: stripped = text.strip() if not stripped: return None try: parsed = json.loads(stripped) found = extract_api_key_from_json(parsed) if found: return found except json.JSONDecodeError: pass assignment = re.search( r"(?im)^\s*(?:LINKMIND_API_KEY|LAGI_LINKMIND_API_KEY|LAGI_API_KEY|api[_-]?key|apikey|key)\s*[:=]\s*[\"']?([^\"'\s`]+)", text, ) if assignment: return assignment.group(1).strip() raw_key = re.search(r"\bsk-[A-Za-z0-9._-]+\b", text) if raw_key: retur ...[truncated 4500 chars]- Remediation
View remediation
Remediation Suggestions
- Require an explicit
--configpath by default, particularly for operations that transmit credentials. - If automatic discovery is retained, restrict it to LinkMind-specific filenames such as
linkmind.keyandlinkmind_api_key.txt; do not inspect.env,config.json,config.txt, orconfig.mdautomatically. - Accept only exact LinkMind-specific fields such as
LINKMIND_API_KEYorapiKey. - Remove support for generic names such as
keyand broad environment variables such asLAGI_API_KEY. - Remove recursive traversal that accepts arbitrary JSON string values.
- Remove the fallback that treats any single-token text file as a valid credential.
- Validate the expected LinkMind key format before network transmission and reject ambiguous files containing multiple candidate values.
- Warn the user and require confirmation if a credential was discovered implicitly rather than supplied through an explicit LinkMind configuration source.
- Keep configuration-file permissions restricted to the agent user and avoid storing credential files in project repositories.
- Require an explicit
