T09 · Insecure Skill Coding Practices
- Location
scripts/config.py:53- Finding
API Key Persisted in a Plaintext File Without Explicit Permission Controls
- Content
View full analysis
Vulnerability Details
File Location:
scripts/config.py:53-60
Vulnerability Type: Plaintext credential storage
Risk Level: MediumVulnerable Code
python 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_keyTechnical Analysis
The supplied API key is written directly to
.envas plaintext. The implementation does not explicitly create the file with restrictive permissions or verify the permissions of an existing file. Its confidentiality therefore depends on the process umask, existing filesystem permissions, deployment environment, backup configuration, and repository hygiene.The update is also performed directly rather than through a securely created temporary file followed by an atomic replacement. While this primarily creates an integrity and reliability concern, the principal security issue is persistent plaintext credential storage.
Attack Path
- A user provides a valid API key as required by the skill.
set_api_key()invokessave_api_key_to_env().- The key is written to the project working directory in
.env. - A local user or process with permission to read that file, a backup collector, or a repository operation that includes
.envobtains the credential. - The exposed key is used to make unauthorized requests to the XiaoBenYang API until it is revoked.
Exploitation requires access to the
.envfile or to a copy of it; this code does not itself grant such access.Impact Assessment
Disclosure grants the attacker the API authorization associated with
XBY_APIKEY. This may permit unauthorized API usage, consumption of account quotas, access to responses available to that API identity, and charges or servi ...[truncated 125 chars]- Remediation
View remediation
Remediation Suggestions
- Prefer an operating-system credential manager, orchestrator secret, or session-only environment variable instead of persistent plaintext storage.
- If file persistence is required, create the file with owner-only permissions such as
0600and reject or correct an existing file with broader permissions. - Write updates through a securely created temporary file in the same directory, apply restrictive permissions, and atomically replace the destination.
- Ensure
.envis excluded from source control, build artifacts, diagnostics, and backups that are not approved to contain secrets. - Avoid printing exception details that could reveal sensitive paths or values.
- Document credential rotation and immediately revoke keys suspected of exposure.
