Back to skill

Security audit

Codex CLI Guardian

Security checks for vulnerabilities and agentic risk

Overview

This is a real Codex launcher, but it handles API keys and task text unsafely enough that installing it should be reviewed first.

Review this before installing. It asks for a Codex/OpenAI API key, stores it locally, runs Codex tasks in the background, and currently has shell-script flaws that can turn crafted task text or a modified credential file into command execution. Remove bundled task history, avoid plaintext skill-local secrets, and fix the shell parsing before trusting it on a real machine.

Vulnerability Patterns
  • Unauthorized Access and Privilege EscalationObtains permissions beyond the task's legitimate needs
  • 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 (6)

T09 · Insecure Skill Coding Practices

Error
Location
bin/codex-call.sh:22
Finding

Credential File Is Executed as Shell Code

Content
View full analysis
/dev/null echo "${OPENAI_API_KEY_0011AI:-}" | tr -d '\r' else echo "" fi } ``` ```bash cat > "$CRED_FILE" <
Remediation
View remediation

T09 · Insecure Skill Coding Practices

Error
Location
bin/codex-call.sh:97
Finding

Task and Credential Values Are Reparsed by bash -c

Content
View full analysis
/dev/null 2>&1 || EXIT_CODE=$? ``` ### Technical Analysis The script correctly passes the original task to Python as an argument, but then embeds the output of `shlex.quote` inside an additional double-quoted command argument. It subsequently reparses the complete string with `bash -c`. `shlex.quote` is safe when its output is inserted directly into an otherwise correctly constructed shell command. Wrapping that output inside another quoting context changes its interpretation. In particular, the quote sequence generated for task text containing an apostrophe includes double-quote characters. Those characters can interact with the manually inserted double quotes when `bash -c` parses the reconstructed command. The API-key value is also interpolated into the generated command before it is reparsed. A quote or shell metacharacter in a credential value can therefore affect command parsing as well. ### Attack Path 1. An attacker supplies a crafted task containing an apostrophe followed by shell quote-boundary and command-control syntax, or controls a specially formed credential value. 2. Python produces a shell-quoted representation of the task. 3. The script embeds that representation inside another pair of double quotes in `CODEX_CMD`. 4. `bash -c` reparses the resulting string rather than preserving the task as one opaque argument. 5. Crafted syntax can escape the intended argument context and execute a command before or instead of Codex. ### Impact Assessment ...[truncated 358 chars]
Remediation
View remediation
/dev/null 2>&1 || EXIT_CODE=$? ``` Additional hardening should include: - Treat all task descriptions and credential values as opaque strings. - Do not use `eval`, `bash -c`, or dynamically assembled command strings. - Retain the `--` option terminator before user-controlled positional data. - Add regression tests with apostrophes, double quotes, command substitutions, semicolons, newlines, backticks, backslashes, and leading hyphens. - Use a shell static-analysis tool such as ShellCheck in continuous integration. ]]>

T05 · Unauthorized Access and Privilege Escalation

Warning
Location
bin/session.sh:141
Finding

Untrusted PID File Can Cause Termination of Unrelated Processes

Content
View full analysis
/dev/null) if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then kill "$pid" 2>/dev/null && echo "✅ 已发送 SIGTERM 终止任务 (PID: $pid)" || echo "❌ 终止失败" else echo "ℹ️ 没有运行中的任务" fi else echo "ℹ️ 没有运行中的任务" fi rm -f "$lock_file" "$STATE_DIR/current-task.json" ;; ``` The launcher uses the same weak identity check: ```bash check_lock() { if [[ -f "$LOCK_FILE" ]]; then local pid pid=$(cat "$LOCK_FILE" 2>/dev/null) if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then echo "⚠️ Codex 忙碌中,请稍后再试" exit 1 else rm -f "$LOCK_FILE" fi fi } ``` ### Technical Analysis The PID file is treated as authoritative proof that a process belongs to the current Codex task. The only validation is `kill -0`, which establishes that a process can be signaled but does not establish its identity. PIDs are reused by the operating system. If the original task exits without the lock being removed, the stored PID can later belong to an unrelated process. A writable or replaceable lock file also permits direct PID substitution. The value is not restricted to a positive decimal PID, and the `kill` invocation does not use an option terminator. Special negative PID values can have process-group or broader signaling semantics depending on the shell and platform. ### Attack Path 1. A stale lock remains after a task exits and its PID is reused, or an attacker changes `state/codex.lock`. 2. The lock contains the PID of another process belonging to the same user, or a specially formed negative ...[truncated 666 chars]
Remediation
View remediation

T09 · Insecure Skill Coding Practices

Warning
Location
bin/codex-call.sh:79
Finding

Predictable Shared Temporary Files Permit Collision and Symlink Attacks

Content
View full analysis
/dev/null || true # 去除 \r(防止 CRLF) key="${key//$'\r'}" # 实际调用 codex 验证 env "${ENV_VAR_NAME}=${key}" codex --full-auto exec -o /tmp/setup-verify.txt "echo ok" >/dev/null 2>&1 return $? } ``` ### Technical Analysis The Skill writes output to predictable names under the shared `/tmp` directory. `/tmp/setup-verify.txt` is constant, while task summary names are predictable from date-based task identifiers. The code does not create these files exclusively, verify their ownership or type, reject symbolic links, or place them in a private temporary directory. On a multi-user host, another local user can pre-create a path or symbolic link before the Skill runs. Actual overwrite behavior depends on how Codex opens its output file, but the Skill provides no protection against path collisions or link traversal. An attacker-controlled pre-existing file can also interfere with whether output is considered present and what data is later read as the summary. ### Attack Path 1. An attacker predicts the next task identifier or targets the fixed `/tmp/setup-verify.txt` path. 2. The attacker pre-creates the path, potentially as a symbolic link to another file writable by the victim. 3. The Skill invokes Codex with the attacker-prepared path as its output destination. 4. Codex may overwrite the linked target, fail in an attacker-controlled way, or write data into a file observable by the attacker. 5. For task summaries, the launcher subsequently read ...[truncated 429 chars]
Remediation
View remediation

T09 · Insecure Skill Coding Practices

Warning
Location
bin/codex-call.sh:84
Finding

Task Data Is Written to JSON Without Proper Serialization

Content
View full analysis
"$STATE_DIR/current-task.json" < "$TASKS_DIR/task-${TASK_ID}.json" < str: return \"Hello, World!\" ``` 如果你想,我也可以顺手加一行调用示例。", "started_at": "2026-04-04T14:26:45+08:00", "finished_at": "2026-04-04T14:27:05+08:00" } ``` ### Technical Analysis Untrusted task text is inserted directly into JSON string literals. Double quotes, backslashes, carriage returns, tabs, and other control characters are not JSON-encoded. Summary handling replaces only double quotes and removes newlines; this is not a complete JSON serializer. The bundled malformed record confirms that ordinary task text containing quoted identifiers already corrupts the generated JSON. More carefully crafted input could terminate the intended string and inject additional fields or values. Status and history functions later use Pytho ...[truncated 1089 chars]
Remediation
View remediation

other

Warning
Location
state/tasks/task-20260404-010.json:3
Finding

Distributed Task History Exposes Personal Information and Local Host Metadata

Content
View full analysis
Remediation
View remediation
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • Tool MisuseTool Parameter Abuse, Chaining Abuse, Unsafe Defaults
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
Findings (68)

Natural-Language Policy Violations

High
Category
Not specified by scanner
Confidence
97% confidence
Finding

The file is written as a Chinese-only reference and presents itself as the correct usage guide without offering a language choice or documenting a justified locale restriction. This can violate language/locale policy when users are not given an opt-in or alternative.

Content

No source excerpt is available for this finding.

External Model or Provider Selection

High
Category
Excessive Agency
Confidence
90% confidence
Finding

Skill selects an external model or provider that may use a different account or billing plan than the operator expects. Undisclosed model switches can cause unexpected cost or quota consumption.

Content

Scanner excerpt · CLI.md (reported line 28)May include surrounding context.

Codex 默认要求在 git 目录下运行。可用 --skip-git-repo-check 跳过。

bash
codex exec --skip-git-repo-check "..."

Credential Access

High
Category
Privilege Escalation
Confidence
93% confidence
Finding

The example explicitly instructs users to place a Codex API key into a local credentials.env file, indicating collection and local storage of credentials. In context, this is sensitive because examples also show the key being validated and echoed, making the credential-handling pattern more dangerous and more likely to result in exposure or insecure file permissions.

Content

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

text
🔑 OPENAI_API_KEY_0011AI 设置向导

🔍 credentials.env 不存在,开始设置...

=== STEP 3: 获取 Key ===
请输入你的 Codex API Key:

Missing User Warnings

High
Category
Not specified by scanner
Confidence
98% confidence
Finding

The setup example shows a user entering an API key, displays the key back in output, and states that it is saved to a credentials file, without any privacy or handling warning. This normalizes unsafe secret handling and could lead users or implementers to expose credentials in chat transcripts, logs, screenshots, or insecure local storage.

Content

No source excerpt is available for this finding.

Credential Access

High
Category
Privilege Escalation
Confidence
96% confidence
Finding

The example confirms that the API key has been saved and reveals the storage path, reinforcing a credential collection/storage workflow in a predictable file location. Predictable plaintext storage locations increase the blast radius of accidental disclosure, local compromise, backup leakage, or mistaken commits.

Content

Scanner excerpt · EXAMPLES.md (reported line 28)May include surrounding context.

✅ Key 验证通过!

✅ API Key 已保存: sk-o...e39KmsCk 文件位置: skills/codex-cli-guardian/credentials.env

设置完成!现在可以调用 Codex 执行任务了。

text

Credential Access

High
Category
Privilege Escalation
Confidence
93% confidence
Finding

The reference design explicitly stores an API key in a skill-local file named credentials.env, which creates a durable secret on disk inside the project structure. Even with mode 600, this increases the chance of accidental inclusion in backups, archives, logs, or repository operations, and centralizes a high-value credential in a predictable location.

Content

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

md
│   ├── codex-call.sh        # 主调用脚本(后台 + PTY)
│   └── session.sh            # 状态管理 / kill
├── scripts/
│   └── init-setup.sh         # API Key 验证 + 写入 credentials.env
├── state/
│   ├── current-task.json     # 运行中任务
│   ├── tasks/               # 任务历史

Credential Access

High
Category
Privilege Escalation
Confidence
96% confidence
Finding

The document prescribes storing OPENAI_API_KEY_0011AI in credentials.env within the skill directory. This is dangerous because a plaintext file secret can be copied, committed, exfiltrated by other local tools, or read by any process running as the same user, and the skill context specifically revolves around managing privileged API access.

Content

Scanner excerpt · REFERENCES.md (reported line 40)May include surrounding context.

md
## 2. API Key 管理

**存储文件**:`credentials.env`(skill 目录内)
**格式**:`OPENAI_API_KEY_0011AI=<key>`
**权限**:600

Credential Access

High
Category
Privilege Escalation
Confidence
95% confidence
Finding

The workflow says a validated API key should be written to credentials.env after test execution, formalizing secret persistence as part of setup. This turns a transient credential into a standing local secret and may cause long-lived exposure if the file is later reused, copied, or inspected by other automation.

Content

Scanner excerpt · REFERENCES.md (reported line 48)May include surrounding context.

md
1. 检测已有 key → 询问是否重设
2. 获取 Key(环境变量优先,否则要求用户输入)
3. **验证 Key**:实际调用 `codex --full-auto exec "echo ok"`
4. 验证成功 → 写入 `credentials.env`(权限 600);验证失败 → 回到 STEP 2

**运行时**:codex-call.sh 从 skill 目录内的 `credentials.env` 读取 Key

Credential Access

High
Category
Privilege Escalation
Confidence
97% confidence
Finding

The runtime behavior explicitly reads the API key from a predictable credentials.env file in the skill directory, confirming operational dependency on local plaintext secret storage. In this context, the skill is a session guardian that automates Codex execution, so compromise of that file directly enables unauthorized API use and possible downstream task execution under the victim's account.

Content

Scanner excerpt · REFERENCES.md (reported line 50)May include surrounding context.

md
3. **验证 Key**:实际调用 `codex --full-auto exec "echo ok"`
4. 验证成功 → 写入 `credentials.env`(权限 600);验证失败 → 回到 STEP 2

**运行时**:codex-call.sh 从 skill 目录内的 `credentials.env` 读取 Key

---

Tp4

High
Category
MCP Tool Poisoning
Confidence
94% confidence
Finding

声明将该技能描述为涵盖 API Key 管理与验证、任务执行、结果摘要、后台模式运行等较完整的“会话守护者”。但提供的代码块仅是一个 session.sh 状态脚本,核心行为是基于 state 目录中的 JSON 和锁文件进行状态查询、最近任务列表展示、PID 存活检查、终止进程以及清理状态。它确实部分符合“会话锁定与 PID 追踪”等描述,但缺少声明中的几个关键能力:没有任何 API Key 读取/写入/校验逻辑,没有启动或执行任务的逻辑,也没有生成结果摘要的功能。因此描述明显高于并偏离了该代码块的实际能力,构成描述与行为不一致。

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
95% confidence
Finding

声明描述的是一个更完整的“会话守护者”工具,涵盖会话管理、任务执行与跟踪等多项能力。但提供的代码片段实际上只是 API Key 初始化/验证脚本。它确实涉及 API Key 验证与保存,这与声明中的一部分相符;不过其主要行为并不是会话守护、后台运行或任务编排,也没有任何会话锁定、PID 记录、结果摘要生成等逻辑。因此,描述明显夸大并偏离了该代码块的实际功能,应判定为不匹配。

Content

No source excerpt is available for this finding.

Credential Access

High
Category
Privilege Escalation
Confidence
90% confidence
Finding

The skill explicitly centers around reading an API key from credentials.env for later shell-driven task execution. Even though the document says the key should not be logged and should use 600 permissions, storing live credentials inside the skill workspace and designing normal operation around reading them creates a sensitive secret-access path that could be abused by other prompts, tools, or mis-scoped file access.

Content

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

md
## 技能职责

1. **API Key 管理** — 首次引导输入并验证,验证通过才写入(init-setup);codex-call 直接读取 credentials.env,不重复验证
2. **任务执行** — 后台模式运行 Codex,主人可继续聊天
3. **结果摘要** — 使用 `-o` 输出文件,只保存 Codex 完成语
4. **并发控制** — PID 锁防止多任务同时执行

Credential Access

High
Category
Privilege Escalation
Confidence
90% confidence
Finding

The file inventory documents the exact location of credentials.env and its role as API key storage, which lowers the effort needed for an attacker or a prompt-injected agent to target the secret. In the context of a shell-capable orchestration skill, naming and normalizing a secret file path materially increases the risk of credential discovery and misuse.

Content

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

md
| 路径 | 用途 |
|------|------|
| `credentials.env` | API Key(skill 目录内,600 权限) |
| `state/current-task.json` | 运行中任务 |
| `state/tasks/*.json` | 历史任务摘要 |
| `state/codex.lock` | PID 锁文件 |

Credential Access

High
Category
Privilege Escalation
Confidence
88% confidence
Finding

Although framed as a security principle, this section confirms that the workflow depends on a locally stored API key file. Reliance on file-based secret handling in a shell-enabled agent context remains dangerous because any unexpected file-read capability, debugging output, or auxiliary script can become a credential exfiltration path.

Content

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

md
## 安全原则

1. API Key 不落日志
2. `credentials.env` 权限 600
3. credentials.env 已被 .gitignore 忽略,不会被 git 提交
4. init-setup 验证 Key 通过才写入,失败不保存(codex-call 不验证 Key)

Credential Access

High
Category
Privilege Escalation
Confidence
87% confidence
Finding

The statement that codex-call does not revalidate the key means any value present in credentials.env is trusted for execution. This increases the risk of stale, swapped, or maliciously planted credentials being used silently, and combined with file-based secret storage can enable unauthorized account usage or harder-to-detect abuse.

Content

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

md
1. API Key 不落日志
2. `credentials.env` 权限 600
3. credentials.env 已被 .gitignore 忽略,不会被 git 提交
4. init-setup 验证 Key 通过才写入,失败不保存(codex-call 不验证 Key)

---

Tool Parameter Abuse

High
Category
Tool Misuse
Confidence
95% 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 · bin/codex-call.sh (reported line 131)May include surrounding context.

sh
}
EOF

    rm -f "$STATE_DIR/current-task.json"

) &

Tool Parameter Abuse

High
Category
Tool Misuse
Confidence
95% 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 · bin/session.sh (reported line 158)May include surrounding context.

sh
}
EOF

    rm -f "$STATE_DIR/current-task.json"

) &

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 · bin/codex-call.sh (reported line 15)May include surrounding context.

sh
# init-setup.sh — 检查并引导设置 OPENAI_API_KEY_0011AI
#
# 流程:
#   STEP 1: 触发条件 — credentials.env 不存在
#   STEP 2: Fallback — 优先读环境变量 $OPENAI_API_KEY_0011AI,否则要求用户提供
#   STEP 3: 验证 Key 有效,无效或空则回到 STEP 2
#   STEP 4: 写入 credentials.env,权限 600,结束

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 · scripts/init-setup.sh (reported line 5)May include surrounding context.

sh
# init-setup.sh — 检查并引导设置 OPENAI_API_KEY_0011AI
#
# 流程:
#   STEP 1: 触发条件 — credentials.env 不存在
#   STEP 2: Fallback — 优先读环境变量 $OPENAI_API_KEY_0011AI,否则要求用户提供
#   STEP 3: 验证 Key 有效,无效或空则回到 STEP 2
#   STEP 4: 写入 credentials.env,权限 600,结束

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 · scripts/init-setup.sh (reported line 8)May include surrounding context.

sh
# init-setup.sh — 检查并引导设置 OPENAI_API_KEY_0011AI
#
# 流程:
#   STEP 1: 触发条件 — credentials.env 不存在
#   STEP 2: Fallback — 优先读环境变量 $OPENAI_API_KEY_0011AI,否则要求用户提供
#   STEP 3: 验证 Key 有效,无效或空则回到 STEP 2
#   STEP 4: 写入 credentials.env,权限 600,结束

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 · scripts/init-setup.sh (reported line 17)May include surrounding context.

sh
# init-setup.sh — 检查并引导设置 OPENAI_API_KEY_0011AI
#
# 流程:
#   STEP 1: 触发条件 — credentials.env 不存在
#   STEP 2: Fallback — 优先读环境变量 $OPENAI_API_KEY_0011AI,否则要求用户提供
#   STEP 3: 验证 Key 有效,无效或空则回到 STEP 2
#   STEP 4: 写入 credentials.env,权限 600,结束

Credential Access

High
Category
Privilege Escalation
Confidence
84% confidence
Finding

The script writes the API key in plaintext to credentials.env. Although it applies mode 600 afterward, plaintext local storage still creates exposure risk if the project directory is backed up, synced, committed accidentally, or read before permissions are tightened.

Content

Scanner excerpt · scripts/init-setup.sh (reported line 136)May include surrounding context.

sh
fi
done

# STEP 4: 写入 credentials.env
cat > "$CRED_FILE" <<EOF
OPENAI_API_KEY_0011AI=$NEW_KEY
EOF

Credential Access

High
Category
Privilege Escalation
Confidence
95% confidence
Finding

The task description embeds shell metacharacters and a command substitution pattern using /etc/passwd inside a filename-like string. Even though this JSON file is only a record, it documents an input designed to probe for command injection/path handling weaknesses, and any component that later interpolates this field into a shell command could execute unintended commands or access sensitive files.

Content

Scanner excerpt · state/tasks/task-20260404-004.json (reported line 3)May include surrounding context.

json
{
  "task_id": "20260404-004",
  "description": "用 Python 写文件 test"\$`cat /etc/passwd`.py 内容是 `print("危险字符测试")`",
  "status": "done",
  "summary": "已创建文件 [test\"\$`cat /etc/passwd`.py](/Users/qztcm09/.openclaw/workspace/tmp/codex/test%22%5C$%60cat%20/etc/passwd%60.py),内容是:  ```python print(\"危险字符测试\") ```  这里的 `/` 被当作路径分隔符,所以实际是创建了相对路径 `test\"\$`cat /etc/passwd`.py`",
  "started_at": "2026-04-04T14:33:05+08:00",

Credential Access

High
Category
Privilege Escalation
Confidence
97% confidence
Finding

The summary shows the dangerous string was propagated into output and path-like rendering, including /etc/passwd and shell metacharacters. This increases risk because logging, hyperlink generation, templating, or later automation may reuse the tainted string, leading to command injection, path traversal effects, or disclosure of sensitive file references in operational tooling.

Content

Scanner excerpt · state/tasks/task-20260404-004.json (reported line 5)May include surrounding context.

json
"task_id": "20260404-004",
  "description": "用 Python 写文件 test"\$`cat /etc/passwd`.py 内容是 `print("危险字符测试")`",
  "status": "done",
  "summary": "已创建文件 [test\"\$`cat /etc/passwd`.py](/Users/qztcm09/.openclaw/workspace/tmp/codex/test%22%5C$%60cat%20/etc/passwd%60.py),内容是:  ```python print(\"危险字符测试\") ```  这里的 `/` 被当作路径分隔符,所以实际是创建了相对路径 `test\"\$`cat /etc/passwd`.py`",
  "started_at": "2026-04-04T14:33:05+08:00",
  "finished_at": "2026-04-04T14:33:28+08:00"
}

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The guide mentions --dangerously-bypass-approvals-and-sandbox and describes it casually as '真正的 yolo' without a strong warning about unrestricted command execution, file modification, and possible impact to user data or the host system. In a tool that orchestrates CLI execution, normalizing this flag materially increases the risk that operators invoke a no-guardrails mode they do not fully understand.

Content

No source excerpt is available for this finding.