fix(knowledge): keep PATCH category moves inside knowledge/ - #469
Merged
Merged
Conversation
PATCH /knowledge/documents/{doc_id} sanitized the new category with a
private copy of the dirname rule that lacked the "." / ".." fallback, so
category_id ".." moved the document directory out of knowledge/ into
the project directory, where the md scan no longer finds it.
Route the category through the shared sanitize_dirname (the rule the
create path already uses, so "." / ".." fall back to "Others"), build
the target from the project's knowledge_dir, and assert the resolved
target stays inside it before any directory is created or moved. A
document an earlier move left outside knowledge/ is moved back on its
next category change.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The supported-versions table still named 1.2.x as current; 1.4.x is the live line. Also state where the advisory line sits: issues that let untrusted input reach beyond what the caller can already touch get an advisory, while issues a trusted caller can trigger only against its own data are fixed as hardening and noted in the release notes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
gloryfromca
approved these changes
Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PATCH /knowledge/documents/{doc_id}sanitized a newcategory_idwith a private copy of the dirname rule (_safe_category) that lacked the./..fallback of the sharedsanitize_dirname. Withcategory_id: ".."the document directory was moved fromknowledge/<category>/up into the project directory, where the md-scan fallback no longer finds it (and an index rebuild from markdown would drop it). Reported privately; impact is limited to data the caller can already modify through the API, so it is handled as hardening per the threat model in SECURITY.md.service/knowledge.py): drop_safe_category; the move target isknowledge_dir(app, project) / sanitize_dirname(category, "Others") / <doc dir>, so./..fall back toOthersexactly as on create. The resolved target is asserted to stay insideknowledge/before any directory is created or moved (PathTraversalErrorotherwise). A document an earlier move left outside is moved back on its next category change.1.2.x→1.4.x; add a "what counts as a vulnerability" line under Scope.[Unreleased]→ Fixed entry.An audit of the other places where external input becomes a path segment (app/project/sender ids, upload filename, create-time category/title/topic, skill/reference/script names, profile writes) found no other instance; they all go through
PathSafeId,sanitize_dirname, orMarkdownWriter._ensure_within_root.Area
Verification
New tests in
tests/unit/test_service/test_knowledge_crud.py(real filesystem): categoryResearch Notes/../.stay inknowledge/; an escaped doc is repaired; a category dir symlinked outsideknowledge/raisesPathTraversalError. The..,.and symlink cases fail against the previous code.Checklist
main..envfiles, dependency folders, or generated output.Notes for Reviewers
category_idmetadata keeps the raw value (as on create); only the directory segment is sanitized._require_knowledge_capabilitiesis a feature-tier gate (embed + rerank), not authorization, so PATCH intentionally stays without it.By submitting this pull request, I agree that my contribution is licensed under
the Apache License 2.0.
🤖 Generated with Claude Code