Skip to content

Fix critical security issues: RCE via /tools/call, missing auth, path traversal#5485

Open
NullLabTests wants to merge 1 commit into
chatchat-space:masterfrom
NullLabTests:fix/security-rce-tools-call
Open

Fix critical security issues: RCE via /tools/call, missing auth, path traversal#5485
NullLabTests wants to merge 1 commit into
chatchat-space:masterfrom
NullLabTests:fix/security-rce-tools-call

Conversation

@NullLabTests

Copy link
Copy Markdown

Summary

Fixes #5475 (RCE via shell tool) and #5474 (path traversal + missing auth).

Fix 1 — RCE via shell tool (Critical, #5475)

The shell tool was auto-registered from langchain_community.tools.ShellTool and callable by any unauthenticated attacker through POST /tools/call with {"name": "shell", "tool_input": {"query": "id"}}.

Change: Commented out the shell import in tools_factory/__init__.py. The shell tool is no longer registered by default. Users who explicitly need it can uncomment the import.

Fix 2 — Missing API authentication (High, #5474)

All API endpoints, including /tools/*, had zero authentication.

Change: Added CHATCHAT_API_KEY environment variable support to tool_routes.py. When set, all /tools/* endpoints require Authorization: Bearer <CHATCHAT_API_KEY>. Fully backward compatible — no auth is required when the env var is unset.

Fix 3 — Path traversal in validate_kb_name (High, #5474)

The validate_kb_name() function only checked for literal "../", which is trivially bypassed with URL encoding (..%2f), absolute paths (/etc/passwd), or normalized traversal.

Change: Now rejects:

  • ../ and ..\\ traversal sequences
  • Absolute paths (via os.path.isabs)
  • Normalized path traversal (via os.path.normpath + startswith(".."))
  • Empty knowledge base names

Files changed: 3 files +17/-5

Fix 1 — RCE via shell tool (Critical):
  Disable the shell tool from default registration. The shell tool
  (langchain_community.tools.ShellTool) allowed arbitrary OS command
  execution through the unauthenticated POST /tools/call endpoint.

Fix 2 — Missing API authentication (High):
  Add CHATCHAT_API_KEY environment variable support to the /tools/*
  routes. When set, all tool endpoints require Authorization: Bearer
  <key>. Backward compatible: no auth required when key is unset.

Fix 3 — Path traversal in validate_kb_name (High):
  Hardened validate_kb_name() to reject ..%2f (URL-encoded), absolute
  paths, and normalized .. traversal, preventing arbitrary file
  read/write through knowledge base endpoints.

Closes chatchat-space#5475, chatchat-space#5474
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] RCE/shell tool exposed without auth

1 participant