Validate serviceurl claim matches activity ServiceUrl#545
Conversation
Add validation to ensure the "serviceurl" claim in user claims matches the activity's ServiceUrl (case-insensitive) in BotApplication. Throw InvalidDataException on mismatch. Add unit tests covering matching, case-insensitivity, mismatches, and absence of the claim.
There was a problem hiding this comment.
Pull request overview
Adds a security validation in BotApplication.ProcessAsync to ensure the authenticated user’s serviceurl claim matches the incoming activity’s ServiceUrl (case-insensitive), and expands unit test coverage to verify expected behavior for matching, case-only differences, mismatches, and missing claim scenarios.
Changes:
- Add
serviceurl-vs-activityServiceUrlvalidation toBotApplication.ProcessAsync, throwingInvalidDataExceptionon mismatch. - Add unit tests covering match, case-insensitive match, mismatch, and missing-claim behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| core/src/Microsoft.Teams.Core/BotApplication.cs | Adds serviceurl claim validation in the incoming activity processing path. |
| core/test/Microsoft.Teams.Core.UnitTests/BotApplicationTests.cs | Adds unit tests to validate the new claim/ServiceUrl matching behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Record activity types and start spans for each turn, tagging spans with activity details (type, ID, conversation ID, channel ID, bot ID, service URL) to improve observability and diagnostics.
heyitsaamir
left a comment
There was a problem hiding this comment.
It'd be good to double check if this logic works in various settings:
- 1:1
- Group Chats
- Channels
- Threads
Changed service URL validation to use StringComparison.Ordinal for a case-sensitive match instead of OrdinalIgnoreCase. This affects how the service URL in the activity is compared to the service URL claim.
Add logging for ServiceUrl mismatches using LogServiceUrlClaimMismatch. Update the exception message for clarity. Refactor test to set Conversation property inline during activity initialization.
how so? this is only about claims and serviceUrls, it should not affect any other fields in the payload (and yes, tested without any issue) |
Add validation to ensure the "serviceurl" claim in user claims matches the activity's ServiceUrl (case-insensitive) in BotApplication. Throw InvalidDataException on mismatch. Add unit tests covering matching, case-insensitivity, mismatches, and absence of the claim.