T09 · Insecure Skill Coding Practices
- Location
scripts/config.py:48- Finding
API Key Persisted in a Plaintext Environment File
- Content
View full analysis
Vulnerability Details
File Location:
scripts/config.py, lines 48-63
Vulnerability Type: Plaintext storage of sensitive credentials
Risk Level: Mediumpython 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_keyTechnical Analysis
The supplied API key is written directly to a
.envfile in the current working directory without encryption or an explicit restrictive file mode. When the file is newly created, its permissions depend on the process umask. When it already exists, potentially insecure permissions are retained.The credential may consequently be accessible to other local users or processes with read access to the working directory. The file may also be included inadvertently in source-control commits, workspace archives, backups, diagnostic bundles, or container images.
The API key is additionally copied into the process environment. This is normal for many applications, but it expands exposure to process inspection, crash reporting, and child processes in environments where those channels are not adequately isolated.
Attack Path
- A user supplies an API key through the skill's documented configuration workflow.
set_api_key()passes the credential tosave_api_key_to_env().- The function stores the credential as
XBY_APIKEY=<secret>in the working-directory.envfile. - An attacker obtains loca ...[truncated 663 chars]
- Remediation
View remediation
Remediation Suggestions
- Prefer a platform-managed secret store, operating-system credential manager, or session-only environment variable instead of writing credentials to the project directory.
- If file persistence is unavoidable, create the file atomically with mode
0600and verify that an existing file is not readable by group or other users. - Store secrets in a dedicated user configuration directory rather than the current working directory.
- Ensure
.envis excluded from source control, build artifacts, logs, backups, and support bundles. - Validate the supplied value and reject newline or control characters before serialization.
- Avoid exposing secrets to unnecessary child processes and redact them from errors, telemetry, and crash reports.
- Document credential revocation and rotation procedures for users whose
.envfile may have been exposed.
