fix(api): prevent arbitrary deletion in DELETE /skills/by-path by validating and canonicalizing paths#215
Conversation
|
Warning Review limit reached
More reviews will be available in 27 minutes and 19 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6262643061
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .iter() | ||
| .any(|sp| skill_dir.starts_with(sp) || skill_dir == *sp); | ||
| let allowed_paths = canonical_allowed_skills_paths(&skills_paths); | ||
| let is_valid = path_is_in_allowed_skill_dir(&skill_dir, &allowed_paths); |
There was a problem hiding this comment.
Allow deleting symlinked skills by validating the link path
When a discovered skill is a symlink inside an agent's skills directory that points to a real directory elsewhere, this canonicalizes delete_dir and compares the target (skill_dir) against the allowed skills roots, so the request is rejected even though the link being deleted is under the valid skills path. Symlinked skills are supported elsewhere in the repo (discovery records canonical_path for symlink entries and the manager removes only the symlink), and the UI sends the displayed sourcePath, so users can no longer remove those valid symlinked skill installations via this endpoint.
Useful? React with 👍 / 👎.
Motivation
DELETE /skills/by-pathroute accepted a caller-suppliedsource_pathandagentsand performedremove_dir_allon the derived directory, allowing deletion outside intended skill directories whenagentswas empty or when paths used lexical traversal (..).source_pathvalues by deriving and deleting parent directories, which could recursively delete large parts of the filesystem.Description
agentslist early to avoid bypassing validation usingif req.agents.is_empty()and return a clear error via a helperdelete_by_path_response.canonical_skill_dir,canonical_allowed_skills_pathsandpath_is_in_allowed_skill_dirhelpers to perform containment checks on canonical paths rather than lexicalstarts_with.source_skill_dir(use the directory itself or its parent for file targets) and only attempt deletion on the verified target directory (delete_dir), while treating nonexistentsource_pathas an idempotent no-op (return success without deleting a parent directory).detect_plugin_for_pathagainst the resolved source directory and invokeremove_dir_allonly on the validateddelete_dir.Testing
cargo fmt -p aghub-api --checkwhich passed.git diff --check) which passed.cargo test -p aghub-apiandRUSTC_WRAPPER= cargo test -p aghub-api --offline, but full test execution was blocked by the environment (missingsccachewrapper binary and blocked network access / uncached dependencies), so unit tests added to the crate could not be executed here.crates/api/src/routes/skills.rsfor the new path validation helpers.Codex Task