Skip to content

fix: validate caller app on Entra inbound Agent ID tokens - #695

Open
Corina (corinagum) wants to merge 2 commits into
mainfrom
cg/entra-caller-app-validation
Open

Corina (corinagum) wants to merge 2 commits into
mainfrom
cg/entra-caller-app-validation

Conversation

@corinagum

Copy link
Copy Markdown
Collaborator

Summary

Inbound activities authenticated with an Entra (Agent ID) token are now accepted only when the token was requested by the Agent 365 platform. The caller app is read from azp, falling back to appid for v1 tokens, and compared case-insensitively. Tokens from any other client app are rejected with 401. Bot Framework tokens are unaffected.

Changes

Authentication marks Entra tokens whose caller app is not the Agent 365 platform, and BotApplication.ProcessAsync returns 401 for marked requests before reading the body. The check is scoped to the activity endpoint so tab and function endpoints protected by AddBotAuthorization() keep accepting user tokens.

Behavior change

Entra-authenticated activities sent from any app other than the Agent 365 platform (for example, a custom client or another bot calling the bot's endpoint directly with an Entra token) now receive 401.

Testing

  • Unit tests for allowed azp, allowed appid, case-insensitive match, azp precedence, disallowed azp, disallowed appid, missing caller claims, and Bot Framework tokens unaffected.
  • Verified locally end to end: an Entra token from a different app registration with the bot as audience returns 401, and the activity is not processed.

Copilot AI balanced review requested due to automatic review settings October 9, 2026 17:10
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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.

🟢 Approval recommended

The authentication behavior and tests are sound; only a minor documentation correction remains.

1 open finding
What changed in this PR

Restricts Entra-authenticated bot activities to tokens requested by Agent 365 while leaving Bot Framework and non-activity endpoints unaffected.

Changes:

  • Validates azp/appid caller claims.
  • Rejects marked activity requests with HTTP 401.
  • Adds logging and unit coverage.
File Description
src/​Microsoft.Teams.Core/​Hosting/​JwtExtensions.cs Identifies unauthorized Entra callers.
src/​Microsoft.Teams.Core/​BotApplication.cs Rejects marked requests before deserialization.
src/​Microsoft.Teams.Core/​Log.cs Adds rejection logging.
test/​Microsoft.Teams.Core.UnitTests/​Hosting/​JwtExtensionsTests.cs Tests caller-claim validation.
test/​Microsoft.Teams.Core.UnitTests/​BotApplicationTests.cs Tests early 401 behavior.

🧠 Review effort: Balanced


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

Comment thread src/Microsoft.Teams.Core/BotApplication.cs Outdated
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.

2 participants