T09 · Insecure Skill Coding Practices
- Location
references/11-hook-bracket.md:18- Finding
Unvalidated Session Identifier Enables Temporary-File Path Traversal and Symlink Attacks
- Content
View full analysis
/dev/null | grep -o '[0-9]*$' || echo "0") jq -n --arg ts "$(date +%s)" --arg ctx "$CTX" --arg sid "$SESSION_ID" \ '{start_ts: $ts, start_ctx: $ctx, session_id: $sid}' > "$TMPDIR/bracket-${SESSION_ID}.json" ``` ```bash INPUT=$(cat) SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // ""') TRANSCRIPT=$(echo "$INPUT" | jq -r '.transcript_path // ""') BRACKET_FILE="$TMPDIR/bracket-${SESSION_ID}.json" [ -f "$BRACKET_FILE" ] || exit 0 START=$(cat "$BRACKET_FILE") ELAPSED=$(( $(date +%s) - $(echo "$START" | jq -r '.start_ts') )) CUR_CTX=$(bash context-usage.sh "$TRANSCRIPT" 2>/dev/null | grep -o '[0-9]*$' || echo "0") ``` ### Technical Analysis The hook obtains `SESSION_ID` from JSON input and directly embeds it into a path under `$TMPDIR`. Shell quoting prevents word splitting and wildcard expansion, but it does not remove path separators or traversal components such as `../`. If a caller can influence the hook payload, a crafted session identifier can cause the first hook to write outside the intended bracket-state namespace. The Stop hook can subsequently read from an unintended path. The predictable pathname also exposes the operation to symlink attacks by another process with access to the temporary directory. The same code accepts `transcript_path` from the input and passes it to another script without validating that it identifies an authorized transcript. Although it is passed as a quoted argument rather than evaluated as shell syntax, the receiving script could be induced to process an unintended local file. ### Attack Path 1. An attacker influences the hook inp ...[truncated 983 chars]- Remediation
View remediation
