[PR #25377] fix: tenant_id was not specific when retrieval end-user in plugin backwards invocation wraps #31040

Closed
opened 2026-02-21 20:48:43 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/25377

State: closed
Merged: Yes


Fixes #25378

Summary

This PR fixes a critical security vulnerability in the plugin backwards invocation API that could potentially allow cross-tenant data access.

Security Issue Fixed

The get_user function in api/controllers/inner_api/plugin/wraps.py was not properly enforcing tenant isolation when retrieving end users. The function was:

  1. Attempting to fetch Account objects using untrusted user_id input
  2. Not validating tenant_id when querying EndUser objects
  3. Potentially allowing access to users from different tenants

Changes Made

  1. Removed Account retrieval: The function now only works with EndUser objects, treating all user_id inputs as session IDs
  2. Added tenant_id validation: All EndUser queries now include tenant_id in the WHERE clause to ensure proper tenant isolation
  3. Improved documentation: Added clear comments explaining that user_id is untrusted input
  4. Centralized constant: Created DEFAULT_SERVICE_API_USER_ID constant in core/file/constants.py to replace hardcoded "DEFAULT-USER" strings

Impact

  • Ensures strict tenant isolation in multi-tenant deployments
  • Prevents potential cross-tenant data access
  • Improves code clarity and maintainability

Screenshots

N/A - Security fix with no UI changes

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/25377 **State:** closed **Merged:** Yes --- Fixes #25378 ## Summary This PR fixes a critical security vulnerability in the plugin backwards invocation API that could potentially allow cross-tenant data access. ### Security Issue Fixed The `get_user` function in `api/controllers/inner_api/plugin/wraps.py` was not properly enforcing tenant isolation when retrieving end users. The function was: 1. Attempting to fetch Account objects using untrusted user_id input 2. Not validating tenant_id when querying EndUser objects 3. Potentially allowing access to users from different tenants ### Changes Made 1. **Removed Account retrieval**: The function now only works with EndUser objects, treating all user_id inputs as session IDs 2. **Added tenant_id validation**: All EndUser queries now include tenant_id in the WHERE clause to ensure proper tenant isolation 3. **Improved documentation**: Added clear comments explaining that user_id is untrusted input 4. **Centralized constant**: Created `DEFAULT_SERVICE_API_USER_ID` constant in `core/file/constants.py` to replace hardcoded "DEFAULT-USER" strings ### Impact - Ensures strict tenant isolation in multi-tenant deployments - Prevents potential cross-tenant data access - Improves code clarity and maintainability ## Screenshots N/A - Security fix with no UI changes ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:48:43 -05:00
yindo closed this issue 2026-02-21 20:48:43 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#31040