T09 · Insecure Skill Coding Practices
- Location
scripts/browser.py:92- Finding
Authentication Cookies Are Stored in an Unprotected Plaintext File
- Content
View full analysis
Vulnerability Details
File Location:
scripts/browser.py:92-97
Vulnerability Type: Plaintext storage of reusable session credentials
Risk Level: Highpython def save_cookies(self): """Save cookies to a file.""" cookies = self.context.cookies() with open(self.cookie_path, 'w', encoding='utf-8') as f: json.dump(cookies, f, ensure_ascii=False, indent=2) print(f"[Cookie] Saved to {self.cookie_path}")The cookie path is derived from a fixed filename in the script directory:
python def __init__(self): self.cookie_path = Path(__file__).parent / COOKIE_FILETechnical Analysis
After a successful login, the application retrieves every cookie from the active browser context and serializes the complete collection to
scripts/fanqie_cookies.json. Browser session cookies are authentication credentials that can permit account access without knowledge of the account password.The file is created using the process's default permissions. The code does not:
- Encrypt the stored credentials.
- Use an operating-system credential vault.
- Explicitly restrict the file to the current user.
- Validate the permissions of an existing cookie file.
- Prevent the cookie file from being included in backups or source-control archives.
- Remove expired credentials automatically.
The documentation states that cookies may remain valid for approximately 24 hours. Therefore, the exposure window is long enough for copied credentials to be reused.
Attack Path
- A user runs the login workflow and authenticates through the browser.
scripts/login.py:47-48callsself.browser.save_cookies().- The complete authenticated cookie collection is written in plaintext to
scripts/fanqie_cookies.json. - Another local user, compromised process, backup service, synchronization client, or accidentally published project archive obtains the file.
- The attacker import ...[truncated 736 chars]
- Remediation
View remediation
Remediation Suggestions
- Store session credentials in an operating-system credential manager, such as Windows Credential Manager, macOS Keychain, or a Linux Secret Service implementation.
- If file-based storage is unavoidable, encrypt the cookie data with a key that is not stored beside the encrypted file.
- Create the file atomically with owner-only permissions, such as mode
0600on POSIX systems. - Before reading an existing file, reject symbolic links, verify file ownership, and reject group- or world-readable permissions.
- Store credentials in a dedicated private application-data directory rather than the source tree.
- Add the credential filename to
.gitignoreand applicable backup or synchronization exclusions. - Delete the file when the session expires and retain the existing deletion behavior on logout.
- Consider using Playwright storage state only if it receives the same encryption and permission protections, because storage-state files also contain reusable credentials.
