T09 · Insecure Skill Coding Practices
- Location
bridge.py:339- Finding
Unvalidated Task Identifier Permits Path Traversal Outside Bridge Storage
- Content
View full analysis
None: task_dir = TASKS_DIR / task_id task_dir.mkdir(parents=True, exist_ok=True) (task_dir / "bridge.pid").write_text(str(os.getpid())) write_json_atomic( task_dir / "task.json", { "task_id": task_id, "workdir": workdir, "prompt": prompt, "created_at": now_iso(), "round": 0, }, ) (task_dir / "output.log").touch() (task_dir / "events.jsonl").touch() (task_dir / "bridge.log").touch() ``` `bridge.py:415-417`: ```python def sigterm_handler(signum: int, frame: Any) -> None: task_dir = TASKS_DIR / args.task_id write_status(task_dir, "error", "Bridge process terminated by signal") ``` `codex-bridge-dispatch.sh:63-68`: ```bash if [[ -d "$TASKS_DIR/$TASK_ID" ]]; then echo "Error: task '$TASK_ID' already exists at $TASKS_DIR/$TASK_ID" exit 1 fi mkdir -p "$TASKS_DIR/$TASK_ID" ``` `codex-bridge-answer.sh:42-57`: ```bash TASK_DIR="$TASKS_DIR/$TASK_ID" if [[ ! -d "$TASK_DIR" ]]; then echo "Error: task '$TASK_ID' not found" exit 1 fi if [[ -f "$TASK_DIR/status.json" ]]; then STATUS=$(python3 -c "import json,sys; print(json.load(open(sys.argv[1])).get('status',''))" "$TASK_DIR/status.json" 2>/dev/null || echo "") if [[ "$STATUS" != "waiting_for_answer" ]]; then echo "Warning: task status is '$STATUS', not 'waiting_for_answer'" fi fi TMP_FILE="$TASK_DIR/answer.json.tmp" ANSWER_FILE="$TASK_DIR/answer.json" ``` `codex-bridge-status.sh:75-112`: ```bash TASK_DIR="$TASKS_DIR/$TASK_ID" if [[ ! -d "$TASK_DIR" ]]; ...[truncated 3331 chars]- Remediation
View remediation
str: if not TASK_ID_RE.fullmatch(task_id): raise ValueError("Invalid task identifier") if task_id in {".", ".."}: raise ValueError("Invalid task identifier") return task_id ``` 2. Resolve the destination and enforce containment before every access: ```python tasks_root = TASKS_DIR.resolve() task_dir = (tasks_root / validate_task_id(task_id)).resolve() if task_dir.parent != tasks_root: raise ValueError("Task path escapes task storage") ``` 3. Apply equivalent validation in all three shell entry points, or centralize path resolution in a single Python helper used by every operation. 4. Explicitly reject `/`, `\`, `..`, control characters, and absolute paths in task identifiers. 5. Reject symbolic-link task directories and sensitive files. Where supported, use descriptor-relative filesystem operations and no-follow semantics to reduce time-of-check/time-of-use and symlink risks. 6. Add automated tests covering: - `../` traversal. - Absolute paths. - Nested separators. - Symlinked task directories. - Valid identifiers at minimum and maximum lengths. ]]>
