T09 · Insecure Skill Coding Practices
- Location
scripts/nexus.sh:174- Finding
Unvalidated Server-Provided Session ID Enables Filesystem Escape and Recursive Deletion
- Content
View full analysis
Vulnerability Details
File Location:
scripts/nexus.sh:174-179,scripts/nexus.sh:628-641,scripts/nexus.sh:904-917
Vulnerability Type: Path traversal leading to arbitrary filesystem writes and recursive deletion
Risk Level: HighTechnical Analysis
In default, non-verified mode, the
createandclaimhandlers trust thesessionIdreturned by the remote server and use it directly as a filesystem path component:bash RESP_CREATOR=$(echo "$RESPONSE" | jq -r '.creatorAgentId // empty') if [[ -n "$RESP_CREATOR" && "$STRICT_SESSION" != true ]]; then SESSION_ID=$(echo "$RESPONSE" | jq -r '.sessionId // empty') if [[ -n "$SESSION_ID" ]]; then write_binding "$SESSION_ID" AGENT_FILE="$NEXUS_DATA_DIR/$SESSION_ID/agent" strict_atomic "$AGENT_FILE" "$RESP_CREATOR" || strict_error local_state_error SESSION_KEY=$(echo "$RESPONSE" | jq -r '.sessionKey // empty') if [[ -n "$SESSION_KEY" ]]; then KEY_FILE="$NEXUS_DATA_DIR/$SESSION_ID/key" strict_atomic "$KEY_FILE" "$SESSION_KEY" || strict_error local_state_error fi fi fiThe same response-driven persistence occurs after a successful pairing claim:
bash SESSION_ID=$(echo "$RESPONSE" | jq -r '.sessionId // empty') if [[ -n "$SESSION_ID" && "$STRICT_SESSION" != true ]]; then write_binding "$SESSION_ID" AGENT_FILE="$NEXUS_DATA_DIR/$SESSION_ID/agent" strict_atomic "$AGENT_FILE" "$AGENT_ID" || strict_error local_state_error SESSION_KEY=$(echo "$RESPONSE" | jq -r '.sessionKey // empty') if [[ -n "$SESSION_KEY" ]]; then KEY_FILE="$NEXUS_DATA_DIR/$SESSION_ID/key" strict_atomic "$KEY_FILE" "$SESSION_KEY" || strict_error local_state_error fi fiAlthough strict-mode paths validate session identifiers, these default-mode paths do not enforce the documented 48-character hexadecimal session ID format. A value containing
../components therefore escapesNEXUS_DATA_DIRwhen used bywrite_binding,strict_atomic, or direct path con ...[truncated 2370 chars]- Remediation
View remediation
Remediation Suggestions
- Validate every session ID before using it in a URL, lookup, or filesystem path:
bash validate_session_id() { [[ "$1" =~ ^[a-fA-F0-9]{48}$ ]] || strict_error invalid_request } - Apply validation uniformly to:
- Positional session IDs.
- Alias values loaded from
aliases.json. - Session IDs returned by
createandclaim. - Session directory names discovered from local storage.
- Canonicalize each generated state path and verify that it remains strictly beneath the canonical
NEXUS_DATA_DIR. - Reject
.and.., path separators, control characters, and symlinked path components. - Before recursive deletion, repeat identifier validation and containment checks, then use:
bash rm -rf -- "$validated_path" - Prefer descriptor-relative or equivalent safe filesystem operations where available instead of relying only on string concatenation.
- Add regression tests covering traversal values, absolute paths, encoded separators, malformed aliases, and malicious server responses.
- Validate every session ID before using it in a URL, lookup, or filesystem path:
