Back to skill

Security audit

Pwsh Encoding Fix

Security checks for vulnerabilities and agentic risk

Overview

The skill matches its stated file-repair purpose, but its helper script can run unintended operating-system commands if given a specially crafted JavaScript filename.

Use this skill only on files and filenames you trust until the helper script is changed to use an argument-based process API such as execFileSync or spawnSync with shell disabled. Before running --fix, make your own backup of important files even though the script attempts to create a .bak copy.

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

Error
Location
pwsh-encoding-fix.js:121
Finding

OS Command Injection via Crafted JavaScript File Path

Content
View full analysis

Vulnerability Details

File Location: pwsh-encoding-fix.js, lines 121–123
Vulnerability Type: OS command injection
Risk Level: High

Vulnerable Code

js
if (filePath.endsWith('.js')) {
  execSync('node --check "' + absPath + '"', { stdio: 'pipe' });
}

Technical Analysis

The script obtains filePath from a command-line argument and derives absPath using path.resolve(). It then concatenates that attacker-influenced path into a command string passed to execSync().

By default, execSync() executes the string through a system shell. Wrapping absPath in double quotes does not safely escape embedded quotation marks or shell metacharacters. A specially crafted filename can terminate the quoted path and append an additional command. The requirement that the input end in .js does not prevent such a payload because the filename can retain that suffix after the injected shell expression.

Path resolution canonicalizes the path but does not provide shell escaping or argument separation.

Attack Path

  1. An attacker creates or supplies a JavaScript file whose filename contains shell syntax appropriate for the target operating system, including an embedded double quote that escapes the intended quoted argument.

  2. The attacker persuades a user or agent to diagnose that file:

    text
    node pwsh-encoding-fix.js <crafted-filename>
    
  3. main() passes the filename to diagnose().

  4. diagnose() resolves the filename to absPath and confirms that the original argument ends in .js.

  5. The script constructs a shell command by concatenating absPath into node --check "...".

  6. execSync() invokes the system shell, which interprets the injected quotation mark and metacharacters.

  7. The attacker's appended command executes with the privileges of the user running the skill.

Successful exploitation requires the crafted filename to be valid on the host filesystem and its shell syntax to match the operating syst ...[truncated 741 chars]

Remediation
View remediation

Remediation Suggestions

Remove shell interpretation and pass the executable and its arguments separately. Use the current Node.js executable rather than relying on shell command lookup:

js
const { execFileSync } = require('child_process');

if (filePath.endsWith('.js')) {
  execFileSync(process.execPath, ['--check', absPath], {
    stdio: 'pipe',
    shell: false
  });
}

Additional hardening measures:

  1. Do not attempt to solve the issue solely through manual shell escaping; argument-based process APIs are safer and portable.
  2. Consider validating that the target is a regular file with fs.statSync(absPath).isFile() before invoking Node.js.
  3. If only expected file types should be processed, validate the extension using the resolved path and a strict allowlist.
  4. Add regression tests containing spaces, quotation marks, ampersands, semicolons, command-substitution characters, and platform-specific shell metacharacters in filenames.
  5. Preserve the existing captured-output behavior, but sanitize exception text before exposing it in contexts where terminal escape sequences or untrusted logs may be relevant.
Vulnerability Patterns
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (4)

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

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

md
| `SKILL.md` | 本文档 |

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The documentation advertises a --fix mode that automatically repairs files, but it does not explicitly warn that the operation will overwrite the target file and may not be reversible. In a file-repair context, users may run the command on the only copy of a corrupted source file, causing further loss of data or destruction of forensic evidence if the repair guess is wrong.

Content

No source excerpt is available for this finding.

Context-Inappropriate Capability

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The script builds a shell command string and executes it with execSync: node --check "<path>". Although the path is quoted, this still grants shell execution capability to a tool whose primary purpose is file inspection/repair, and on Windows shell parsing edge cases can make string-based command construction risky if filenames contain special characters. In skill context, this is somewhat less suspicious because it is used for syntax validation, but it still expands the attack surface beyond necessary file processing.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
90% confidence
Finding

SQP-3 applies to all file types and includes language or locale policy violations. The document presents all operational instructions in Chinese and does not indicate that the user can choose another language or that the skill is intentionally restricted to Chinese-speaking users for a documented regional reason.

Content

No source excerpt is available for this finding.