SECURITY: validate context IDs before chat persistence/removal to prevent path traversal outside usr/chats #180
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
nsaspy/a0-symbolics#180
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Finding
Context IDs cross a filesystem trust boundary without canonical validation.
helpers/context_utils.py::use_context()accepts a caller-providedctxidand, if it does not already exist, constructs anAgentContext(id=ctxid)verbatim.Chat persistence then builds paths with:
helpers.files.get_abs_path()is onlyos.path.join(_base_dir, *relative_paths)for relative inputs; it does not normalize/reject.., separators or absolute path components in a multi-part join.More critically,
api/chat_remove.pyacceptsinput["context"], callspersist_chat.remove_chat(ctxid)even when no context exists, andremove_chat()calls:files.delete_dir()resolves the supplied joined path through the OS and recursively callsshutil.rmtree(..., ignore_errors=True)with no containment check.A context ID containing traversal components can therefore escape
usr/chats. Depending on process permissions, chat removal can recursively delete a directory outside the chat store, and persistence can create/writechat.jsonoutside the intended store.Example shape to cover in regression tests (do not use a real important path):
Required fix direction
Treat context IDs as opaque identifiers with one canonical validator used at every external boundary and persistence entry point.
./.., absolute paths, NUL/control characters and invalid length/charset before lookup/create/removePath(...).resolve().is_relative_to(CHATS_FOLDER.resolve())Acceptance
chat_createcannot create a context whose ID escapes or creates nested filesystem paths.chat_removecannot delete anything outside the canonicalusr/chats/<validated-id>directory.save_tmp_chat,remove_chat, message-file helpers and chat-file path helpers defensively enforce containment even if called internally with an invalid ID..., slash/backslash variants, absolute paths, URL-ish values, empty/whitespace, Unicode/control characters and overlong IDs.Mirrored from
lost-rob0t/a0-symbolics#43via tracker sync.