T09 · Insecure Skill Coding Practices
- Location
scripts/_lib.sh:49- Finding
Unvalidated Session Identifier Enables Path Traversal and Arbitrary File Overwrite
- Content
View full analysis
/dev/null || true) if [ -z "${sid:-}" ]; then local file="$CHRONOS_HOME/current-session" if [ -f "$file" ]; then sid=$(cat "$file") else sid="anon-$(now_epoch)" echo "$sid" > "$file" fi fi echo "$sid" } ``` ```bash # scripts/session_start.sh:9-32 INPUT=$(cat) SESSION=$(resolve_session_id "$INPUT") LEDGER=$(ledger_path "$SESSION") STATE=$(state_path "$SESSION") NOW_UTC=$(now_utc_iso) NOW_LOCAL=$(now_local_iso) NOW_EPOCH=$(now_epoch) TZ=$(tz_name) OFFSET=$(utc_offset) # Init ledger (truncate if fresh session start) : > "$LEDGER" # Init state if command -v jq >/dev/null 2>&1; then jq -n \ --arg s "$SESSION" --arg iso "$NOW_UTC" --arg loc "$NOW_LOCAL" \ --arg tz "$TZ" --arg off "$OFFSET" --argjson ep "$NOW_EPOCH" \ '{session_id:$s, started_at_utc:$iso, started_at_local:$loc, started_at_epoch:$ep, tz:$tz, utc_offset:$off, turn:0, last_user_at_utc:$iso, last_user_at_epoch:$ep}' \ > "$STATE" else cat > "$STATE" <- Remediation
View remediation
.jsonl`. - Store the original identifier only inside the state file if needed. 3. Enforce canonical-path containment: - Resolve both `CHRONOS_HOME` and the destination path to canonical absolute paths. - Verify that the destination begins with the canonical home path plus the platform path separator. - Abort without writing if containment fails. 4. Apply identical protections in: - `scripts/_lib.sh` - `scripts/_lib.ps1` - `installers/opencode/plugin.ts` 5. Harden file creation: - Create `CHRONOS_HOME` with user-only permissions. - Create ledger and state files with restrictive permissions. - Avoid following symbolic links where platform APIs permit it. - Use exclusive or no-follow file-opening flags for security-sensitive writes. 6. Add regression tests for identifiers containing: - `../` and `..\` - Absolute Unix paths - Windows drive and UNC paths - Encoded separators - Newlines and control characters - Excessively long values ]]>
