Back to skill

Security audit

12306 Conflict

Security checks for vulnerabilities and agentic risk

Overview

This 12306 automation skill is not malicious, but it should be reviewed because it handles credentials and stores login cookies in a predictable plaintext file without clear disclosure.

Review this skill carefully before installing. Use a dedicated or low-risk 12306 account if possible, do not commit credentials or cookie files, delete 12306_cookies.json after use, and install only if you accept local plaintext session-cookie storage and the gap between the purchase-automation claim and the actual login/query implementation.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (1)

T09 · Insecure Skill Coding Practices

Warning
Location
12306_client.py:48
Finding

Browser Session Cookies Stored in a Predictable Plaintext File

Content
View full analysis

Vulnerability Details

File Location: 12306_client.py, lines 48–51
Vulnerability Type: Plaintext storage of sensitive session data
Risk Level: Medium

Vulnerable 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:
        pass

Technical Analysis

The application serializes all cookies from the Playwright browser context into a predictable file named 12306_cookies.json by default. The file is stored without encryption, access-control validation, or explicit owner-only permissions.

Browser cookies may include authenticated session tokens. Although the operating system's default permissions depend on the process umask, the implementation does not ensure that only the account running the application can read the resulting file. The predictable working-directory location also increases the likelihood that the file will be included in backups, shared workspaces, archives, or source-control commits.

The broad exception handler suppresses write failures and prevents users from recognizing that cookie persistence has not been secured or completed correctly.

Attack Path

  1. A user runs the client and establishes an authenticated 12306 browser session.
  2. login() invokes save_cookies(), which writes the browser-context cookies to 12306_cookies.json.
  3. A local process, another user with access to the directory, a backup system, or a recipient of an accidentally committed/archive copy obtains the file.
  4. The exposed authentication cookies are imported into another compatible browser context.
  5. If the cookies remain valid and the service does not reject the replay, the attacker can impersonate the affected session.

This path requires access to the generated cookie file; the audited code does not itself transmit the cookies to an external party.

Impact Assessment

Su ...[truncated 543 chars]

Remediation
View remediation

Remediation Suggestions

  1. Avoid persistent session storage unless it is essential to the workflow.
  2. Store authentication state in an operating-system credential store or another encrypted secret-storage facility.
  3. If file persistence is unavoidable:
    • Use an absolute path inside a user-private application-data directory.
    • Create the file atomically with owner-only permissions such as 0600.
    • Verify existing file ownership and permissions before reading or overwriting it.
    • Apply a restrictive process umask.
  4. Save only the minimum cookies required rather than every cookie in the browser context.
  5. Add 12306_cookies.json and equivalent authentication-state files to .gitignore and packaging exclusions.
  6. Delete the cookie file during logout and document how users can revoke exposed sessions.
  7. Replace the bare except block with specific exception handling and report failures without logging cookie values.
  8. Add tests that verify restrictive permissions and ensure sensitive cookie data is never printed or committed.
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (6)

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
87% confidence
Finding

The client accesses sensitive environment variables for the 12306 username and password. The file does not include any user-facing warning, logging, or explanatory comment that credentials may be sourced from the environment, which is a safety-relevant behavior under the rule.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
92% confidence
Finding

The code persists browser cookies, which may include authenticated session tokens, to a local JSON file without warning, access controls, or encryption. If another local user, malware, or a backup/sync process accesses that file, the session could be reused to hijack the user's authenticated 12306 account context.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
87% confidence
Finding

The documentation references required environment variables for a login-related skill but provides no warning about handling credentials, secret storage, logging risks, or least-privilege use. For an authentication-related tool, this omission can lead users to place sensitive values in insecure files or expose them during execution, increasing the chance of credential leakage or misuse.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Low
Category
Not specified by scanner
Confidence
95% confidence
Finding

The top-level docstring and class docstring say this is a "12306 购票自动化客户端" (ticket-purchase automation client), which implies booking/purchasing capability. In the code, the implemented operations are browser startup, cookie persistence, login, and querying tickets; there is no code that selects a train, submits an order, or completes a purchase.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
93% confidence
Finding

The script emits a success message only in Chinese ("登录成功"). This imposes a specific language in user-facing behavior without any visible language choice, opt-in, or documented region-specific justification in the file.

Content

No source excerpt is available for this finding.

Missing User Warnings

Low
Category
Not specified by scanner
Confidence
89% confidence
Finding

On L08, the test reads RAILWAY_12306_USERNAME and RAILWAY_12306_PASSWORD, which are sensitive credentials. The file provides no docstring, comment, or other disclosure explaining that users must supply real login credentials for an external service, so the credential access lacks visible warning in this code file.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.