T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/code-review-robust.sh:22
- Finding
- Untrusted PR content is reviewed by a privileged, stateful main agent<![CDATA[ ## Vulnerability Details **File Location**: `scripts/code-review-robust.sh:22-94` **Vulnerability Type**: Indirect prompt injection and excessive agent privileges **Risk Level**: High ### Vulnerable Code ```bash SESSION_ID="gitcode-pr-review-${REPO_OWNER}-${REPO_NAME}-$(date +%Y%m%d)" WORKSPACE_DIR="${OPENCLAW_WORKSPACE:-${HOME}/.openclaw/workspace}" REVIEW_DIR="$WORKSPACE_DIR/reviews/$(date +%Y-%m)" mkdir -p "$REVIEW_DIR" REVIEW_FILE="$REVIEW_DIR/PR-${PR_ID}-${REPO_NAME}.md" LOG_FILE="$WORKSPACE_DIR/logs/code-review-${REPO_NAME}-${PR_ID}.log" TASK="... - API: https://gitcode.com/api/v5/repos/${REPO_OWNER}/${REPO_NAME}/pulls/${PR_ID}/files - Token path: $WORKSPACE_DIR/data/gitcode-token.txt ... - The report must be saved to: ${REVIEW_FILE} ..." AGENT_OUTPUT=$("$OPENCLAW_CMD" agent \ --agent main \ --session-id "$SESSION_ID" \ --message "$TASK" \ --timeout 600 \ --thinking high \ 2>&1) || true ``` The `TASK` excerpt above is an English rendering of the original task text while preserving the security-relevant paths, endpoint, and instructions. ### Technical Analysis The script delegates review of contributor-controlled PR content to the OpenClaw `main` agent. The task directs that agent to retrieve the PR diff, reveals the local GitCode credential path, and directs it to write to a workspace report file. No control shown in the audited code: - Restricts the agent to a dedicated, least-privileged review profile. - Removes filesystem or network tools not required for analysis. - Treats instructions embedded in source code, comments, filenames, or diff text as untrusted data. - Prevents the agent from reading files other than the intended PR data. - Prevents secrets or unrelated workspace content from being included in the generated report. The session identifier is reused for all PRs in the same repository during a given day. Consequently, malicious content encountered while reviewing one PR can potentially influence ...[truncated 2140 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Create a dedicated review-only agent instead of using `--agent main`. 2. Remove filesystem, shell, credential, messaging, and unrestricted network tools from the review agent. 3. Fetch PR metadata and diffs in a deterministic wrapper, then provide only the required sanitized diff to the model. 4. Do not disclose credential paths or token-handling details in model prompts. 5. Explicitly state that all repository content is untrusted data and that instructions found in code, comments, documentation, filenames, or diffs must never be followed. 6. Use a fresh session for every PR, such as a session identifier containing the immutable repository identity and PR number. 7. Apply output controls before publication: - Scan for tokens, secrets, private keys, and unexpected file contents. - Enforce report size and format limits. - Require human approval before sending reports outside GitCode. 8. Separate review generation from publication. The review agent should not have access to DingTalk, WeCom, or GitCode comment-posting capabilities. 9. Use a narrowly scoped GitCode token with read-only access for diff retrieval. Use a separate narrowly scoped credential for comment submission. 10. Run the review process in a sandbox with an isolated filesystem, no inherited secrets, and an explicit destination allowlist. ]]>
