Back to skill

Security audit

GMNCODE Usage

Security checks for vulnerabilities and agentic risk

Overview

The skill appears purpose-built for GMNCODE usage reporting, but it handles account credentials and persists bearer tokens in a way users should review first.

Install only if you are comfortable giving the skill your GMNCODE login credentials and letting it cache a bearer token locally. Prefer environment variables over a saved password file, restrict file permissions, avoid shared machines, and clear the token cache when finished or until the cache write logic is hardened.

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

Warning
Location
scripts/gmncode_usage.py:56
Finding

Bearer Token Cache Is Not Created with Atomic Restrictive Permissions

Content
View full analysis

Vulnerability Details

File Location: scripts/gmncode_usage.py:56-72
Related Token Storage Logic: scripts/gmncode_usage.py:127-132
Vulnerability Type: Insecure sensitive-file creation and silent permission failure
Risk Level: Medium

Vulnerable Code

python
def ensure_file_mode(path: pathlib.Path, mode: int) -> None:
    try:
        path.chmod(mode)
    except OSError:
        pass


def secure_write_json(path: pathlib.Path, payload: dict[str, Any]) -> None:
    path.parent.mkdir(parents=True, exist_ok=True)
    path.write_text(json.dumps(payload, ensure_ascii=False), encoding="utf-8")
    ensure_file_mode(path, stat.S_IRUSR | stat.S_IWUSR)

The affected function stores the access token through the following call:

python
def _save_cached_token(self, access_token: str, expires_in: int) -> None:
    expires_at = int(dt.datetime.now(dt.timezone.utc).timestamp()) + int(expires_in)
    secure_write_json(TOKEN_CACHE, {
        "access_token": access_token,
        "expires_at": expires_at,
        "base_url": self.base_url,
    })

Technical Analysis

The cache file is created or truncated by Path.write_text() before mode 0600 is applied. Its initial permissions therefore depend on the process umask. With a common umask of 022, a newly created file may initially have mode 0644, creating a time-of-check/time-of-use exposure window in which another local user can read the bearer token.

The implementation also suppresses every OSError raised by chmod(). If permission hardening fails because of filesystem behavior, ownership, access-control rules, or another operating-system error, execution continues while the sensitive file may remain readable by unintended users.

Additionally, Path.write_text() follows symbolic links. The fixed cache location reduces practical exploitability, but an attacker who can manipulate the cache path or its parent directories could potentially redirect the token write. The code do ...[truncated 1626 chars]

Remediation
View remediation

Remediation Suggestions

  1. Create the cache directory with mode 0700 and verify that it is owned by the current user.
  2. Create the token file with mode 0600 at creation time rather than applying permissions after writing.
  3. Use os.open() with restrictive and defensive flags where supported:
python
flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC
if hasattr(os, "O_NOFOLLOW"):
    flags |= os.O_NOFOLLOW

fd = os.open(path, flags, 0o600)
try:
    with os.fdopen(fd, "w", encoding="utf-8") as handle:
        json.dump(payload, handle, ensure_ascii=False)
        handle.flush()
        os.fsync(handle.fileno())
except Exception:
    try:
        path.unlink()
    except OSError:
        pass
    raise
  1. Prefer writing to a securely created mode-0600 temporary file in the same directory and then replacing the destination atomically with os.replace().
  2. Reject symbolic links and validate that both the cache directory and destination are regular files owned by the current user.
  3. Do not suppress permission-setting failures. Abort token caching, remove any insecurely created file, and report a clear error.
  4. Consider continuing without persistent caching when secure storage cannot be guaranteed.
  5. Add tests using permissive umasks and simulated chmod() failures to verify that the token is never observable with group or world permissions.
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (17)

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

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

md
2. 优先运行 `scripts/gmncode_usage.py`,不要每次都重新手写登录、token 缓存和重试逻辑。

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

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

md
2. 优先运行 `scripts/gmncode_usage.py`,不要每次都重新手写登录、token 缓存和重试逻辑。

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

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

md
2. 优先运行 `scripts/gmncode_usage.py`,不要每次都重新手写登录、token 缓存和重试逻辑。

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

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

md
2. 优先运行 `scripts/gmncode_usage.py`,不要每次都重新手写登录、token 缓存和重试逻辑。

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

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

md
2. 优先运行 `scripts/gmncode_usage.py`,不要每次都重新手写登录、token 缓存和重试逻辑。

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

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

md
2. 优先运行 `scripts/gmncode_usage.py`,不要每次都重新手写登录、token 缓存和重试逻辑。

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

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

md
2. 优先运行 `scripts/gmncode_usage.py`,不要每次都重新手写登录、token 缓存和重试逻辑。

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

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

md
2. 优先运行 `scripts/gmncode_usage.py`,不要每次都重新手写登录、token 缓存和重试逻辑。

Ae1

High
Category
analysis-evasion
Confidence
100% confidence
Finding

Referenced artifact was not completely inspected

Content

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

md
2. 优先运行 `scripts/gmncode_usage.py`,不要每次都重新手写登录、token 缓存和重试逻辑。

Credential Access

High
Category
Privilege Escalation
Confidence
70% confidence
Finding

Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Content

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

md
脚本已经处理好了:
- 通过 `/api/v1/auth/login` 登录
- access token 本地缓存
- 遇到 `401` / `INVALID_TOKEN` 时自动重新登录并重试一次
- dashboard 所需的 referer / headers

Credential Access

High
Category
Privilege Escalation
Confidence
88% confidence
Finding

The documentation instructs users to store account email and password in a local .env file, which creates a plaintext-at-rest credential storage pattern. Even with restrictive file permissions, plaintext credentials can be exposed through backups, endpoint compromise, shell tooling, or accidental disclosure, and the skill context makes this meaningful because these credentials grant access to usage and billing-related account data.

Content

Scanner excerpt · references/api.md (reported line 15)May include surrounding context.

建议权限:

bash
chmod 600 ~/.openclaw/.env

脚本读取顺序:

Credential Access

High
Category
Privilege Escalation
Confidence
60% confidence
Finding

Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Content

Scanner excerpt · scripts/gmncode_usage.py (reported line 6)May include surrounding context.

python
Secure credential loading order:
1. Environment variables: GMNCODE_EMAIL / GMNCODE_PASSWORD
2. ~/.openclaw/.env entries with the same names

Base URL is hardcoded to https://gmncode.cn because it is not sensitive.

Credential Access

High
Category
Privilege Escalation
Confidence
60% confidence
Finding

Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Content

Scanner excerpt · scripts/gmncode_usage.py (reported line 42)May include surrounding context.

python
TIMEZONE = "Asia/Shanghai"
DEFAULT_BASE_URL = "https://gmncode.cn"
ENV_FILE = pathlib.Path.home() / ".openclaw" / ".env"
CACHE_DIR = pathlib.Path.home() / ".cache" / "openclaw" / "gmncode-usage"
TOKEN_CACHE = CACHE_DIR / "token.json"

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
88% confidence
Finding

The skill explicitly instructs use of environment variables, local .env files, shell commands, file access, and outbound HTTP requests, but it declares no tool restrictions or permission scope. This increases the blast radius: an agent invoking the skill may gain broader-than-necessary access to credentials, local files, and the network without an explicit least-privilege boundary.

Content

No source excerpt is available for this finding.

Sudo/Root Execution

Medium
Category
Privilege Escalation
Confidence
80% confidence
Finding

Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.

Content

Scanner excerpt · references/api.md (reported line 15)May include surrounding context.

建议权限:

bash
chmod 600 ~/.openclaw/.env

脚本读取顺序:

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

This script hardcodes a Shanghai timezone and later sends an explicit Chinese Accept-Language header while also emitting Chinese-language console output. That creates a natural-language/locale policy issue because the skill imposes a specific locale on all users with no opt-in, fallback, or documented region-specific justification.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
90% confidence
Finding

The API examples hard-code timezone=Asia/Shanghai in multiple endpoint definitions, which constitutes a locale-specific behavior in natural-language documentation. The file does not indicate that this timezone is optional, user-selectable, or justified as a region-specific requirement.

Content

No source excerpt is available for this finding.