Skip to content

Security hardening: token validation and service URL improvements#515

Merged
corinagum merged 13 commits into
mainfrom
cg/security
Apr 21, 2026
Merged

Security hardening: token validation and service URL improvements#515
corinagum merged 13 commits into
mainfrom
cg/security

Conversation

@corinagum

@corinagum corinagum commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Security hardening for token validation, service URL handling, and development tooling.

  • Service URL validation: Validate inbound serviceUrl against allowed hostnames from the configured cloud environment preset. Configurable via additionalAllowedDomains for non-standard channels or sovereign clouds without presets.
  • Scope validation: Use exact set membership instead of substring matching for JWT scope checks.
  • MCP tool results: Fix isCallToolResult returning incorrect results for valid tool responses.
  • DevTools: Prevent the DevTools plugin from starting in production environments.

Test plan

  • Unit tests for domain allowlist (cloud preset FQDNs, rejected domains, attacker trafficmanager, localhost, custom domains, wildcard, cross-cloud rejection, botframework.com rejected by default)
  • Unit tests for exact scope matching (substring rejected, exact match among multiple scopes)
  • Unit tests for isCallToolResult (valid results, null, primitives, unknown types)
  • Unit tests for DevTools production guard
  • E2E validated in Teams -- real Bot Framework JWT and serviceUrl pass the allowlist with no regressions
  • E2E validated DevTools blocked on NODE_ENV=production
  • E2E confirmed unauthenticated DevTools WebSocket is unreachable when guard is active

@corinagum
corinagum marked this pull request as ready for review April 14, 2026 23:35
Copilot AI review requested due to automatic review settings April 14, 2026 23:35

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Security hardening across the auth pipeline and developer tooling by tightening validation rules and preventing unsafe defaults.

Changes:

  • Added allowlist-based validation for inbound serviceUrl before it’s used in outbound calls (with customization hooks).
  • Hardened JWT validation (exact scope matching; enforce tenantId when restricting issuers).
  • Fixed MCP tool-result type guard and blocked DevTools from running in production; added unit tests.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
packages/dev/src/plugin.ts Throws early to prevent DevTools plugin use in production (NODE_ENV=production).
packages/dev/src/plugin.spec.ts Adds unit tests for the production guard behavior.
packages/apps/src/middleware/jwt-validation-middleware.ts Updates ServiceTokenValidator instantiation for new constructor parameter.
packages/apps/src/middleware/auth/service-token-validator.ts Introduces serviceUrl allowlist validation and exposes isAllowedServiceUrl.
packages/apps/src/middleware/auth/service-token-validator.spec.ts Adds extensive unit coverage for service URL allowlist behavior and new constructor signature.
packages/apps/src/middleware/auth/jwt-validator.ts Enforces tenantId when allowedTenantIds is used; switches to exact scope matching.
packages/apps/src/middleware/auth/jwt-validator.spec.ts Adds tests for new tenant/scope validation behavior.
packages/apps/src/http/http-server.ts Threads additionalAllowedDomains and validates serviceUrl even when auth is skipped.
packages/apps/src/app.ts Exposes additionalAllowedDomains at the App options level.
external/mcp/src/plugin.ts Fixes isCallToolResult guard to correctly accept valid results.
external/mcp/src/plugin.spec.ts Adds unit tests for isCallToolResult guard.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/dev/src/plugin.spec.ts Outdated
Comment thread packages/apps/src/middleware/auth/service-token-validator.ts Outdated
Comment thread packages/apps/src/middleware/jwt-validation-middleware.ts
Comment thread packages/apps/src/app.ts
Comment thread packages/apps/src/http/http-server.ts Outdated
Comment thread packages/apps/src/middleware/auth/service-token-validator.ts Outdated
Comment thread packages/apps/src/middleware/auth/service-token-validator.ts
Comment thread packages/apps/src/middleware/auth/service-token-validator.ts Outdated
Comment thread packages/apps/src/middleware/auth/service-token-validator.ts Outdated
Comment thread packages/apps/src/middleware/auth/service-token-validator.ts Outdated
heyitsaamir
heyitsaamir previously approved these changes Apr 20, 2026
Comment thread packages/apps/src/middleware/auth/service-token-validator.ts Outdated
Comment thread packages/apps/src/middleware/auth/service-token-validator.ts
@corinagum
corinagum merged commit c5eff7b into main Apr 21, 2026
7 checks passed
@corinagum
corinagum deleted the cg/security branch April 21, 2026 16:19
corinagum added a commit to microsoft/teams-sdk that referenced this pull request Apr 22, 2026
## Summary

Documentation for security hardening changes shipping in the SDK PRs:
- microsoft/teams.ts#515
- microsoft/teams.py#370
- microsoft/teams.net#418

### New page: Service URL Validation

`src/pages/templates/essentials/service-url-validation.mdx` +
per-language include files

Documents the service URL domain allowlist:
- Allowed hostnames by cloud environment preset
- How to add custom domains via `additionalAllowedDomains`
- Sovereign cloud FQDNs that require manual configuration
- How to disable validation with wildcard `*`
- Note on proactive messaging

## Test plan

- [x] Docusaurus builds without errors
- [x] New page renders correctly for all 3 languages
- [x] Admonitions render correctly
corinagum added a commit that referenced this pull request Apr 27, 2026
Follow-up to the allowlist feature (shipped via #515). No runtime
behavior change for correct callers. Adds hardening informed by review
feedback on the sibling Python PR (microsoft/teams.py#404):

1. **Docstring clarity.** `App.additionalAllowedDomains`,
`HttpServerOptions`, and `ServiceTokenValidator` constructor all
document that entries must be bare hostnames matched exactly
(case-insensitive); wildcard patterns like `*.example.com`, URL
suffixes, and full URLs are NOT supported. `['*']` is the sole wildcard,
used as a disable-validation sentinel.
2. **Defensive copy.** `HttpServer` and `ServiceTokenValidator` no
longer store the caller's array by reference. A post-construction
mutation of the caller's array would previously have changed validator
behavior at runtime; now it is isolated.
3. **Tests** covering the class of bug Python shipped in #404: plumbing
from `HttpServerOptions` through `HttpServer.initialize()` into the
`ServiceTokenValidator` constructor.

---------

Co-authored-by: Copilot <[email protected]>
corinagum added a commit that referenced this pull request Apr 28, 2026
## Summary

Reverting the serviceUrl allowlist defense-in-depth feature before
public release. Open design questions on the work item (default
sovereign cloud domains, narrowing of `*.botframework.com`, applying to
proactive `ConversationReference`s, consultation with APX) should be
resolved before this becomes part of the public API surface.

This feature has not shipped in any release. Removing the public
`additionalAllowedDomains` option is a breaking change for anyone
building from `main`, which is not ideal but acceptable since no release
has been cut. Reverting now buys time to discuss without breaking
customers later.

## Removed

- `isAllowedServiceUrl` helper
- `additionalAllowedDomains` option on `AppOptions` and
`HttpServerOptions`, plus plumbing through `App` -> `HttpServer` ->
`ServiceTokenValidator`
- `CloudEnvironment.allowedServiceUrls` field, per-cloud entries
(Public/USGov/USGovDoD/China), and `withOverrides` parameter
- Service URL hostname check in the skip-auth path of
`HttpServer.authorize`
- All allowlist tests (`additionalAllowedDomains plumbing`, cloud preset
acceptance/rejection, wildcard, defensive copy, etc.)

## Preserved (other security work bundled into PR #515)

- Scope validation (exact set membership)
- `isCallToolResult` fix in `external/mcp`

## Preserved (sovereign cloud, separate work)

`CloudEnvironment` presets, `withOverrides`, `cloudFromName`, `cloud`
option on `App`, and the `cloud` parameter on `ServiceTokenValidator`
are unchanged.

## Test plan

- [x] `npm run build` clean (full workspace)
- [x] `npm run lint` clean
- [x] `npx jest` in `packages/apps`: 19 suites, 245 tests pass
- [x] `tsc --noEmit` clean for `packages/apps` and `packages/api`
- [x] Smoke test: `examples/echo` starts and binds to port
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