Skip to content

Fix missing conversation ownership check on SQL driver endpoints - #1442

Open
carfeii wants to merge 1 commit into
SciSharp:masterfrom
carfeii:fix/sql-driver-missing-conversation-ownership-check
Open

carfeii wants to merge 1 commit into
SciSharp:masterfrom
carfeii:fix/sql-driver-missing-conversation-ownership-check

Conversation

@carfeii

@carfeii carfeii commented Sep 16, 2026

Copy link
Copy Markdown

Fixes #1441

Summary

POST /sql-driver/{conversationId}/execute (and the sibling /sql-driver/{conversationId}/result) were gated only by [Authorize] with no check that the caller owns conversationId. Since ConversationService.SetConversationId has no ownership check either and silently creates a new conversation for an unknown id, any authenticated user could execute arbitrary SQL against any configured data source by supplying a conversation id of their own choosing.

Fix

Add the same admin-or-owner check ConversationController.GetConversation already applies when reading a conversation's own dialog (IUserService.IsAdminUser plus a ConversationFilter.UserId filter), to both ExecuteSqlQuery and AddQueryExecutionResult.

Testing

Built the actual BotSharp.Plugin.SqlDriver project against the real solution (dotnet build), confirming 0 errors. I was not able to complete a full running-server end-to-end HTTP test in the time available (the full solution build, across all plugins, is fairly heavy); the fix reuses the exact same service calls (IUserService.IsAdminUser, IConversationService.GetConversations, ConversationFilter) already exercised by the working ConversationController.GetConversation action in the same repository, so I'm confident in its correctness, but flagging this so a maintainer can do a final runtime check before merging.

POST /sql-driver/{conversationId}/execute was gated only by
[Authorize] (any logged-in user, no role check) and performed no
check that the caller owns conversationId. The underlying
ConversationService.SetConversationId call has no ownership check
either, and silently creates a new conversation using the caller's
own user id if the given id doesn't already exist, so any
authenticated user could execute an arbitrary SQL statement against
any configured data source by supplying a conversationId of their
own choosing. The sibling endpoint /sql-driver/{conversationId}/result
had the identical gap.

Add the same admin-or-owner check ConversationController.GetConversation
already applies when reading a conversation's own dialog (IUserService.
IsAdminUser plus a ConversationFilter.UserId filter), to both
ExecuteSqlQuery and AddQueryExecutionResult.
@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

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.

Missing Conversation Ownership Check on SQL Driver Endpoint Allows Any Authenticated User to Execute Arbitrary SQL

1 participant