Skip to content

fix: prevent path traversal in websocket handle_data file reads - #438

Open
painbaba wants to merge 1 commit into
OpenBMB:mainfrom
painbaba:fix/ws-base-path-traversal
Open

fix: prevent path traversal in websocket handle_data file reads#438
painbaba wants to merge 1 commit into
OpenBMB:mainfrom
painbaba:fix/ws-base-path-traversal

Conversation

@painbaba

Copy link
Copy Markdown

Fixes #437

Root cause

handle_data() in XAgentServer/application/websockets/common.py treats file_name from stored Raw records as a trusted workspace-relative path. Record data can be polluted through /conv/community (as described in #437), so os.path.join(root_dir, "workspace", file_name) followed by open() reads files outside the workspace — relative traversal (../x) and absolute-path overrides both escape — and the content is returned base64-encoded to the /ws/base/{interaction_id} websocket client.

Fix

  • Resolve the workspace root and the candidate path with os.path.realpath(), and only read the file when the resolved path stays inside the workspace (file_path.startswith(workspace_dir + os.sep)).
  • Tighten os.path.exists to os.path.isfile so only regular files are read.

Verification

Repro harness running the handle_data implementation from before/after this change against the same fixture:

input before after
../secret.txt (outside workspace) file returned blocked
absolute path outside workspace file returned blocked
plot.png inside workspace returned returned (unchanged, base64 identical)

file_name stored in raw records is client-influenced (it can be polluted
via /conv/community), but handle_data() joined it into
root_dir/workspace and read the file without any containment check,
allowing relative traversal and absolute-path overrides to read
arbitrary files as base64 on the /ws/base websocket.

Resolve the candidate path and require it to stay inside the
interaction workspace before reading.

Fixes OpenBMB#437
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.

[Vulnerability] Path Traversal in /ws/base endpoint

2 participants