Skip to content

fix: guard knowledge file mutations - #27

Draft
cursor[bot] wants to merge 3 commits into
mainfrom
cursor/critical-bug-investigation-3c35
Draft

cursor[bot] wants to merge 3 commits into
mainfrom
cursor/critical-bug-investigation-3c35

Conversation

@cursor

@cursor cursor Bot commented Aug 25, 2026

Copy link
Copy Markdown

Pull Request Checklist

Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.

Before submitting, make sure you've checked the following:

  • Target branch: Please verify that the pull request targets the dev branch.
  • Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
  • Testing: Have you written and run sufficient tests to validate the changes?
  • Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
  • Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following:
    • BREAKING CHANGE: Significant changes that may affect compatibility
    • build: Changes that affect the build system or external dependencies
    • ci: Changes to our continuous integration processes or workflows
    • chore: Refactor, cleanup, or other non-functional code changes
    • docs: Documentation update or addition
    • feat: Introduces a new feature or enhancement to the codebase
    • fix: Bug fix or error correction
    • i18n: Internationalization or localization changes
    • perf: Performance improvement
    • refactor: Code restructuring for better maintainability, readability, or scalability
    • style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.)
    • test: Adding missing tests or correcting existing tests
    • WIP: Work in progress, a temporary label for incomplete or ongoing work

Changelog Entry

Description

  • Bug and impact: A user with write access to any knowledge base could submit another user's guessed file_id to knowledge file routes. Add/batch-add could index foreign file contents into the caller's knowledge base, while remove deleted the global file database record before verifying the file belonged to that knowledge base, causing cross-user data loss.
  • Root cause: Knowledge file endpoints authorized the knowledge base but did not authorize the referenced file or verify membership before vector/database mutations. The remove endpoint also treated a knowledge detach as a global file deletion.
  • Fix: Require users to own files (or be admin) before adding them to knowledge, require update/remove file IDs to already belong to the target knowledge base before file lookup or vector mutation, and remove the global file deletion from knowledge detach.

Added

  • Dependency-light knowledge file helper coverage in tests/test_knowledge_file_regressions.py.

Changed

  • Knowledge file add, update, remove, and batch-add routes now enforce file ownership/membership invariants before processing.

Deprecated

  • None.

Removed

  • Removed unintended global file-row and per-file vector collection deletion from knowledge file detach.

Fixed

  • Fixed cross-user knowledge file IDOR/data-loss path in knowledge file mutation endpoints.

Security

  • Prevents unauthorized indexing of another user's file content and prevents deleting unrelated file records via /api/v1/knowledge/{id}/file/remove.

Breaking Changes

  • None.

Additional Information

  • Validation performed:
    • python3 -m py_compile backend/open_webui/utils/knowledge_files.py backend/open_webui/routers/knowledge.py tests/test_knowledge_file_regressions.py
    • python3 tests/test_knowledge_file_regressions.py
    • git diff --cached --check

Screenshots or Videos

  • Not applicable; backend authorization/data-loss fix.

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.

Open in Web View Automation 

cursoragent and others added 3 commits August 25, 2026 11:09
Co-authored-by: mkatwi <mkatwi@users.noreply.github.com>
Co-authored-by: mkatwi <mkatwi@users.noreply.github.com>
Co-authored-by: mkatwi <mkatwi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant