Back to skill

Security audit

Token Stats Pkg

Security checks for vulnerabilities and agentic risk

Overview

This skill appears to be a disclosed local token-usage viewer with some normal installation and export caveats, not malware.

Install only if you are comfortable with a local CLI reading your AI assistant usage/history stores to compute token statistics. Avoid running npm or setup commands with elevated privileges, prefer trusted registries, and keep exported reports in a private location because they can reveal work patterns and session metadata.

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

T08 · Insecure Dependencies

Warning
Location
README.md:49
Finding

Unpinned Global npm Installer Creates a Supply-Chain Execution Risk

Content
View full analysis

Vulnerability Details

File Location: README.md:49 and README.md:61
Vulnerability Type: Unpinned third-party dependency installed globally from mutable registries
Risk Level: Medium

Relevant code snippets:

bash
# Install
npm install -g clawhub
bash
npm install -g clawhub --registry=https://registry.npmmirror.com

The same unpinned installation approach is repeated in the troubleshooting instructions at README.md:381-384 and mirrored in README.zh.md.

Technical Analysis

The documented installation procedure directs users to globally install the latest available release of the clawhub npm package without specifying an exact version or verifying an integrity digest. The optional use of https://registry.npmmirror.com introduces an additional package-distribution trust boundary.

npm packages can execute lifecycle scripts during installation. Consequently, the effective code executed by this command can change after the Skill has been reviewed, even when the audited project itself remains unchanged. A compromised maintainer account, malicious package update, registry compromise, or dependency-chain compromise could cause attacker-controlled code to execute during installation.

This finding concerns the installation documentation and supply-chain model. The audit did not establish that the current clawhub package or the mirror is malicious. The runtime implementation in token-stats.py does not itself download remote payloads, import networking libraries, or invoke subprocesses.

Attack Path

  1. An attacker compromises the clawhub npm package, one of its transitive dependencies, its publisher account, or a configured registry.
  2. The attacker publishes or serves a malicious package version containing an npm lifecycle script or modified executable.
  3. A user follows the project documentation and runs npm install -g clawhub without an exact version or integrity constr ...[truncated 1134 chars]
Remediation
View remediation

Remediation Suggestions

  1. Pin the installer to a reviewed exact version, for example:

    bash
    npm install -g clawhub@<reviewed-exact-version> --ignore-scripts
    

    Use --ignore-scripts only after confirming that the package does not legitimately require lifecycle scripts.

  2. Publish the expected package name, exact version, source repository, and integrity digest in the installation documentation.

  3. Prefer the official npm registry. If a mirror must be supported, clearly identify it as an additional trust boundary and provide a procedure for comparing package integrity against the official registry.

  4. Avoid global installation where practical. Use a project-local, version-locked dependency or distribute a verified standalone installer.

  5. Pin and audit transitive dependencies through an appropriate lockfile in the installer project.

  6. Update all duplicated installation and troubleshooting commands in README.md and README.zh.md so users are not directed back to the unpinned command.

  7. Warn users not to run npm installation with sudo or administrator privileges unless explicitly required and independently reviewed.

Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • Output HandlingUnvalidated Output Injection, Cross-Context Output, Unbounded Output
  • Tool MisuseTool Parameter Abuse, Chaining Abuse, Unsafe Defaults
  • Rogue AgentSelf-Modification, Session Persistence
Findings (17)

Tool Parameter Abuse

High
Category
Tool Misuse
Confidence
85% confidence
Finding

Tool parameters are crafted to achieve unintended or unsafe behavior. Parameter abuse can bypass intended safety checks (e.g. shell=True, --force, dangerous glob patterns).

Content

Scanner excerpt · README.md (reported line 341)May include surrounding context.

bash
clawhub uninstall agent-usage-stats
rm -f ~/.local/bin/token-stats

# Clean up old aliases (if you previously set alias token-stats=...)
grep "alias token-stats" ~/.zshrc ~/.bashrc 2>/dev/null || echo "No old aliases found"

Tool Parameter Abuse

High
Category
Tool Misuse
Confidence
85% confidence
Finding

Tool parameters are crafted to achieve unintended or unsafe behavior. Parameter abuse can bypass intended safety checks (e.g. shell=True, --force, dangerous glob patterns).

Content

Scanner excerpt · README.zh.md (reported line 385)May include surrounding context.

bash
clawhub uninstall agent-usage-stats
rm -f ~/.local/bin/token-stats

# Clean up old aliases (if you previously set alias token-stats=...)
grep "alias token-stats" ~/.zshrc ~/.bashrc 2>/dev/null || echo "No old aliases found"

Tp4

High
Category
MCP Tool Poisoning
Confidence
94% confidence
Finding

The declared purpose emphasizes simple interactive selection and token viewing, but the described detected behavior expands into direct backend selection, watch mode, broad local scanning, exporting data, and shell configuration inspection/setup. This mismatch is dangerous because users and calling agents may grant trust based on a narrow description while the skill performs more expansive local enumeration and persistence-related actions than expected.

Content

No source excerpt is available for this finding.

Unvalidated Output Injection

High
Category
Output Handling
Confidence
95% confidence
Finding

Model output is used without validation or sanitization. Unvalidated output injected into downstream contexts (SQL, shell, HTML) enables injection attacks and arbitrary code execution.

Content

Scanner excerpt · token-stats.py (reported line 430)May include surrounding context.

python
params.append(to_ts)
            clause = " AND ".join(where)

            cur = conn.execute(
                f"SELECT model, SUM(input_tokens) as inp, SUM(output_tokens) as out, "
                f"SUM(cache_read_tokens) as cache, SUM(api_call_count) as calls, "
                f"SUM(tool_call_count) as tools, COUNT(*) as cnt "

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
85% confidence
Finding

The README shows user-facing output strings in Chinese, which suggests the skill may present results in a fixed language. Under the language/locale policy, forcing a specific language without opt-in or explanation is a policy concern unless the tool is clearly documented as region-specific or offers a choice.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
88% confidence
Finding

Multiple output examples in the usage section are rendered in Chinese, reinforcing that the skill may default to a fixed language. The README does not tell users they can change the language or that the skill is intended only for a Chinese-speaking context.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
87% confidence
Finding

The compare-mode example uses Chinese labels for core interface text, which may indicate a mandatory output locale. Since there is no accompanying note about language configuration or regional scope, this appears to violate the policy against forcing a language without user opt-in.

Content

No source excerpt is available for this finding.

Session Persistence

Medium
Category
Rogue Agent
Confidence
60% confidence
Finding

Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.

Content

Scanner excerpt · README.md (reported line 309)May include surrounding context.

md
| Command | Description |
|---------|-------------|
| `clawhub install agent-usage-stats` | Install from ClawHub |
| `token-stats --setup` | Create global command at `~/.local/bin/token-stats` |

> 💡 All commands above are also available via `token-stats --help`.

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
83% confidence
Finding

The skill advertises local data access and a setup command, but it does not declare any explicit tool scope or permissions despite behavior consistent with file reads, shell usage, and likely local file modification during setup. Missing scope declarations increase the chance that an agent executes the skill with broader capabilities than users expect, which is risky for a package that inspects local agent data stores and may touch shell configuration.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The skill metadata and user-facing documentation are entirely written in Chinese, including the description and usage guidance, with no indication that other languages are supported or that language choice is optional. This creates a language/locale policy concern because it implicitly requires a specific language for use without user opt-in or documented justification.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
92% confidence
Finding

The module docstring and all user-facing CLI/help text are written in Chinese, and the script does not offer any language selection or opt-in. Under the policy for natural-language violations, forcing a specific language/locale without user choice is reportable across all file types.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The skill’s stated purpose is viewing token usage, but it also writes an executable launcher into ~/.local/bin and inspects shell rc files for aliases. That is a scope-expanding side effect affecting the user’s shell environment, which can surprise users and creates persistence beyond simple monitoring behavior.

Content

No source excerpt is available for this finding.

Context-Inappropriate Capability

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The setup path creates a persistent global command wrapper unrelated to merely reading token statistics. Even though it is gated behind --setup, this installation behavior changes the user environment and can be abused or misused if users do not expect a monitoring utility to establish persistent command hooks.

Content

No source excerpt is available for this finding.

Missing User Warnings

Low
Category
Not specified by scanner
Confidence
78% confidence
Finding

This markdown file describes an export feature that saves agent usage statistics to JSON or CSV files, but it does not explicitly warn users that exported data will be written to disk and may persist in a chosen directory. Because the skill handles usage data and creates files, a brief disclosure about local file creation and potential sensitivity of exported stats would improve user awareness.

Content

No source excerpt is available for this finding.

Missing User Warnings

Low
Category
Not specified by scanner
Confidence
90% confidence
Finding

This README explains the --export feature and shows users how to write usage statistics to chosen directories, but it does not warn that the exported JSON/CSV may contain sensitive local activity metadata such as model usage, session counts, or history-derived data. For markdown files, omissions of warnings about behaviors that could affect user data or privacy should be flagged.

Content

No source excerpt is available for this finding.

Missing User Warnings

Low
Category
Not specified by scanner
Confidence
81% confidence
Finding

The README includes sed and source commands that alter ~/.zshrc, which affects the user's shell environment, but there is no nearby warning to review the command before running it or back up the file. For markdown files, destructive or system-integrity-affecting behaviors should be disclosed to the user.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Low
Category
Not specified by scanner
Confidence
91% confidence
Finding

The stated purpose is to select an assistant and view token usage. The export flow writes JSON or CSV files to arbitrary user-provided directories, which goes beyond pure viewing/monitoring behavior described in the manifest.

Content

No source excerpt is available for this finding.