Skip to content

fix(plugins): require auth on twitter-chat-tools routes acting on uid-keyed tokens (#14451) - #23706

Closed
hardik4love-lang wants to merge 4 commits into
BasedHardware:mainfrom
hardik4love-lang:fix/twitter-tools-auth-isolation-14451
Closed

hardik4love-lang wants to merge 4 commits into
BasedHardware:mainfrom
hardik4love-lang:fix/twitter-tools-auth-isolation-14451

Conversation

@hardik4love-lang

Copy link
Copy Markdown
Contributor

🎯 Summary

Fixes #14451

Failure-Class: none
UI-Evidence: none

Every chat-tool route in plugins/omi-twitter-chat-tools-app/main.py previously accepted uid in the JSON body, executed get_valid_access_token(uid) / twitter_api_request(uid, ...), and acted on that user's Twitter OAuth credentials with zero caller authentication. An unauthenticated caller could read a victim's timeline, search queries, or tweets, or perform write actions (post, like, unlike, retweet, delete) as the victim.

Changes

  • plugins/omi-twitter-chat-tools-app/twitter_tools_auth.py: Added require_twitter_tools_auth dependency validating TWITTER_TOOLS_SECRET via Authorization: Bearer <token> or ?twitter_tools_token=<token>, using constant-time hmac.compare_digest with UTF-8 byte encoding and failing closed with HTTP 503 when unconfigured.
  • plugins/omi-twitter-chat-tools-app/main.py: Added _auth: None = Depends(require_twitter_tools_auth) to all 10 chat-tool routes (post_tweet, get_timeline, get_my_tweets, get_mentions, search_tweets, like_tweet, unlike_tweet, retweet, delete_tweet, get_user_profile). Onboarding and webview routes remain open.
  • plugins/omi-twitter-chat-tools-app/hermetic_stubs.py & test_max_results.py: Updated minimal fastapi mocks with Depends and Header support so older hermetic test suites remain 100% green.
  • .github/checks-manifest.yaml: Registered twitter-chat-tools-auth-tests entry running the hermetic auth test suite.
  • Hermetic Tests: Added plugins/omi-twitter-chat-tools-app/test_tools_auth.py covering fail-closed 503, 401 on missing/invalid/malformed credentials, non-ASCII UTF-8 safety, and static wiring checks (9/9 passing).

Bounty Settlement Details

  • Bounty Reward: $200 USD
  • Designated Payout Method: PayPal ([email protected])
  • Linked Support Tickets: #146152932 / #145972803

Closes #14451

hardik4love-lang added 3 commits October 26, 2026 15:15
…-keyed tokens (BasedHardware#14451)

Failure-Class: none
UI-Evidence: none

- Add `twitter_tools_auth.py` providing `require_twitter_tools_auth` to validate incoming /tools/* requests against `TWITTER_TOOLS_SECRET` via `Authorization: Bearer` or `?twitter_tools_token=`, using constant-time `hmac.compare_digest` with UTF-8 byte encoding and failing closed with HTTP 503 when unconfigured.
- Protect all 10 chat-tool routes (`post_tweet`, `get_timeline`, `get_my_tweets`, `get_mentions`, `search_tweets`, `like_tweet`, `unlike_tweet`, `retweet`, `delete_tweet`, `get_user_profile`) with `_auth: None = Depends(require_twitter_tools_auth)`.
- Register `twitter-chat-tools-auth-tests` in `.github/checks-manifest.yaml`.
- Add hermetic test coverage in `test_tools_auth.py` (9/9 passing).

Closes BasedHardware#14451

Signed-off-by: hardik4love-lang <[email protected]>
…s auth tests

Failure-Class: none
UI-Evidence: none

Signed-off-by: hardik4love-lang <[email protected]>
Failure-Class: none
UI-Evidence: none

Signed-off-by: hardik4love-lang <[email protected]>
@Git-on-my-level

Copy link
Copy Markdown
Member

Verdict: correct, well-scoped security fix that follows the repo's established tools-auth pattern (shipbob / composio / github-app); no blocking issues — two small follow-ups below.

What I verified:

  • plugins/omi-twitter-chat-tools-app/twitter_tools_auth.py — fails closed with 503 when TWITTER_TOOLS_SECRET is unset or blank, 401 on missing/wrong/malformed credentials, constant-time hmac.compare_digest over UTF-8 bytes (non-ASCII tokens get a clean 401, not a 500).
  • plugins/omi-twitter-chat-tools-app/main.py — Depends(require_twitter_tools_auth) is wired on all ten /tools/* handlers; I checked the plugin's full route inventory and no other route acts on stored Twitter tokens (OAuth callback/setup must stay open; /disconnect was already HMAC-guarded).
  • plugins/omi-twitter-chat-tools-app/hermetic_stubs.py and test_max_results.py — the minimal fastapi stubs gain Header/Depends/status so the existing hermetic suites stay green; consistent with how the stubs are used elsewhere.
  • plugins/omi-twitter-chat-tools-app/test_tools_auth.py — covers the 503/401 paths, both credential channels, malformed Authorization headers, and statically asserts all ten handlers declare the _auth dependency.
  • .github/checks-manifest.yaml — the new twitter-chat-tools-auth-tests entry mirrors the existing manifest format exactly; the hermetic merge gate is green on this head.

Security: shared-secret caller auth matches the accepted pattern from the sibling fixes; uid-as-body-key remains by design (backend data plane). Reusing TWITTER_TOOLS_SECRET (already required by the disconnect guard) avoids a new env var, but it now serves double duty — worth a README line. Blast radius if wrong: all ten tools return 503/401, which is the intended fail-closed trade-off.

Follow-ups (non-blocking):

  • Update plugins/omi-twitter-chat-tools-app/README.md: document that /tools/* now require the shared secret (Bearer header or twitter_tools_token) and that TWITTER_TOOLS_SECRET guards both disconnect HMAC and tools auth — the README currently describes it as disconnect-only. The shipbob plugin README is the model for this.
  • Optional note: query-param tokens can appear in access logs; that's the repo-wide convention so fine to keep, but Bearer-only would be marginally cleaner long term.

Bounty settlement is handled by the maintainers through the bounty process — this review covers the code change only.

USER IMPACT: a user's connected Twitter account can no longer be read or acted on by an unauthenticated caller who knows their uid; tool behavior is otherwise unchanged once the backend presents the configured secret.

Leaving for human maintainer sign-off: a shared-secret auth change on routes that act with users' OAuth tokens deserves maintainer confirmation of the deployment wiring (secret configured, backend caller updated to present it) 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 positive-signal Automation verified a genuine fix/quality contribution python labels Oct 26, 2026
@hardik4love-lang

Copy link
Copy Markdown
Contributor Author

Hi @Git-on-my-level,

Thank you for the review! Updated \plugins/omi-twitter-chat-tools-app/README.md\ to document that all ten /tools/*\ chat-tool endpoints now require caller authentication via \TWITTER_TOOLS_SECRET\ (via \Authorization: Bearer \ or \ witter_tools_token=), and clarified that \TWITTER_TOOLS_SECRET\ guards both the disconnect link and tool execution.

Ready for maintainer sign-off and merge!

@Git-on-my-level

Copy link
Copy Markdown
Member

Verdict: this is a real security fix, correctly implemented and tested — from my review it is merge-ready pending a maintainer sign-off on the auth model (details below).

What I verified on head 37749f8:

  • twitter_tools_auth.py — require_twitter_tools_auth fails closed with 503 when TWITTER_TOOLS_SECRET is unset/blank, returns 401 (with WWW-Authenticate) on missing, malformed, or wrong credentials, and compares via hmac.compare_digest on UTF-8 bytes, so a non-ASCII token yields 401 rather than a TypeError 500. Bearer scheme matching is case-insensitive.
  • main.py — exactly the ten /tools/* handlers (post_tweet, get_timeline, get_my_tweets, get_mentions, search_tweets, like_tweet, unlike_tweet, retweet, delete_tweet, get_user_profile) now declare _auth: None = Depends(require_twitter_tools_auth); the onboarding routes (/auth/twitter, callback, /setup), /disconnect (still guarded by require_signed_link), /health, and the manifest are intentionally unchanged. No other behavior changes in this file.
  • test_tools_auth.py — 9 hermetic tests covering fail-closed 503, all 401 paths, non-ASCII safety, and static wiring checks over all ten handlers. I ran it and the updated test_max_results.py (4 tests) in an isolated, network-disabled container: both suites pass.
  • hermetic_stubs.py / test_max_results.py — stub-only additions (Header, Depends, status) so the hermetic environment matches the new imports; no production impact.
  • .github/checks-manifest.yaml — registers twitter-chat-tools-auth-tests with the same trigger/lane pattern as the sibling entries; command matches the new test file.
  • README.md — accurately documents 401 vs 503 and both credential channels.

Security: this closes an unauthenticated-access hole where any caller could act on a victim's Twitter OAuth token (read timeline/mentions, post, like, retweet, delete). Two design notes for a maintainer before merge: (1) TWITTER_TOOLS_SECRET is a single shared secret across all users and the uid remains caller-chosen, so any secret holder can act as any uid — fine if this service is only reachable by the trusted Omi backend, worth confirming the deployment story; (2) the ?twitter_tools_token= query channel can leak the secret into access logs — the Bearer header should be the preferred mechanism going forward.
UX/rollout: deployments that previously ran without TWITTER_TOOLS_SECRET will now get 503 on all tool routes until it is configured — intended fail-closed behavior and documented in the README; worth a release/upgrade note for anyone self-hosting this plugin.
Blast radius: confined to plugins/omi-twitter-chat-tools-app plus its check registration.

USER IMPACT: none for end users — Twitter chat tools keep working unchanged; self-hosters of this plugin must set TWITTER_TOOLS_SECRET or tool calls will now (correctly) fail closed.

Remaining asks (non-blocking): maintainer confirmation of the shared-secret trust model; consider deprecating the query-param channel in favor of the Bearer header; the bounty settlement details in the PR description need maintainer/ops verification outside this code review.

Leaving for human maintainer review: security-sensitive auth change on a plugin that handles user Twitter OAuth tokens — the shared-secret model and merge decision need maintainer sign-off. (AI-generated maintainer feedback on behalf of the Omi maintainers.)


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 the needs-maintainer-review Needs a human maintainer to sign off before merge label Oct 27, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Verdict: the production change is correct and well scoped — this properly closes the unauthorized-use hole from #14451; leaving security sign-off to a human maintainer.

Per-file findings (all seven changed files reviewed):

  • plugins/omi-twitter-chat-tools-app/twitter_tools_auth.py — guard logic is correct: a malformed Authorization header returns 401 without falling through to the query param, comparison uses hmac.compare_digest on UTF-8 bytes, and an unset/blank TWITTER_TOOLS_SECRET fails closed with 503 before any credential check.
  • plugins/omi-twitter-chat-tools-app/main.py — all ten /tools/* handlers (post_tweet, get_timeline, get_my_tweets, get_mentions, search_tweets, like_tweet, unlike_tweet, retweet, delete_tweet, get_user_profile) now declare _auth via Depends(require_twitter_tools_auth); no /tools/* route remains unguarded. The OAuth, webview, and onboarding routes and the already HMAC-guarded /disconnect are intentionally unchanged — correct, since those operate on the caller's own session rather than a client-supplied uid.
  • plugins/omi-twitter-chat-tools-app/test_tools_auth.py — 9/9 pass (suite run in an isolated container): fail-closed 503, 401 on missing/wrong/malformed credentials, non-ASCII header safety, and signature-level wiring checks across all ten handlers.
  • plugins/omi-twitter-chat-tools-app/hermetic_stubs.py and test_max_results.py — Header/Depends/status stub additions keep the older hermetic suites green (4/4).
  • .github/checks-manifest.yaml — twitter-chat-tools-auth-tests registered with the right triggers for the plugin path.
  • plugins/omi-twitter-chat-tools-app/README.md — accurately documents both credential channels and the 401/503 behavior.

Non-blocking notes for the maintainer:

  • Rollout coupling: nothing else in the repo sends this secret, so the invoking chat-tool client must present TWITTER_TOOLS_SECRET at deploy time or every twitter tool call will return 401 (503 if the env is unset). Fail-closed is the right default, but merge should be coordinated with the caller and deployment config.
  • The query-param channel (twitter_tools_token=...) exposes the shared secret in access logs; it mirrors the existing /disconnect HMAC-in-query pattern so it is consistent, but header-only would be tighter if the caller can be taught.
  • Sibling chat-tools plugins (omi-whoop-app, omi-notion-app, omi-google-calendar-app, omi-linear-app) carry the same body-uid trust pattern; worth a tracking issue to replicate this fix.

Security: closes a genuine unauthenticated read/write-as-victim vulnerability. Blast radius if wrong: all twitter chat tools — mitigated by fail-closed behavior and green hermetic tests. Performance/cost: negligible (one env read plus a constant-time compare per request).
USER IMPACT: none until deployed; once live, twitter chat tools only answer callers presenting the configured secret, blocking anyone who was using them without authorization.

Still wanted before merge: an end-to-end check against the real invoking client with the secret configured, since the hermetic suite cannot cover the platform side.

Leaving for human maintainer review: security-sensitive auth change on a surface that acts with users' Twitter OAuth tokens needs maintainer sign-off.


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

@hardik4love-lang

Copy link
Copy Markdown
Contributor Author

Hi @Git-on-my-level @kodjima33
eed human response: Auth guard wired across all 10 tools, hermetic tests 9/9 passing green, verified fail-closed behavior. Ready for maintainer merge sign-off!

@aryanorastar

Copy link
Copy Markdown
Collaborator

Closing #23706 at 37749f8a41f7f985327312b89f8bd6d0de8e67be as a later copy of #14452, which remains the open vehicle for the same change. Not merged.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @hardik4love-lang 👋

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 positive-signal Automation verified a genuine fix/quality contribution 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: twitter-chat-tools — nine /tools/* routes trust body uid and act with the victim's Twitter token

3 participants