T09 · Insecure Skill Coding Practices
- Location
scripts/tool-error-tracker.sh:12- Finding
Unvalidated Session Identifier Enables Filesystem Path Traversal and State Poisoning
- Content
View full analysis
/dev/null) [ -z "$SESSION_ID" ] && SESSION_ID="${NC_SESSION:-}" [ -z "$SESSION_ID" ] && exit 0 SESSION_DIR="${SESSIONS_DIR}/${SESSION_ID}" mkdir -p "$SESSION_DIR" STATE_FILE="${SESSION_DIR}/tool-errors.json" ``` The resulting path is later written through an atomic replacement: ```bash TMP="${STATE_FILE}.${$}.$(date +%s).tmp" jq -n \ --arg tool "$TOOL" \ --arg hash "$INPUT_HASH" \ --arg error "$ERROR" \ --argjson count "$COUNT" \ --arg first "$(jq -r '.first_at // ""' "$STATE_FILE" 2>/dev/null || echo "$NOW")" \ --arg last "$NOW" \ '{tool_name: $tool, input_hash: $hash, error: $error, count: $count, first_at: (if $first == "" then $last else $first end), last_at: $last}' \ > "$TMP" mv "$TMP" "$STATE_FILE" ``` The advisor constructs a read path in the same way: ```bash # scripts/tool-error-advisor.sh SESSIONS_DIR="${HOME}/.openclaw/shared-context/sessions}" INPUT=$(cat) SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // ""' 2>/dev/null) [ -z "$SESSION_ID" ] && SESSION_ID="${NC_SESSION:-}" [ -z "$SESSION_ID" ] && echo '{"continue":true}' && exit 0 STATE_FILE="${SESSIONS_DIR}/${SESSION_ID}/tool-errors.json" [ -f "$STATE_FILE" ] || { echo '{"continue":true}'; exit 0; } ``` The denial tracker repeats the unsafe construction: ```bash SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // ""' 2>/dev/null) [ -z "$SESSION_ID" ] && SESSION_ID="${NC_SESSION:-}" [ -z "$SESSION_ID" ] && echo '{"continue":true}' && exit 0 SESSION_DIR="${SESSIONS_DIR}/${SESSION_ID}" STATE_FILE="${SESSION_DIR}/de ...[truncated 2285 chars]- Remediation
View remediation
