Back to skill

Security audit

12306 Train Query

Security checks for vulnerabilities and agentic risk

Overview

This train-ticket query skill is purpose-aligned, but its network script disables HTTPS certificate checks and follows unrestricted redirects, which makes its results and request data easier to tamper with.

Install only if you are comfortable with a simple 12306 query helper that makes live network requests, and treat its output as untrusted until the TLS bypass and redirect handling are fixed. It should not be used for purchasing tickets or handling real login/session credentials in its current form.

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
scripts/train_query.js:20
Finding

Disabled TLS Certificate Validation and Unrestricted Redirect Handling

Content
View full analysis
{ let data = ''; res.on('data', chunk => data += chunk); res.on('end', () => { const stations = {}; const regex = /@[^|]+\|([^|]+)\|([^|]+)\|/g; let match; while ((match = regex.exec(data)) !== null) { stations[match[1]] = match[2]; } resolve(stations); }); }).on('error', reject); ``` ```js const options = { headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36', 'Accept': 'application/json, text/plain, */*', 'Accept-Language': 'zh-CN,zh;q=0.9', 'Referer': 'https://www.12306.cn/mormhweb/', 'Cookie': 'JSESSIONID=test123; BIGipServerotn=123456' }, rejectUnauthorized: false }; function fetch(url, opts, callback) { const client = url.startsWith('https') ? https : http; client.get(url, opts, (res) => { if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) { const newUrl = new URL(res.headers.location, url).toString(); fetch(newUrl, opts, callback); } else { let data = ''; res.on('data', chunk => data += chunk); res.on('end', () => callback(data)); } }).on('error', e => { console.log('Fetch Error:', e.message); resolve([]); }); } ``` ### Technical Analysis The script explicitly sets `rejectUnauthorized: false` for both station-data retrieval and ticket queries. This disables standard TLS certificate-chain and hostname verification. Consequently, the script will accept expired, self-signed, incorrectly scoped, or attac ...[truncated 2928 chars]
Remediation
View remediation
{ // Process the response. }); ``` 2. Permit redirects only when the destination uses HTTPS and belongs to an explicit trusted-host allowlist, such as `kyfw.12306.cn`. 3. Reject HTTPS-to-HTTP redirects: ```js const nextUrl = new URL(res.headers.location, url); if (nextUrl.protocol !== 'https:') { return reject(new Error('Insecure redirect blocked')); } if (nextUrl.hostname !== 'kyfw.12306.cn') { return reject(new Error('Redirect to an untrusted host blocked')); } ``` 4. Do not forward cookies, authorization headers, referer values, or other origin-specific headers when the destination origin changes. 5. Remove the hard-coded `Cookie` header unless the endpoint demonstrably requires it. If authentication is later required, obtain session values securely and never embed valid credentials in source code. 6. Add a strict redirect limit, such as three redirects, to prevent redirect loops and recursion-based resource exhaustion. 7. Enforce maximum response sizes and request timeouts before buffering complete remote responses in memory. 8. Validate HTTP status codes and expected response content types before parsing data. 9. Treat remote station and ticket data as untrusted input and verify the expected schema before displaying it. ]]>
Vulnerability Patterns
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
Findings (8)

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

Scanner excerpt · SKILL.md (reported line 19)May include surrounding context.

md
node scripts/train_query.js [出发站] [到达站] [日期]

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

Scanner excerpt · SKILL.md (reported line 34)May include surrounding context.

md
node scripts/train_query.js [出发站] [到达站] [日期]

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

Scanner excerpt · SKILL.md (reported line 37)May include surrounding context.

md
node scripts/train_query.js [出发站] [到达站] [日期]

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
86% confidence
Finding

The skill invokes a network-capable script to query train ticket availability, but the manifest shown does not declare any explicit tool scope such as permissions or allowed-tools. Undeclared network capability weakens reviewability and enforcement, making it easier for a seemingly simple travel skill to perform unexpected outbound requests or expand behavior beyond what users and operators expect.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The trigger language is broad enough to match many general travel-related conversations, including ambiguous requests about buying tickets or train travel. Overbroad activation boundaries can cause the skill to run unexpectedly, exposing user travel queries to the skill and increasing the chance of unnecessary network access or unintended delegation.

Content

No source excerpt is available for this finding.

Context-Inappropriate Capability

Medium
Category
Not specified by scanner
Confidence
99% confidence
Finding

The script disables TLS certificate validation when fetching station data from 12306, which allows a man-in-the-middle attacker to impersonate the remote server and supply arbitrary responses. In this skill's context, that can tamper with train station mappings and downstream query behavior, and it is especially unjustified because a simple ticket-query skill should rely on authenticated HTTPS rather than bypassing it.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
90% confidence
Finding

The request header sets Accept-Language to zh-CN,zh;q=0.9, which forces a specific language/locale behavior. Under the policy, locale constraints should either be user-selectable or clearly justified as region-specific; this file does neither in its user-facing usage text.

Content

No source excerpt is available for this finding.

Context-Inappropriate Capability

Low
Category
Not specified by scanner
Confidence
91% confidence
Finding

The custom fetcher automatically follows redirects to any HTTP or HTTPS location without restricting the destination host, so a compromised upstream or MITM could bounce the script to an attacker-controlled endpoint. Combined with disabled TLS verification in the request options, this broadens the trust boundary and can cause the skill to consume malicious content outside its stated 12306-only purpose.

Content

No source excerpt is available for this finding.