Skip to content

🔒 Fix Unauthenticated RCE Vulnerability in execute_tool endpoint#39

Open
jakobengdahl wants to merge 1 commit into
mainfrom
fix-rce-execute-tool-vulnerability-4151204992036068489
Open

🔒 Fix Unauthenticated RCE Vulnerability in execute_tool endpoint#39
jakobengdahl wants to merge 1 commit into
mainfrom
fix-rce-execute-tool-vulnerability-4151204992036068489

Conversation

@jakobengdahl

Copy link
Copy Markdown
Owner

This PR addresses a critical security vulnerability where the /execute_tool endpoint allowed unauthenticated execution of arbitrary MCP tools, potentially leading to Remote Code Execution (RCE) or data loss.

Changes:

  1. Backend (backend/api_host/server.py):

    • Defined a SAFE_TOOLS set containing read-only tools (e.g., search_graph, get_node_details).
    • Modified execute_tool_endpoint to enforce a check: if AUTH_ENABLED is false, only tools in SAFE_TOOLS are allowed. All other tools return a 403 Forbidden.
    • If AUTH_ENABLED is true, the existing middleware handles authentication, so no additional check is needed (authenticated users are trusted).
  2. Frontend (frontend/web/src/components/ChatPanel.jsx):

    • Refactored the "Save View" functionality to use api.addNodes() (which calls the REST endpoint) instead of api.executeTool('add_nodes', ...). This ensures the frontend uses the appropriate, typed API method and avoids the new restriction on execute_tool for what is essentially a data creation operation.
  3. Tests (backend/tests/test_security_execute_tool.py):

    • Added a new test file to verify the security logic.
    • Tests cover:
      • Unauthenticated access to safe tools (Allowed).
      • Unauthenticated access to unsafe tools (Blocked 403).
      • Authenticated access to unsafe tools (Allowed).
      • Authenticated access without credentials (Blocked 401).

Impact:

  • Security: significantly improved by preventing unauthorized modification of the graph or execution of sensitive tools via the generic tool endpoint.
  • Usability: Unauthenticated users (e.g., public read-only deployments) can still use search and visualization features but cannot modify data. Local developers running without auth can still use the REST API for data modification if needed, though execute_tool is now read-only for them. This encourages enabling authentication for any write-access deployment.

PR created automatically by Jules for task 4151204992036068489 started by @jakobengdahl

- Restrict `execute_tool` to read-only operations when authentication is disabled.
- Implement `SAFE_TOOLS` whitelist in `backend/api_host/server.py`.
- Update `frontend/web/src/components/ChatPanel.jsx` to use `api.addNodes` instead of `execute_tool` for saving views, ensuring compatibility and correct API usage.
- Add comprehensive security tests in `backend/tests/test_security_execute_tool.py` covering authenticated and unauthenticated scenarios.

This change mitigates the risk of arbitrary tool execution by unauthenticated users while preserving read-only access for public instances. Write operations now require authentication or use of specific REST endpoints that are subject to their own security policies.

Co-authored-by: jakobengdahl <5815405+jakobengdahl@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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.

1 participant