T09 · Insecure Skill Coding Practices
- Location
scripts/delete-sandbox.sh:7- Finding
Path Traversal in Sandbox State Paths Can Cause Arbitrary Directory Deletion
- Content
View full analysis
` state directory. The deletion script then passes that path to `rm -rf`. Because `rm` resolves traversal components, it may recursively delete an attacker-selected directory writable by the process. The same weakness in `create-sandbox.sh` can cause SSH keys and the `fqdn` state file to be created outside the intended state directory. ### Attack Path 1. An attacker or untrusted caller supplies a sandbox name containing traversal components, such as `../path/to/target`. 2. The script constructs `/tmp/../path/to/target`, which resolves outside the intended sandbox state namespace. 3. For deletion, the selected directory must contain a readable `fqdn` file so execution reaches the API request. 4. If the UKC deletion request succeeds, the script executes `rm -rf` on the tr ...[truncated 696 chars]- Remediation
View remediation
&2 exit 1 fi ``` 2. Explicitly reject `/`, `\`, `.` and `..` path components. 3. Use a dedicated state root with restrictive permissions instead of the shared `/tmp` namespace: ```bash STATE_ROOT="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/unikraft-sandboxes" install -d -m 700 "${STATE_ROOT}" ``` 4. Resolve the candidate path with `realpath` and verify that its parent is exactly the approved state root before creating or deleting it. 5. Use `mktemp -d` for unique state directories and persist the exact generated path in trusted process state. 6. Before deletion, verify ownership, permissions, expected marker files, and that the resolved target is neither the state root nor any parent directory. 7. Consider removing files individually or using a file-descriptor-relative deletion mechanism rather than applying unrestricted `rm -rf` to a caller-derived path. ]]>
