Skip to content

fix(app): prevent path traversal via user_id header in python file upload (#3104)#3118

Open
qfmy83 wants to merge 1 commit into
eosphoros-ai:mainfrom
qfmy83:fix/issue-3104-path-traversal
Open

fix(app): prevent path traversal via user_id header in python file upload (#3104)#3118
qfmy83 wants to merge 1 commit into
eosphoros-ai:mainfrom
qfmy83:fix/issue-3104-path-traversal

Conversation

@qfmy83

@qfmy83 qfmy83 commented Jun 27, 2026

Copy link
Copy Markdown

What

The POST /api/v1/python/file/upload handler builds the destination directory from the untrusted user_id request header:

upload_dir = os.path.join(base_dir, "python_uploads", user_id)
os.makedirs(upload_dir, exist_ok=True)

user_id is used directly as a path component with no validation, and the existing _resolve_upload_path containment check only validates the filename against upload_dir — which has already been poisoned by user_id. A header such as user_id: ../../../../tmp/x therefore escapes the uploads directory, letting a client write attacker-controlled content to an arbitrary location on the server (which can escalate to RCE via a startup hook, usercustomize.py, a cron dir, etc.). The default auth dependency is a mock, so the endpoint is unauthenticated. Fixes #3104.

Fix

Add _resolve_upload_dir(base_dir, user_id) that treats user_id as a single, opaque path segment: it rejects absolute paths, multi-segment values and ./.., then canonicalizes the directory and verifies it stays inside the python_uploads root (mirroring the existing _resolve_upload_path guard). An invalid user_id now returns a clean failure instead of writing outside the root. Legitimate ids (uuid / email-like) are unaffected.

Testing

Added test_python_upload_path_traversal.py:

  • the ../../tmp/... exploit and other traversal/absolute/multi-segment ids are rejected
  • legit user_ids resolve inside the uploads root and keep their name
pytest packages/dbgpt-app/tests/openapi/test_python_upload_path_traversal.py -v

Note: this addresses the traversal. The mock auth dependency is a separate hardening concern and is out of scope for this PR.

@qfmy83 qfmy83 force-pushed the fix/issue-3104-path-traversal branch from 8cf3823 to f0ee57c Compare June 27, 2026 10:54

@Aries-ckt Aries-ckt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] [dbgpt-app] Unauthenticated path-traversal arbitrary file write via the user_id header in the python file-upload endpoint

2 participants