T09 · Insecure Skill Coding Practices
- Location
scripts/download.js:383- Finding
Remote Code Execution Through Unsafe Evaluation of Network-Supplied JavaScript
- Content
View full analysis
Vulnerability Details
File Location:
scripts/download.js, lines 383–388 and 674–684
Vulnerability Type: Unsafe execution of untrusted remote JavaScript in a Node.js VM context
Risk Level: CriticalVulnerable Code
js function computeAcw(body, cookieJar) { const scriptMatch = body.match(/<script>([\s\S]*?)<\/script>/); if (!scriptMatch || !body.includes('arg1=')) return cookieJar; const fakeDoc = { cookie: '', location: { reload: () => {} } }; const ctx = vm.createContext({ document: fakeDoc, Date, console: { log: () => {}, error: () => {}, warn: () => {} } }); try { vm.runInContext(scriptMatch[1], ctx, { timeout: 5000 }); } catch (e) {} if (fakeDoc.cookie) {The main download path repeats the same unsafe operation:
js const scriptMatch = body.match(/<script>([\s\S]*?)<\/script>/); if (!scriptMatch) throw new Error('无法提取 JS 脚本'); const fakeDoc = { cookie: '', location: { reload: () => {} } }; const ctx = vm.createContext({ document: fakeDoc, Date: Date, console: { log: () => {}, error: () => {}, warn: () => {} }, }); vm.runInContext(scriptMatch[1], ctx, { timeout: 5000 });Technical Analysis
The downloader retrieves HTML from a remote endpoint, extracts the first script block when the response contains
arg1=, and executes that script usingvm.runInContext.The evaluated script is network-controlled code rather than locally trusted code. Node.js VM contexts are not designed to be a security boundary for hostile input. More importantly, the context explicitly exposes the host-realm
Dateconstructor. A hostile script may traverse the exposed constructor chain to obtain the hostFunctionconstructor and then recover Node.js objects such asprocess. A representative escape primitive is conceptually:js const processObject = Date.constructor.constructor('return process')();Once
processis obtained, the script can access environment variables, load Node.js modules through reachabl ...[truncated 2637 chars]- Remediation
View remediation
Remediation Suggestions
-
Remove remote JavaScript evaluation entirely. Implement the
acw_sc__v2calculation as a fixed local algorithm operating only on narrowly validated challenge values. Do not execute script text extracted from a response. -
Enforce the documented network boundary in code.
- Require HTTPS for share, API, iframe, redirect, and download URLs.
- Validate every destination and every redirect against an explicit hostname allowlist.
- Normalize hostnames before comparison and use exact names or dot-boundary suffix checks.
- Reject credentials in URLs, unexpected ports, non-HTTP protocols, and redirects outside the permitted domain set.
-
Do not treat
node:vmas a hostile-code sandbox. RemovingDateand other explicit host objects would reduce this particular escape route but would not make arbitrary remote-code evaluation safe. -
If script execution is operationally unavoidable, isolate it outside the downloader process. Use a disposable, least-privileged container or worker with:
- No host filesystem mounts.
- No inherited environment variables or credentials.
- No child-process capability.
- No outbound network access.
- Strict CPU, memory, and execution-time limits.
- A minimal structured input and output protocol.
-
Add regression tests using hostile challenge pages to verify that response scripts are never evaluated and that cross-origin, plain-HTTP, and non-allowlisted redirects are rejected before response content is processed.
-
