T09 · Insecure Skill Coding Practices
- Location
scripts/config.py:43- Finding
API Key Persisted Without Restrictive File Permissions
- Content
View full analysis
bool: """将API key保存到.env文件""" 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"保存API key失败: {e}") return False ``` ### Technical Analysis The function persists the API key as plaintext in a `.env` file using `Path.write_text()`. It neither creates the file with a restrictive mode such as `0600` nor verifies or corrects the permissions of an existing file. The resulting permissions depend on the process umask and pre-existing file state. In a shared workspace, container volume, CI environment, or multi-user host, another local principal may be able to read the credential. The function also follows filesystem links normally. If an attacker can create or replace `.env` with a symbolic link before this function runs, the write could target another file accessible to the process. The exact consequences of that condition depend on the process privileges and filesystem protections. ### Attack Path 1. An attacker obtains local access to the project directory or a process capable of reading files in that directory. 2. The user supplies an API key as required by the Skill ...[truncated 1034 chars]- Remediation
View remediation
