fix: Enhance CosmosDB queries to scope results by user ID for improved data security - #1157
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Add direct coverage for the ownership predicates in the deletion query.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This pull request scopes CosmosDB plan-related queries by user ID to improve data isolation, with corresponding test updates.
Changes:
- Added user filters to plan, step, mplan, and agent-message queries.
- Restricted plan deletion by user ID and data type.
- Updated query expectations and parameters in unit tests.
File summaries
| File | Summary |
|---|---|
src/tests/backend/common/database/test_cosmosdb.py |
Updated query expectations; the deletion test needs exact query and parameter assertions, including @user_id and DataType.plan (moderate, 3 votes). |
src/backend/common/database/cosmosdb.py |
Added user-scoped CosmosDB predicates for reads and deletion. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Roopan-Microsoft
approved these changes
Sep 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
This pull request updates several database query methods in
cosmosdb.pyto ensure that all plan-related data is properly scoped to the current user. This enhances data security and isolation, preventing users from accessing or modifying data that does not belong to them. Corresponding unit tests intest_cosmosdb.pyhave also been updated to reflect these changes.Database query scoping improvements:
cosmosdb.py(get_plan_by_plan_id,get_steps_by_plan,delete_plan_by_plan_id,get_mplan, andget_agent_messages) now include auser_idfilter to ensure only data belonging to the current user is accessed or modified. [1] [2] [3] [4] [5]Test updates:
test_cosmosdb.pyhave been updated to expect the newuser_idfilter in queries and parameters, ensuring that tests accurately reflect the new scoping logic. [1] [2] [3] [4]Does this introduce a breaking change?
How to Test
What to Check
Verify that the following are valid
Other Information