T09 · Insecure Skill Coding Practices
- Location
12306_client.py:48- Finding
Authentication Session Cookies Stored in Plaintext
- Content
View full analysis
Vulnerability Details
File Location:
12306_client.py:48-51
Vulnerability Type: Plaintext storage of sensitive authentication data
Risk Level: MediumVulnerable Code
python def save_cookies(self): try: with open(self.cookie_file, "w", encoding="utf-8") as f: json.dump(self.page.context.cookies(), f, ensure_ascii=False, indent=2) except: passTechnical Analysis
The client serializes the complete Playwright browser cookie set to a plaintext JSON file. The default path is the relative filename
12306_cookies.json, and the file is created with permissions determined by the process umask rather than explicitly enforced owner-only permissions.Authentication cookies may function as bearer credentials. Any user or process able to read the cookie file may be able to reuse a still-valid authenticated session without knowing the account password. A relative, caller-controlled path also increases the likelihood that the file will be created in a shared directory, included in a backup, or accidentally committed to source control.
The bare exception handler suppresses all storage failures, preventing callers from detecting insecure or unsuccessful persistence.
Attack Path
- A victim starts the client and authenticates with the 12306 website.
login()invokessave_cookies(), which retrieves all cookies from the browser context.- The cookies are written unencrypted to
12306_cookies.jsonor another caller-supplied path. - An attacker with local read access, access to a shared workspace, backup, artifact archive, or mistakenly committed file obtains the JSON file.
- The attacker imports any still-valid authentication cookies into a compatible browser context.
- If the service accepts the copied session, the attacker impersonates the victim until the session expires or is revoked.
Exploitation requires access to the generated cookie file a ...[truncated 436 chars]
- Remediation
View remediation
Remediation Suggestions
- Prefer an operating-system credential store or encrypted secret-storage facility rather than a plaintext JSON file.
- If file persistence is unavoidable, store cookies in a private per-user application-data directory.
- Create the file atomically with owner-only permissions, such as mode
0600on POSIX systems. - Reject symbolic links and avoid writing through attacker-controlled paths.
- Document that the file contains authentication material and add it to
.gitignore. - Delete the cookie file during logout and when the session is invalid or expired.
- Minimize persisted data by retaining only cookies strictly required for session restoration.
- Replace the bare
exceptclause with specific exception handling and report failures securely without exposing cookie values.
