fix(models): reject path-traversal characters in artifact id fields - #187
fix(models): reject path-traversal characters in artifact id fields#187jason020818 wants to merge 1 commit into
Conversation
Closes vouchdev#149 `Evidence`, `Claim`, `Entity`, `Relation`, `Page`, `Session`, and `Proposal` all declared bare `id: str` with no validation. The storage layer maps those ids directly to filesystem paths: def _yaml(self, sub, obj_id): return self.kb_dir / sub / f"{obj_id}.yaml" An id like `"../../etc/passwd"` would produce a path escaping `kb_dir` on any write operation (`put_*`, `update_*`, lifecycle helpers). Bundle import was already guarded by `_safe_member_path`; model construction was not. Add a module-level `_safe_artifact_id` helper that rejects `/`, `\`, `..`, and NUL bytes, and wire it into a `_id_safe` `@field_validator` on each affected model — mirroring the pattern `Source` already uses for its hex-sha256 constraint. New `tests/test_model_id_safety.py` covers all seven models with parametrized traversal payloads.
|
Warning Review limit reached
More reviews will be available in 54 minutes and 17 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 Plus Run ID: 📒 Files selected for processing (2)
✨ 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 |
|
Closing to focus review bandwidth on higher-priority, smaller bugfix PRs in ragflow/allways/gittensor. Will reopen or resubmit if needed. |
Problem
Every non-Source artifact —
Claim,Page,Entity,Relation,Evidence,Session,Proposal— declaresid: strwith no validator. The storage layer maps those ids directly to filesystem paths viaKBStore._yaml:An id like
"../../etc/passwd"escapeskb_diron any write operation (put_*,update_*, lifecycle helpers).Source.idwas already constrained to a hex sha256; nothing similar existed for the others.Fix
Add a module-level
_safe_artifact_idhelper that rejects/,\,.., and NUL bytes, and wire it into a_id_safe@field_validatoron each affected model — mirroring the patternSourcealready uses.Tests
New
tests/test_model_id_safety.pywith parametrized traversal payloads for all seven affected models. 155 total tests pass.Closes #149