-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The function is named has_access_to_file. The query it runs does not take a user_id.\n\n`backend/open_webui/utils/access_control/files.py` in Open WebUI v0.8.12 ships one function, `has_access_to_file(file_id, access_type, user, db)`, that every file-router endpoint calls to decide whether the caller is allowed to read, write, or delete a file they do not own. The function is the one place where multi-tenant authorization lives for the file subsystem. Nine call sites in `backend/open_webui/routers/files.py` route through it, including `DELETE /api/v1/files/{id}` and `POST /api/v1/files/{id}/data/content/update`.\n\nThe function has five branches. Four of them check who is asking. The fifth is the CVE.\n\n```python\ndef has_access_to_file(\n file_id: str | None,\n access_type: str,\n user: UserModel,\n db: Session | None = None,\n) -> bool:\n file = Files.get_file_by_id(file_id, db=db)\n if not file:\n return False\n\n # Direct ownership\n if file.user_id == user.id:\n return True\n\n # Check if the file is associated with any knowledge bases the user has access to\n knowledge_bases = Knowledges.get_knowledges_by_file_id(file_id, db=db)\n user_group_ids = {group.id for group in Groups.get_groups_by_member_id(user.id, db=db)}\n for knowledge_base in knowledge_bases:\n if knowledge_base.user_id == user.id or AccessGrants.has_access(\n user_id=user.id,\n resource_type='knowledge',\n resource_id=knowledge_base.id,\n permission=access_type,\n user_group_ids=user_group_ids,\n db=db,\n ):\n return True\n\n knowledge_base_id = file.meta.get('collection_name') if file.meta else None\n if knowledge_base_id:\n knowledge_bases = Knowledges.get_knowledge_bases_by_user_id(user.id, access_type, db=db)\n for knowledge_base in knowledge_bases:\n if knowledge_base.id == knowledge_base_id:\n return True\n\n # Check if the file is associated with any channels the user has access to\n channels = Channels.get_channels_by_file_id_and_user_id(file_id, user.id, db=db)\n if access_type == 'read' and channels:\n return True\n\n # Check if the file is associated with any chats the user has access to\n # TODO: Granular access control for chats\n chats = Chats.get_shared_chats_by_file_id(file_id, db=db)\n if chats:\n return True\n ...\n```\n\nRead the channels branch and the chats branch side by side. They are three lines apart in the same function. They are the same shape: \"is this file associated with a container the caller has access to.\"\n\nThe channels branch's query takes `user.id`. It returns only the channels this user is a member of. The predicate checks `access_type == 'read'`. If the access requested is anything other than read, the branch declines.\n\nThe chats branch's query takes `file_id`. It takes nothing else. The predicate checks whether the result is non-empty. If any shared chat anywhere on the system references this file, the branch returns True, for every user, for every access type.\n\n`Chats.get_shared_chats_by_file_id` is in `backend/open_webui/models/chats.py`:\n\n```python\ndef get_shared_chats_by_file_id(self, file_id: str, db: Optional[Session] = None) -> list[ChatModel]:\n with get_db_context(db) as db:\n # Join Chat and ChatFile tables to get shared chats associated with the file_id\n all_chats = (\n db.query(Chat)\n .join(ChatFile, Chat.id == ChatFile.chat_id)\n .filter(ChatFile.file_id == file_id, Chat.share_id.isnot(None))\n .all()\n )\n return [ChatModel.model_validate(chat) for chat in all_chats]\n```\n\nThe query the gate runs against the database does not take a user_id. The function it lives inside is named `has_access_to_file`.\n\n## DELETE asks for 'write'. The branch answers 'yes' anyway.\n\nThe delete endpoint at `backend/open_webui/routers/files.py:751` is unambiguous about what it is asking for:\n\n```python\n@router.delete('/{id}')\nasync def delete_file_by_id(id: str, user=Depends(get_verified_user), db: Session = Depends(get_session)):\n file = Files.get_file_by_id(id, db=db)\n if not file:\n raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=ERROR_MESSAGES.NOT_FOUND)\n\n if file.user_id == user.id or user.role == 'admin' or has_access_to_file(id, 'write', user, db=db):\n # ... proceed to delete from KB associations, vector store, storage, and the files table\n```\n\nThe string `'write'` flows into `has_access_to_file` as the `access_type` argument. The channels branch reads that argument and refuses the request. The chats branch never reads it. The function returns True. The handler proceeds through `Knowledges.remove_file_from_knowledge_by_id`, `VECTOR_DB_CLIENT.delete`, `Files.delete_file_by_id`, and `Storage.delete_file`. The file is gone, the embeddings are gone, the knowledge-base associations are gone, and the response is `{\"message\": \"File deleted successfully\"}`.\n\nThe full attacker request is one curl, given any authenticated session token and any known file UUID:\n\n```bash\ncurl -X DELETE \\\n -H 'Authorization: Bearer ' \\\n https://target.example/api/v1/files/\n```\n\nThe precondition the attacker has to satisfy is that the target file has at some point been attached to a chat the file's owner has shared. `Chat.share_id.isnot(None)` is the filter, and `share_id` is set the first time the owner clicks \"Share\" on the chat in the UI. The share is \"public via link\" semantics, the share_id becomes part of a `/s/{share_id}` URL, but the gate does not check whether the caller holds that URL or has any other relationship to the chat. The gate checks whether the row exists.\n\n## The file UUID is not a secret either\n\nThe CVE description leans on the file UUID being \"impractical to guess.\" It is, in the sense that file UUIDs are 36-character v4s and you cannot brute-force the keyspace. It is not, in the sense that the system publishes them on at least two well-known paths to authenticated users.\n\n`GET /api/v1/knowledge/{id}/files` returns `KnowledgeFileListResponse` whose `items` are `FileUserResponse` objects, which extend `FileModelResponse`:\n\n```python\nclass FileModelResponse(BaseModel):\n id: str\n user_id: str\n hash: Optional[str] = None\n filename: str\n ...\n```\n\nThe endpoint is gated by knowledge-base read access. In a deployment with any shared knowledge base (the common workspace pattern), every user with read access to that KB receives the list of file UUIDs in it, along with the original `user_id` of each file's owner. From that list, the attacker picks a file whose `user_id` is the target, and tries the delete. The delete succeeds for any file in the list that has also been referenced in a shared chat. The KB sharing model assumes \"read access lets you read the files.\" The shared-chat branch quietly upgrades that read access to write-and-delete on the subset of files that also appear in any shared chat anywhere.\n\n`GET /api/v1/chats/share/{share_id}` returns the full chat object, including the message content. File references in chat messages are stored as `{file_id: , ...}` dictionaries. Any authenticated user with a share URL learns the file UUIDs the chat references, and any of those UUIDs is a valid input to the delete.\n\nThe UUID is not the secret. The UUID is the cursor.\n\n## The TODO comment named the access control\n\n`# TODO: Granular access control for chats` is the entire fix in three words.\n\nThe 0.9.0 commit replaces the branch with code that does what the comment said:\n\n```diff\n # Check if the file is associated with any chats the user has access to\n- # TODO: Granular access control for chats\n- chats = Chats.get_shared_chats_by_file_id(file_id, db=db)\n- if chats:\n- return True\n+ shared_chat_ids = await Chats.get_shared_chat_ids_by_file_id(file_id, db=db)\n+ if shared_chat_ids:\n+ accessible_ids = await AccessGrants.get_accessible_resource_ids(\n+ user_id=user.id,\n+ resource_type='shared_chat',\n+ resource_ids=shared_chat_ids,\n+ permission='read',\n+ user_group_ids=user_group_ids,\n+ db=db,\n+ )\n+ if accessible_ids:\n+ return True\n```\n\nThe patched code does three things the unpatched code did not. It returns only the shared chat IDs (not the rows), so the next step has something to filter. It calls `AccessGrants.get_accessible_resource_ids` with the caller's `user_id` and `user_group_ids`, which is the same access-grant machinery the knowledge-base branch above it has been calling all along. And it hard-codes `permission='read'` on the chat-side check, so the shared-chat branch only ever authorizes file access through a chat the caller can read. Delete operations on a file that the caller does not own and does not have KB write access to now have nowhere in the function to pick up authorization, because the chats branch's only `return True` path is gated through a read predicate on the chat.\n\nThe TODO comment is gone from the patched file. The control it described is the patch.\n\n## Five branches, four of them got the assignment\n\nThis is a [Todo That Shipped](/patterns/todo-that-shipped) at the strictest reading. The pattern's canonical form is a comment that names a security-relevant control, with adjacent code that operates without the control. The exhibits in the catalog include [free5GC's `// TODO: Authorize the AF`](/posts/free5gc-cve-2026-44315-oauth-outbound-todo-inbound) sitting above unauthorized PFD handlers for five and a half years, [Cockpit's 2021 comment naming `--output cat`](/posts/cockpit-cve-2026-4802-the-todo-named-the-fix) above the `sh -ec` invocation that became CVE-2026-4802, and [Drupal's `// Use the array values`](/posts/drupal-cve-2026-9082-the-comment-said-values) sitting above the foreach that started using the keys. Open WebUI's variant is shorter on clock (the TODO landed in the same change window as the surrounding refactor of `has_access_to_file` into `utils/access_control/files.py`) and unusually unambiguous on intent: \"Granular access control for chats\" is the exact noun phrase a security review would write at the head of the issue.\n\nIt is also an [Existence Is Authorization](/patterns/existence-is-authorization). The query the branch runs answers \"does this file appear in any shared chat\" with a boolean. The function then returns that boolean as the authorization decision. The pattern's other exhibits include [n8n's `checkIfExecutionExists`](/posts/n8n-chat-existence-was-the-gate) and [Divi Form Builder's `isset($wp_roles->roles[$role])`](/posts/divi-form-builder-cve-2026-5118-administrator-existed). The shape is the same: a handler given a caller-supplied identifier checks that the named resource exists and treats the existence check as the authorization decision. The Open WebUI variant adds a wrinkle the others do not have, which is that the existence check and the granular check were already in the same function, three lines apart. The channels branch immediately above the chats branch took both arguments the chats branch ignored. The author had written the correct shape, then written a second branch that did not match it, then written a comment admitting it.\n\nThe structural reason this exists is not that the developer did not know how to do access control. It is that the developer knew, wrote the comment to remind themselves, and shipped. The TODO comment is not evidence of carelessness. It is evidence of a deferred decision that the next person did not pick up. The five branches in `has_access_to_file` were extended one at a time, and the chat branch is the most recent one. The author saw the shape of the four older branches above it, named the work to bring the new branch into line with them, and pushed.\n\n## The gap between the comment and the next line is the CVE\n\nTwo of the nine file-router endpoints that consult `has_access_to_file` are write operations: `POST /api/v1/files/{id}/data/content/update` and `DELETE /api/v1/files/{id}`. Both of them pass `'write'` as the access_type. Both of them inherited the chats branch's indifference to the access_type. The remediation guide reads \"upgrade to 0.9.0\", which is correct; what the guide does not say is that the upgrade also moves the function to `async def` and rewrites the surrounding async signatures of every caller. The fix is not a backport-friendly one-line change. The fix is the structural commitment to call `AccessGrants` on every branch the function has, which is the commitment the four older branches had already made and the chats branch had been excused from.\n\nThe comment above the branch was the codebase's own description of CVE-2026-45671. The patch makes the comment redundant. The CVE is the four months in between.\n\nPoC: [GHSA-26g9-27vm-x3q8](https://github.com/advisories/GHSA-26g9-27vm-x3q8)","closing_line":"The comment named the access control. The function shipped without it. The query the gate ran does not take a user_id.","hook_md":"Open WebUI's `has_access_to_file()` in version 0.8.12 has five branches. The first four check who is asking. The fifth has a comment above it that reads `# TODO: Granular access control for chats`, and a body that does not. CVE-2026-45671 is the gap between that comment and the next line. Any authenticated user can permanently delete any file that has ever been attached to a publicly shared chat by calling `DELETE /api/v1/files/{id}`, because the gate the delete endpoint consults answers the question \"does this file appear in any shared chat anywhere\" instead of \"is this caller allowed to write to this file.\"","post_id":445,"slug":"open-webui-cve-2026-45671-todo-was-the-access-control","title":"CVE-2026-45671: Open WebUI's TODO Comment Named the Missing Access Control. The Function Shipped Without It.","type":"initial","unreadable_sentence":"The query the gate ran against the database does not take a user_id. The function it lives inside is named has_access_to_file."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCamzVYgAKCRDeZjl4jgkQ JriJAP9pp535oG/I8Fsol88H2nTCLdKAvOA9HiSpp5GDALSS7wD/SHkXqLmytnvg rlVrr+1KCu7+fEp15iIl/BtEA9aGiQU= =ZfMN -----END PGP SIGNATURE-----