T09 · Insecure Skill Coding Practices
- Location
SKILL.md:34- Finding
Private Keys and API Keys Stored in Plaintext JSON
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 34-41
Vulnerability Type: Plaintext storage of sensitive credentials
Risk Level: HighVulnerable Code
python payload = { "public_key": public_key, "private_key": private_key, "api_key": api_key, } with open(output_file, "w", encoding="utf-8") as file: json.dump(payload, file, ensure_ascii=False, indent=2)Technical Analysis
The function stores a private key and API key directly in an unencrypted JSON file. Masking data in an input dialog only protects it from visual observation during entry; it does not protect the resulting file.
The use of
open(output_file, "w")does not explicitly enforce owner-only permissions. Effective permissions consequently depend on the operating system, process umask, existing file permissions, and destination. The destination is also caller-controlled, allowing credentials to be placed in a shared directory, synchronized folder, repository, backup scope, or other unsafe location.No encryption, operating-system keychain integration, secret-manager integration, destination validation, retention control, or secure deletion mechanism is present.
Attack Path
- A user runs the file and enters a private key and API key.
- The function serializes both credentials into an ordinary JSON object.
- The credentials are written in plaintext to
demo_credentials.jsonwhen the file is executed directly, or to another caller-selected path. - A local user, compromised process, backup service, synchronization client, repository scanner, or other principal with access to the destination reads the JSON file.
- The exposed private key or API key is used to impersonate the user or access services authorized by those credentials.
Impact Assessment
Exploitation does not directly grant operating-system privilege escalation. However, an attacker can obtain the full privileges associat ...[truncated 364 chars]
- Remediation
View remediation
Remediation Suggestions
- Do not collect or persist private keys unless this is strictly required.
- Store credentials in an operating-system keychain, hardware-backed keystore, or dedicated secret-management service.
- If file storage is unavoidable, encrypt the data with a key that is not stored alongside the ciphertext.
- Create the file atomically with owner-only permissions, such as mode
0600on POSIX systems, and verify permissions after creation. - Reject destinations in shared, temporary, synchronized, or source-controlled directories.
- Prevent symbolic-link and time-of-check/time-of-use attacks when creating the destination.
- Mask API-key entry in the same manner as private-key entry.
- Clearly warn users that credentials are sensitive and must not be committed, synchronized, or included in backups.
- Define credential retention and secure deletion procedures.
- Rotate any credential previously written by this implementation if unauthorized access to the output file is possible.
