Back to skill

Security audit

Billing Monitor

Security checks for vulnerabilities and agentic risk

Overview

This billing monitor mostly fits its stated purpose, but it needs review because it can source executable local context, run scheduled credential-backed API checks, and change model configuration.

Review before installing. Use this only in an environment where you trust the local context file and scheduler configuration, and replace shell-sourced .context loading with a non-executable config format. Limit checks to explicitly approved provider keys, use dedicated monitoring credentials where possible, set log retention and permissions, and require clear user/admin control before automatic model switching or scheduled hourly checks.

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
SKILL.md:10
Finding
Arbitrary Shell Command Execution Through an Unvalidated Context File## Vulnerability Details **File Location**: `SKILL.md`, lines 10–12 **Vulnerability Type**: Unsafe shell sourcing of a mutable local configuration file **Risk Level**: High ### Vulnerable Code ```bash CONTEXT_FILE="/opt/ocana/openclaw/workspace/skills/billing-monitor/.context" [ -f "$CONTEXT_FILE" ] && source "$CONTEXT_FILE" # Then use: $OWNER_PHONE, $ADMIN_PHONE, $BILLING_LOG, $BILLING_FALLBACK_CONFIG, etc. ``` ### Technical Analysis The `source` shell builtin evaluates the entire contents of `.context` as shell code in the current process. It does not restrict the file to variable assignments. Consequently, the file can contain command substitutions, function definitions, redirections, external command invocations, environment modifications, or other arbitrary shell operations. The skill verifies only that the file exists. It does not validate: - File ownership or group ownership - File permissions - Symbolic-link status - File integrity - The syntax or allowed fields in the file - Whether values contain executable shell expressions This creates an arbitrary-command-execution primitive if an attacker or compromised local process can create, replace, or modify the fixed `.context` file. Commands run with the identity and permissions of the account executing the skill. ### Attack Path 1. An attacker obtains write access to the `.context` file, its containing directory, or a mechanism capable of replacing the file. 2. The attacker inserts shell commands into the file, for example a command that reads API-key environment variables or modifies OpenClaw configuration. 3. The billing-monitor skill is invoked during an API failure, health check, or other documented trigger. 4. The initialization instructions execute `source "$CONTEXT_FILE"`. 5. The attacker's statements execute within the agent's shell context and inherit its environment and permissions. 6. The attacker can access or alter resources availabl ...[truncated 998 chars]
Remediation
## Remediation Suggestions 1. Do not load configuration by using `source`, `.`, `eval`, or command substitution. 2. Store configuration in a non-executable format such as JSON. 3. Parse an explicit allowlist of expected fields with a safe parser. Reject unknown keys, invalid types, control characters, and malformed values. 4. Before reading the file, verify that it is a regular file rather than a symbolic link and that it is owned by the expected account. 5. Require restrictive permissions, such as mode `0600` for the file and a non-writable parent directory for untrusted users. 6. Where integrity guarantees are required, provision the file through a trusted deployment mechanism and verify its digest or signature before use. 7. Keep secrets in an operating-system credential store or dedicated secret manager rather than an executable context file. 8. Pass validated values to commands as quoted arguments and independently validate model identifiers, paths, phone numbers, and channel names before use. A safer JSON-loading pattern is: ```bash CONTEXT_FILE="/opt/ocana/openclaw/workspace/skills/billing-monitor/context.json" [ -f "$CONTEXT_FILE" ] || exit 1 [ ! -L "$CONTEXT_FILE" ] || exit 1 OWNER_PHONE="$( python3 -c 'import json, sys; print(json.load(open(sys.argv[1]))["owner_phone"])' \ "$CONTEXT_FILE" )" ``` The implementation should additionally perform ownership, permission, schema, and value validation before consuming any parsed field.
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Rogue AgentSelf-Modification, Session Persistence
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
Findings (7)

Session Persistence

Medium
Category
Rogue Agent
Content
```bash
LOG_DIR="$HOME/.openclaw/workspace/logs"
mkdir -p "$LOG_DIR"

# Append one line to the log file
echo "$(date -u +%Y-%m-%dT%H:%M:%SZ) BILLING_ERROR api_key_exhausted" \
Confidence
84% confidence
Finding
The skill writes incident records to a persistent log file in the user workspace. Persistent state is security-relevant because it can accumulate operational history, leak service status to other local processes or users, and create undeclared retention of potentially sensitive metadata about outages and billing failures.

Missing User Warnings

Medium
Confidence
95% confidence
Finding
The health-check script reads provider API keys from environment variables and transmits authenticated requests to external services without an explicit warning about credential use, outbound network activity, or minimization requirements. Even though the intent is operational monitoring, silent credential-backed egress materially increases risk in agent environments because users may not realize the skill is authorized to use secrets and contact third-party endpoints.

External Transmission

Medium
Category
Data Exfiltration
Content
# Detect provider from env vars (check in order)
if [ -n "${ANTHROPIC_API_KEY:-}" ]; then
  PROVIDER="Anthropic"
  HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
    -H "x-api-key: ${ANTHROPIC_API_KEY}" \
    -H "anthropic-version: 2023-06-01" \
    -H "content-type: application/json" \
Confidence
96% confidence
Finding
This code sends an authenticated request using the Anthropic API key to an external endpoint. While the request is functionally legitimate, it is still a security-relevant data transmission because the skill causes secret-backed outbound traffic and could incur cost, expose usage metadata, or normalize sending requests without explicit runtime approval.

External Transmission

Medium
Category
Data Exfiltration
Content
-H "anthropic-version: 2023-06-01" \
    -H "content-type: application/json" \
    -d "{\"model\":\"claude-haiku-20240307\",\"max_tokens\":1,\"messages\":[{\"role\":\"user\",\"content\":\"ping\"}]}" \
    https://api.anthropic.com/v1/messages 2>/dev/null)

elif [ -n "${OPENAI_API_KEY:-}" ]; then
  PROVIDER="OpenAI"
Confidence
93% confidence
Finding
The skill transmits data to the Anthropic API endpoint as part of its health check. Even minimal payloads still constitute external transmission tied to a production credential, which can create privacy, audit, and billing concerns if executed automatically or too broadly.

External Transmission

Medium
Category
Data Exfiltration
Content
-H "Authorization: Bearer ${OPENAI_API_KEY}" \
    -H "content-type: application/json" \
    -d "{\"model\":\"gpt-4o-mini\",\"max_tokens\":1,\"messages\":[{\"role\":\"user\",\"content\":\"ping\"}]}" \
    https://api.openai.com/v1/chat/completions 2>/dev/null)

elif [ -n "${GOOGLE_API_KEY:-}" ]; then
  PROVIDER="Google"
Confidence
94% confidence
Finding
The skill sends an authenticated request to OpenAI’s API endpoint using the configured API key. As with the other provider checks, this is a real outbound transmission that uses a secret and may reveal account activity or generate cost if run on a schedule without tight controls.

Description-Behavior Mismatch

Medium
Confidence
92% confidence
Finding
The cron example expands the skill from monitoring a billing error for the active provider into checking all configured API keys and updating billing-status.json, neither of which is defined in the manifest or main procedure. Scope expansion in automation is dangerous because it authorizes broader actions than advertised, which can lead to unauthorized monitoring, unexpected file writes, and overcollection of credential-related state.

Intent-Code Divergence

Medium
Confidence
94% confidence
Finding
The skill’s earlier guidance says routine healthy checks should be silent, but the cron payload instructs the agent to reply HEARTBEAT_OK when all is clear. This creates contradictory behavior that can cause unintended notifications or visible output in supposedly silent monitoring contexts, increasing noise and the chance of operational misuse.

Static analysis

No suspicious patterns detected.