T09 · Insecure Skill Coding Practices
- Location
scripts/config.py:44- Finding
API Key Stored in a Plaintext Dotenv File Without Input Sanitization or Restrictive Permissions
- Content
View full analysis
bool: try: env_path = Path(".env") lines = [] if env_path.exists(): lines = env_path.read_text(encoding="utf-8").splitlines() found = False new_lines = [] for line in lines: if line.startswith("XBY_APIKEY="): new_lines.append(f"XBY_APIKEY={api_key}") found = True else: new_lines.append(line) if not found: new_lines.append(f"XBY_APIKEY={api_key}") env_path.write_text("\n".join(new_lines) + "\n", encoding="utf-8") os.environ["XBY_APIKEY"] = api_key return True except Exception as e: print(f"Failed to save API key: {e}") return False def set_api_key(api_key: str) -> bool: if not api_key or not api_key.strip(): return False api_key = api_key.strip() if not save_api_key_to_env(api_key): return False ``` ### Technical Analysis The application persists the API key directly in a plaintext `.env` file. It does not explicitly apply restrictive file permissions such as mode `0600`. When the file is created, its effective permissions therefore depend on the process umask. In an environment with a permissive umask, another local user or process may be able to read the credential. The API key is also interpolated directly into dotenv file contents without rejecting embedded carriage-return or newline characters. Calling `strip()` removes only leading and trailing whitespace; it does not remove newline characters within the value. A value such as `legitimate-key\nADDITIONAL_SETTING=attacker-value` can consequently introduce an additional persistent dotenv entry. The file update is not atomic. An inte ...[truncated 1952 chars]- Remediation
View remediation
