The vulnerability is an Insecure Direct Object Reference (IDOR) in the API key deletion mechanism of Langflow. The root cause is the delete_api_key function in src/backend/base/langflow/services/database/models/api_key/crud.py, which deleted API keys based solely on their ID (api_key_id) without verifying that the key belonged to the user making the request.
This vulnerability was exposed through the delete_api_key_route API endpoint in src/backend/base/langflow/api/v1/api_key.py. Although this endpoint required user authentication, it did not use the authenticated user's identity to authorize the deletion. It simply passed the api_key_id to the insecure delete_api_key function.
As a result, any authenticated user could send a DELETE request to the /api/v1/api_key/{api_key_id} endpoint with a valid API key ID belonging to any other user, and the system would delete it.
The patch addresses this by:
- Modifying the
delete_api_key function to accept a user_id and adding a check to ensure api_key.user_id matches the provided user_id before deletion.
- Updating the
delete_api_key_route endpoint to retrieve the current_user and pass current_user.id to the delete_api_key function, thereby correctly enforcing ownership.
- Updating another call site in
langflow.__main__.py within the aapi_key function to also pass the user ID.
The identified vulnerable functions are delete_api_key (the core of the vulnerability) and delete_api_key_route (the exposed API endpoint that triggers it). aapi_key is also included as it was another call site for the vulnerable function. During an exploit, a profiler would likely show delete_api_key_route being called, which in turn calls delete_api_key.