Skip to content

fix(plugins): require auth on ms365 tool dispatch trusting body uid - #14686

Closed
onkar717 wants to merge 1 commit into
BasedHardware:mainfrom
onkar717:security/ms365-tools-auth
Closed

onkar717 wants to merge 1 commit into
BasedHardware:mainfrom
onkar717:security/ms365-tools-auth

Conversation

@onkar717

@onkar717 onkar717 commented Sep 19, 2026 •

Copy link
Copy Markdown

What this does

Adds a shared-secret auth guard in front of the /tools/{tool_name} dispatch route in omi-ms365-app, which previously ran Microsoft Graph tools as any uid supplied in the request body.

Vulnerability

tool_dispatch (main.py:208) reads uid from the request body (main.py:216) and runs the named tool as that user (main.py:228), with no check that the caller owns the uid. The one gate, _auth_guard (main.py:187, called at main.py:221), only calls auth.get_access_token(uid) (main.py:189): it proves the target user is connected, not that the caller is that user. Against a connected victim it always succeeds, so it is a no-op for access control.

The 16 tools reached through the single dispatch route include reads (get_me, list_recent_emails, read_email, search_files, read_file_text) and writes as the victim (send_email, send_chat_message, create_event, create_online_meeting, upload_text_file).

Same defect class as the open security filings for whoop (#14453) and the five-app group (#14455). Distinct from #14582 (reflected HTML on the setup and OAuth-error pages), which does not touch the tool routes.

Fix

New plugins/omi-ms365-app/ms365_tools_auth.py: require_ms365_tools_auth checks Authorization: Bearer or a ms365_tools_token query param against the MS365_TOOLS_SECRET env var with hmac.compare_digest, applied via Depends() in front of the dispatch route. Fail-closed 503 when unconfigured, 401 on missing or wrong token. _auth_guard is kept as the connection check.

This follows the merged mentor guard plugins/basic/mentor_webhook_auth.py (#13685), the same shared-secret shape. The whoop guard PR #14454 (issue #14453) is the open sibling in this family; it is not merged yet, and no *_tools_auth.py exists on main today.

Tests

New hermetic regression test plugins/omi-ms365-app/test_tools_auth.py (stdlib only), registered as ms365-tools-auth-tests in .github/checks-manifest.yaml. Covers the guard behaviour (503 unconfigured, 401 missing, 401 wrong, pass on Bearer, pass on query param) and asserts the dispatch route depends on the guard. 6/6 pass locally.

The existing registered check test_tool_dispatch.py broke because its hermetic fastapi stub lacked Depends, which main.py now imports; Depends was added to that stub. It passes 5/5 locally after the fix.

Accuracy note: the checks-manifest entries run the two named plugin tests, not the full suite. I did not run any test needing real fastapi/msal/httpx (no pip on this machine, Python 3.14); the change only adds a defaulted Depends parameter and the stub fix, both verified with the hermetic tests above.

Rollout note

Guard-first: until the backend caller (backend/utils/retrieval/tools/app_tools.py, _call_tool_endpoint) sends MS365_TOOLS_SECRET and the env var is deployed, every ms365 tool returns 503/401. This is the same coordination the whoop family needs; sequencing is a maintainer decision (discussion in the review thread).

Bounty

Proposing US$200, in line with the per-app security fixes proposed in this family (#14453, #14451).
PayPal: [email protected]

Fixes #14683

Failure-Class: none

Investigated and implemented with AI assistance; I verified the reproduction and the fix, and can speak to every line.

@onkar717

Copy link
Copy Markdown
Author

Thanks for reviewing. If this is accepted and merged, what is the typical timing for the bounty payout? Happy to adjust anything you need first.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @onkar717 — the vulnerability analysis is real and well done. I verified on main that tool_dispatch (plugins/omi-ms365-app/main.py:208) reads uid from the request body and _auth_guard (main.py:187) only proves the target user is connected, so all 16 Graph tools — including send_email, send_chat_message, upload_text_file — were reachable by anyone knowing a uid. The guard itself (plugins/omi-ms365-app/ms365_tools_auth.py) is solid: hmac.compare_digest, fail-closed 503 when unconfigured, 401 on a bad token, and the Depends() wiring on the dispatch route is correct. The new tests pass 6/6 and both new .github/checks-manifest.yaml entries are valid and green.

However, I'm requesting changes before this can merge, for four concrete reasons:

1. No caller can present the secret yet — every ms365 tool would fail in production. The backend's tool caller (backend/utils/retrieval/tools/app_tools.py, _call_tool_endpoint) sends only Content-Type: application/json; its auth_required branch is currently a pass placeholder. A repo-wide search finds no sender for MS365_TOOLS_SECRET (or any *_TOOLS_SECRET), and no open PR adds one. Deploying this guard as-is takes every ms365 chat tool to 503 (secret unset) or 401 (secret set, caller sends nothing), after which the backend's webhook circuit breaker disables the app. This needs a companion backend change — sent first or in a coordinated rollout. The existing auth_required flag on chat tools is a natural hook for that side.

2. The shipbob changes break the browser-called /select-channel flow. plugins/omi-shipbob-app/templates/setup.html (line 404) calls fetch('/select-channel', ...) from the user's browser after OAuth. A browser cannot hold a service shared secret, so channel selection would always 503 with no configuration fix. Your plugins/omi-shipbob-app/shipbob_tools_auth.py mirrors the ms365 guard exactly, but the whoop PR in this same family (#14454) handles its browser-called route differently — per-uid HMAC signatures (disconnect_sig/verify_disconnect_sig) — which is the shape /select-channel needs.

3. Existing tests regress (verified by running them at head vs base):

  • plugins/omi-ms365-app/test_tool_dispatch.py — registered as ms365-tool-dispatch-tests in the checks manifest — passes 5/5 on base and fails at head with an ImportError: its fastapi stub doesn't export Depends, which main.py now imports. GitHub Actions hasn't run on this PR yet (only the neutral cubic check), so CI is currently silent about this.
  • plugins/omi-shipbob-app/test_main.py goes from 66/66 on base to 4 failures here (TestCancelWroRegression13183 — direct handler calls now hit the 503 guard before the handler). Your new plugins/omi-shipbob-app/test_tools_auth.py passes 6/6; the existing suite is what breaks.

4. The PR carries a second plugin's fix undeclared, duplicating your own open PR. The title and description cover only ms365, but 4 of the 7 changed files are the complete shipbob change set — the same content as your open #14680. Please keep the shipbob work in #14680 (with a signed/session mechanism for /select-channel per point 2) and reduce this PR to the ms365 fix; the two PRs otherwise conflict on .github/checks-manifest.yaml and shipbob main.py.

One description correction for the record: this doesn't mirror a merged guard — #14453 is an open bounty issue and #14454 is an open, unmerged PR; no *_tools_auth.py or *_TOOLS_SECRET exists on main today, and there's no in-repo backend configuration sending MS365_TOOLS_SECRET. The mechanism is consistent with the open family (#14447/#14452/#14454/#14456/#14680), but none of it has a merged rollout story yet, which is exactly what point 1 needs to solve.

Suggested path forward: (a) drop the shipbob files here; (b) add Depends to the fastapi stub in test_tool_dispatch.py so the registered check stays green; (c) pair the ms365 guard with — or explicitly gate it on — the backend change that sends the secret, so the tools don't go dark on deploy. Happy to re-review once that lands.

On the bounty timing question: payout decisions and timing rest with the maintainers, so I can't promise anything from the review side.

Leaving the rollout decision (backend-first ordering, secret distribution vs. the auth_required platform hook, and how this family of guard PRs lands together) for maintainer sign-off, since it spans the plugin↔backend contract and affects every app in this fix family.

— automated review on behalf of the maintainers; human sign-off required before merge


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added security-review Touches auth, provider routing, secrets, or security-sensitive surfaces needs-maintainer-review Needs a human maintainer to sign off before merge python labels Sep 19, 2026
POST /tools/{tool_name} in omi-ms365-app reads uid from the request body and
runs the named Microsoft Graph tool as that user. The only gate, _auth_guard,
calls auth.get_access_token(uid), which proves the victim is connected but
never that the caller owns the uid. Anyone who knows a connected uid could read
that user's mail and files, send mail and Teams messages, and book meetings as
them.

Add ms365_tools_auth.py: a shared-secret guard (Authorization: Bearer or
ms365_tools_token query param, checked against MS365_TOOLS_SECRET with
hmac.compare_digest), applied via Depends() in front of the dispatch route.
Fail-closed 503 when unconfigured, 401 on missing or wrong token. _auth_guard
stays as the connection check. Mirrors the merged mentor guard
(plugins/basic/mentor_webhook_auth.py).

Register ms365-tools-auth-tests in the checks manifest. New hermetic regression
test proves the guard behaviour and that the dispatch route depends on it (red
before, green after).

Fixes BasedHardware#14683

Failure-Class: none
@onkar717
onkar717 force-pushed the security/ms365-tools-auth branch from 366dffd to c4395fe Compare September 19, 2026 14:12
@onkar717

Copy link
Copy Markdown
Author

Good catch, my error. I branched ms365 off the shipbob branch instead of main, so this PR carried the shipbob files. Rebased onto clean main; #14686 is now ms365-only (one commit). The shipbob work stays in #14680.

Fixed the test regression: added Depends to the fastapi stub in test_tool_dispatch.py, so the registered ms365-tool-dispatch-tests check imports again (5/5 locally). Corrected the PR body: this follows the merged mentor guard plugins/basic/mentor_webhook_auth.py (#13685); whoop #14454 is the open sibling, not merged, and no *_tools_auth.py is on main yet. The manifest runs only the two named plugin tests, not the full suite.

On rollout (point 1): agreed, guard-first takes the ms365 tools to 503/401 until _call_tool_endpoint sends MS365_TOOLS_SECRET and the env var is deployed. How would you like to sequence it: guard-first with the backend change staged, or backend-first? The existing auth_required flag on chat tools looks like the natural hook. Happy to follow whichever order you prefer.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Guard itself is correct, but independently verified: backend's app_tools.py caller never sends MS365_TOOLS_SECRET (auth_required branch is just 'pass'), so merging now would 503/401 every ms365 tool in production - needs a companion backend change first. Approve only, do not merge yet.

@aryanorastar

Copy link
Copy Markdown
Collaborator

Closing as a later duplicate of #14456, opened earlier for the same ms365 uid-keyed tool dispatch auth class.

Both still change plugins/omi-ms365-app/ms365_tools_auth.py. This later head is c4395fed44c4. Continue on #14456.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @onkar717 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-maintainer-review Needs a human maintainer to sign off before merge python security-review Touches auth, provider routing, secrets, or security-sensitive surfaces

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bounty $200] security: ms365: /tools dispatch trusts body uid and acts with the victim's Microsoft token

4 participants