Skip to content

fix: fix other ICM issue and added local setup steps for mcp server - #1162

Merged
Dhruvkumar-Microsoft merged 1 commit into
devfrom
psl-devcms
Sep 25, 2026
Merged

Dhruvkumar-Microsoft merged 1 commit into
devfrom
psl-devcms

Conversation

@Dhruvkumar-Microsoft

Copy link
Copy Markdown
Contributor

Purpose

This pull request introduces important security improvements to the /api/v4/agent_message endpoint, ensuring that agent messages cannot be injected across users and that only the authenticated user can persist messages for their own plans. Additionally, it improves local development setup instructions, environment variable handling, and test coverage for these changes.

Security and Authorization Improvements:

  • The /api/v4/agent_message endpoint now requires a plan_id and verifies that the plan belongs to the authenticated user before processing messages, preventing cross-user message injection. If the plan does not exist for the user, a 404 is returned, and if plan_id is missing, a 400 is returned. (src/backend/api/router.py, src/backend/api/router.pyL896-L911)
  • The build_agent_message_from_agent_message_response function always uses the authenticated user's user_id, ignoring any user_id present in the payload, further preventing cross-user data injection. (src/backend/services/plan_service.py, src/backend/services/plan_service.pyL98-R102)

Testing Enhancements:

  • Added and updated tests to verify that unauthorized agent message writes are rejected and that the authenticated user’s user_id is always enforced. (src/tests/backend/api/test_router.py, [1]; src/tests/backend/services/test_plan_service.py, [2]

Local Development and Configuration Updates:

  • Improved local development setup documentation for the MCP server, clarifying .env file creation, Azure configuration, and local overrides. (docs/LocalDevelopmentSetup.md, [1] [2]
  • Added new environment variables to .env.example and introduced app_env to configuration, allowing for environment-specific behavior. (src/mcp_server/.env.example, [1]; src/mcp_server/config/settings.py, [2]
  • Updated credential selection logic in image_service.py to use the new app_env configuration. (src/mcp_server/services/image_service.py, src/mcp_server/services/image_service.pyL33-R35)

Does this introduce a breaking change?

  • Yes
  • No

How to Test

  • Get the code
git clone [repo-address]
cd [repo-name]
git checkout [branch-name]
npm install
  • Test the code

What to Check

Verify that the following are valid

  • ...

Other Information

@github-actions

Copy link
Copy Markdown

Coverage

Coverage Report •
FileStmtsMissCoverMissing
api
   router.py5406887%63–64, 83–84, 93–94, 98, 113, 116, 124–125, 133–134, 363–365, 375, 407–408, 426, 431–432, 434–436, 439, 451–452, 460, 535–536, 624, 626, 629, 749–754, 758, 781, 812–815, 835, 916–917, 924, 987–988, 994, 1098–1099, 1124–1126, 1504–1513
services
   plan_service.py91891%54–55, 65–67, 82, 164–165
TOTAL383755285% 

Tests Skipped Failures Errors Time
840 0 💤 0 ❌ 0 🔥 9.653s ⏱️

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The router currently raises a 500 for valid plans due to invalid session_id access, with additional contract and test-coverage issues.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

This PR hardens agent-message authorization and improves MCP server local setup and configuration.

Changes:

  • Validates plan ownership and enforces the authenticated user ID.
  • Adds authorization and identity regression tests.
  • Adds environment configuration, credential selection, and setup documentation.
  • Follow-up required for the router’s invalid Plan.session_id access, request-status mismatch, documentation, and targeted test coverage.
File Summary
src/​tests/​backend/​services/​test_plan_service.py Tests authenticated user ID enforcement.
src/​tests/​backend/​api/​test_router.py Tests authorization failures; ownership assertion should be strengthened.
src/​mcp_server/​services/​image_service.py Selects credentials by environment; branch coverage should be added.
src/​mcp_server/​config/​settings.py Adds app_env configuration.
src/​mcp_server/​.env.example Adds environment variables.
src/​backend/​services/​plan_service.py Forces authenticated user IDs.
src/​backend/​api/​router.py Adds plan validation and ownership checks; contains a critical invalid attribute access and contract/documentation mismatches.
docs/​LocalDevelopmentSetup.md Expands MCP setup instructions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/backend/api/router.py
Comment thread src/backend/api/router.py
@Dhruvkumar-Microsoft
Dhruvkumar-Microsoft merged commit 8550801 into dev Sep 25, 2026
15 checks passed
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.

3 participants