Back to skill

Security audit

Phemex Cli

Security checks for vulnerabilities and agentic risk

Overview

This skill is for legitimate Phemex trading, but it asks users to install a mutable global CLI and recommends persistent plaintext financial API credentials without enough safeguards.

Review before installing. Use a pinned, verified phemex-cli version if available, avoid global installs where possible, prefer environment variables or an OS secret store over ~/.phemexrc, restrict API keys to the minimum permissions needed, disable withdrawals, consider IP allowlisting, and use testnet or small limits until you trust the setup.

Vulnerability Patterns
  • Insecure DependenciesIntroduces malicious components through unsafe dependency sources
  • 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
Findings (2)

T08 · Insecure Dependencies

Error
Location
SKILL.md:43
Finding

Unpinned Global Installation of a Mutable Third-Party Package

Content
View full analysis

Vulnerability Details

File Location: SKILL.md, lines 43–48
Vulnerability Type: Unpinned third-party dependency installed globally
Risk Level: High

Vulnerable Code:

markdown
## Before you start

Ensure you have the latest version installed:

```bash
npm install -g phemex-cli@latest
text

### Technical Analysis

The Skill instructs users to install `phemex-cli` globally from npm using the mutable `@latest` distribution tag. The package version and integrity are therefore determined at installation time rather than review time. The repository contains no executable implementation of the CLI, lockfile, integrity hash, or vendored source that would allow the effective runtime code to be audited as part of this project.

npm packages may execute lifecycle scripts during installation and arbitrary code when invoked. Because installation is global, package executables are exposed through the user's global command path. The package subsequently receives access to the Phemex API key and secret required by the Skill. A malicious future release, compromised publisher account, or compromised package could consequently execute with the installing user's operating-system privileges and obtain financially sensitive credentials.

### Attack Path

1. An attacker compromises the npm package, its publisher account, or a release process and publishes a malicious version under the `latest` tag.
2. A user follows the documented command `npm install -g phemex-cli@latest`.
3. npm resolves the mutable tag to the attacker-controlled version.
4. Malicious code executes through an installation lifecycle script or when the globally installed `phemex-cli` command is invoked.
5. The package reads `PHEMEX_API_KEY`, `PHEMEX_API_SECRET`, or `~/.phemexrc`, or manipulates trading commands and responses.
6. The attacker may exfiltrate credentials, perform unauthorized API operations within the key's permissions, or execute other 
...[truncated 589 chars]
Remediation
View remediation

Remediation Suggestions

  • Replace @latest with an exact, reviewed package version; do not use a range or mutable distribution tag.
  • Verify and document the expected npm publisher, package provenance, source repository, and release signature or integrity digest.
  • Commit a lockfile with integrity metadata where the installation model permits it.
  • Prefer a project-local installation over a global installation to reduce command-path exposure and simplify version control.
  • Install with lifecycle scripts disabled when they are not required, and separately review any lifecycle scripts before enabling them.
  • Audit the resolved package and its transitive dependencies before each approved upgrade.
  • Run the CLI under a dedicated, least-privileged account or sandbox.
  • Use a Phemex API key restricted to only the necessary operations and ensure withdrawal permissions are disabled.

T09 · Insecure Skill Coding Practices

Warning
Location
SKILL.md:352
Finding

Plaintext Persistence of Financial API Credentials Without File-Permission Controls

Content
View full analysis

Vulnerability Details

File Location: SKILL.md, lines 352–366
Vulnerability Type: Insecure plaintext secret storage
Risk Level: Medium

Vulnerable Code:

markdown
## Setup

### Option 1: Config file (recommended)

Create `~/.phemexrc` — credentials persist across sessions without exporting env vars:

```bash
# ~/.phemexrc
PHEMEX_API_KEY=your-api-key
PHEMEX_API_SECRET=your-api-secret
PHEMEX_API_URL=https://api.phemex.com

# Optional: max order value limit (USD)
PHEMEX_MAX_ORDER_VALUE=1000
text

### Technical Analysis

The recommended setup stores the Phemex API key and secret persistently in a plaintext file in the user's home directory. The instructions do not require restrictive file permissions, verify file ownership, recommend an operating-system secret store, or warn users to exclude the file from backups and accidental publication.

A home-directory configuration file may be created with permissions influenced by the user's `umask` or by the editor and file-creation workflow. If it is readable by other local users or exposed through backups, synchronization tools, support archives, malware, or accidental repository inclusion, the API secret can be recovered directly. The statement that production credentials can be kept “safely” in the file may give users an unjustified assurance because confidentiality depends on controls not established by the instructions.

### Attack Path

1. A user follows the recommended setup and writes production credentials to `~/.phemexrc`.
2. The file is created with permissive access rights, copied into an insufficiently protected backup, synchronized to another system, or accidentally included in an archive.
3. Another local user, compromised process, backup operator, or other unauthorized party reads the plaintext file.
4. The attacker extracts `PHEMEX_API_KEY` and `PHEMEX_API_SECRET`.
5. The attacker authenticates to the Phemex API and performs any 
...[truncated 676 chars]
Remediation
View remediation

Remediation Suggestions

  • Prefer an operating-system credential manager or another dedicated secret store instead of a plaintext configuration file.
  • If a file is unavoidable, create it with restrictive permissions from the outset, for example with umask 077, and enforce mode 0600.
  • Verify that the file is owned by the intended user and reject execution when it is group-readable, world-readable, or owned by another account.
  • Warn users not to commit, synchronize, share, log, or include ~/.phemexrc in unencrypted backups.
  • Use separate testnet and production keys and apply least-privilege API scopes.
  • Disable withdrawal permissions and any other privileges not needed by the CLI.
  • Apply exchange-side IP allowlisting where available.
  • Rotate credentials immediately if the file may have been disclosed, and document a regular rotation process.
  • Treat PHEMEX_MAX_ORDER_VALUE as defense in depth only; enforce financial limits server-side or through a separately protected policy because an attacker who can alter the file may also alter this value.
Vulnerability Patterns
  • Rogue AgentSelf-Modification, Session Persistence
  • 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 (1)

Session Persistence

Medium
Category
Rogue Agent
Confidence
91% confidence
Finding

The skill recommends storing live exchange API credentials in a persistent plaintext file at ~/.phemexrc, which increases exposure to credential theft from local compromise, overly broad file permissions, backups, shell history, or other tools reading the home directory. In this skill's context, those credentials can authorize account access and trading actions, so compromise could lead to unauthorized trades, transfers, or account abuse.

Content

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

Option 1: Config file (recommended)

Create ~/.phemexrc — credentials persist across sessions without exporting env vars:

bash
# ~/.phemexrc

Static analysis

No suspicious patterns detected.