Skip to content

Security hardening: token validation and service URL improvements#370

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

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

Conversation

@corinagum

@corinagum corinagum commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

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 additional_allowed_domains for non-standard channels or sovereign clouds without presets.
  • Scope validation: Use exact set membership instead of substring matching for JWT scope checks.
  • Issuer validation: Log a warning when Entra token validation is configured without a tenant ID, making the silent issuer validation skip visible.
  • 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, botframework.com rejected by default)
  • Unit tests for exact scope matching
  • Unit test for issuer validation warning
  • Unit tests for DevTools production guard
  • E2E validated in Teams -- no regressions
  • E2E validated DevTools blocked on PYTHON_ENV=production

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

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 for token validation and inbound serviceUrl handling, plus preventing DevTools from running in production.

Changes:

  • Added serviceUrl domain allowlist validation (with additional_allowed_domains) and strengthened JWT scope checks to exact set membership.
  • Added issuer-validation warning when Entra validation is configured without a tenant ID.
  • Added a production-environment guard to prevent the DevTools plugin from starting, with accompanying unit tests.

Reviewed changes

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

Show a summary per file
File Description
packages/devtools/src/microsoft_teams/devtools/devtools_plugin.py Blocks DevTools plugin initialization when environment indicates production.
packages/devtools/tests/test_devtools_plugin.py Adds tests for DevTools production guard and basic plugin initialization behavior.
packages/apps/src/microsoft_teams/apps/auth/token_validator.py Adds service URL allowlist logic, warning for missing tenant ID, and exact scope matching.
packages/apps/src/microsoft_teams/apps/http/http_server.py Adds serviceUrl allowlist validation and plumbs additional_allowed_domains into server init.
packages/apps/src/microsoft_teams/apps/options.py Adds additional_allowed_domains to app options/internal options.
packages/apps/src/microsoft_teams/apps/app.py Passes additional_allowed_domains from app options into server initialization.
packages/apps/tests/test_token_validator.py Adds unit tests for domain allowlist, exact scope matching, and issuer warning.
packages/apps/tests/test_http_server.py Adds unit tests for idempotent initialize, endpoint validation, auth rejection, and serviceUrl allowlist behavior.
packages/apps/tests/test_app.py Adds unit test for merging app options with defaults.
examples/cards/src/main.py Formatting-only change (single-line method chaining).

Comment thread packages/devtools/src/microsoft_teams/devtools/devtools_plugin.py Outdated
Comment thread packages/apps/src/microsoft_teams/apps/auth/token_validator.py Outdated
Comment thread packages/apps/src/microsoft_teams/apps/http/http_server.py
Comment thread packages/apps/src/microsoft_teams/apps/auth/token_validator.py Outdated
Comment thread packages/apps/src/microsoft_teams/apps/auth/token_validator.py Outdated
Comment thread packages/apps/src/microsoft_teams/apps/auth/token_validator.py
Comment thread packages/apps/src/microsoft_teams/apps/auth/token_validator.py
@corinagum
corinagum merged commit f84ccfd into main Apr 21, 2026
7 checks passed
@corinagum
corinagum deleted the cg/security branch April 21, 2026 16:18
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 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
`additional_allowed_domains` 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

- `is_allowed_service_url` helper
- `additional_allowed_domains` option on
`AppOptions`/`InternalAppOptions`, plus plumbing through `App` ->
`HttpServer` -> `TokenValidator` (`for_service`, `for_entra`,
`validate_token`)
- `CloudEnvironment.allowed_service_urls` field and per-cloud entries
(PUBLIC/US_GOV/US_GOV_DOD/CHINA)
- Service URL hostname check in `HttpServer.handle_request`
- All allowlist tests in `test_token_validator.py` and
`test_http_server.py`

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

- Scope validation (exact set membership)
- Issuer validation logging when `tenant_id` is missing in `for_entra`

## Preserved (sovereign cloud, separate work)

`CloudEnvironment` presets, `with_overrides`, `from_name`, `cloud`
option on `App`, and the `cloud` parameter on `TokenValidator` factories
are unchanged.

## Test plan

- [x] `uv run ruff check` clean (full repo)
- [x] `uv run pyright` clean (full repo, 0 errors / 0 warnings)
- [x] `uv run pytest packages/apps/tests/`: 246 tests pass
- [x] Smoke test: `examples/echo` starts and uvicorn binds to port

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.

4 participants