Skip to content

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

Open
hridaya423 wants to merge 2 commits into
BasedHardware:mainfrom
hridaya423:fix/twitter-tools-auth
Open

hridaya423 wants to merge 2 commits into
BasedHardware:mainfrom
hridaya423:fix/twitter-tools-auth

Conversation

@hridaya423

@hridaya423 hridaya423 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

All ten chat-tool routes in omi-twitter-chat-tools-app take uid from the JSON body and act with the stored Twitter OAuth token (get_valid_access_token(uid) / twitter_api_request(uid, ...)) with no caller authentication:

  • Write as the victim: post_tweet, like_tweet, unlike_tweet, retweet, delete_tweet
  • Read as the victim: get_timeline, get_my_tweets, get_mentions, search_tweets, get_user_profile

Anyone who knows a uid can tweet, like, retweet, or delete from the victim's connected account. Same defect class as zapier (#14428/#14429), the paid mentor fix (#13685), and the transcript-webhook fix (#14446/#14447); this app was missed by all of them and by the #13463 umbrella.

Fix

twitter_tools_auth.py, a shared-secret guard (Authorization: Bearer or twitter_tools_token query param → TWITTER_TOOLS_SECRET env, hmac.compare_digest), applied via _auth: None = Depends(require_twitter_tools_auth) to all ten routes. Caller authentication only; uid stays the body-level data-plane key, matching how the backend invokes tools. Fail-closed 503 unconfigured, 401 bad token.

Tests

test_tools_auth.py (hermetic, stdlib): 503 unconfigured, 401 missing/wrong, bearer + query token accepted. Existing test_max_results.py stub gained a Depends attribute so the app still loads hermetically.

pytest plugins/omi-twitter-chat-tools-app → 9 tests + 64 subtests pass (5 new).

Refs #14451

Failure-Class: none

All ten chat-tool routes took uid from the JSON body and acted with the
stored Twitter OAuth token — post_tweet/like/retweet/delete write as the
victim, timeline/mentions/profile read as the victim — with no caller
authentication. Same defect class as zapier (BasedHardware#14428) and the paid mentor
fix; this app was missed by both and by BasedHardware#13463.

Adds twitter_tools_auth.py (shared-secret bearer/query-token guard,
TWITTER_TOOLS_SECRET env) applied via Depends() to every tool route.
Fails closed 503 when unconfigured, 401 on missing/wrong token.

Verified: 9 tests + 64 subtests pass including 5 new guard tests;
existing test stub gained a Depends attribute.

Refs BasedHardware#14451
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @hridaya423 — this closes the uid-as-auth hole from #14451 across the whole tool surface, and the guard is a faithful replica of the pattern we merged for the mentor plugin in #13685. Verified independently:

  • twitter_tools_auth.py — hmac.compare_digest (constant-time), fails closed with 503 when TWITTER_TOOLS_SECRET is unset/blank and 401 on missing/wrong tokens; Bearer header and twitter_tools_token query param both accepted. No bypass path found.
  • main.py — all ten /tools/* routes get Depends(require_twitter_tools_auth) (post_tweet, get_timeline, get_my_tweets, get_mentions, search_tweets, like_tweet, unlike_tweet, retweet, delete_tweet, get_user_profile). Diffed against the route inventory on main: nothing in the tool surface was missed, and the OAuth/setup/health routes are untouched, matching the bounty's scope.
  • test_tools_auth.py — hermetic (stdlib-only, stubbed fastapi), covers 503/401/wrong-token/bearer/query-token; ran it standalone: 5/5 pass. test_max_results.py also still passes with the new Depends stub (4/4).

Two small asks before merge, both following the #13685 precedent:

  1. Register the new suite in .github/checks-manifest.yaml next to twitter-chat-tools-max-results-tests — that entry's trigger already fires on this directory, but its command only runs test_max_results.py, so test_tools_auth.py would never run in CI. The repo contract is that hermetic tests run in CI; fix(plugins): bind mentor transcript buffer to authenticated uid #13685 did exactly this for plugin-mentor-session-auth-tests.
  2. The commit is a fix: without a Failure-Class: trailer; the failure-class-protocol check (triggers: all) will flag it once CI runs. scripts/pr-preflight --suggest gives paste-ready guidance; a code-only fix like this can declare none. Trivial nit while you're in there: the test_tools_auth.py docstring cites C8 slice 1: route eleven settings events plus the four C7 exemplars through TypedEvents #14448, but the bounty is [Bounty $200] security: twitter-chat-tools — nine /tools/* routes trust body uid and act with the victim's Twitter token #14451.

One sequencing note for maintainers (not a change request): the guard is fail-closed by design, and the backend chat-tool caller (backend/utils/retrieval/tools/app_tools.py, _call_tool_endpoint) currently sends no secret — its auth_required branch is a no-op pass. So once this deploys, the ten twitter tools return 503 (secret unset) or 401 (secret set, caller not sending it) until the caller side lands (#14471 is the zapier-shaped equivalent, still open) and TWITTER_TOOLS_SECRET is rolled out to both sides. Taking the tool dark to close an act-as-victim hole is a defensible trade, but it's a maintainer sequencing decision — hence security-review + needs-maintainer-review. Follow-up worth its own issue, outside this bounty's scope: /disconnect?uid= and /setup/twitter?uid= still trust a bare uid (anyone can unplug a victim's connection or probe whether a uid is connected) — same class, lower severity.

AI-generated maintainer feedback posted on David's behalf.


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 18, 2026
Reviewer asks: test_tools_auth.py was not in .github/checks-manifest.yaml
(the existing max-results entry only runs test_max_results.py), and the
docstring cited BasedHardware#14448 instead of the BasedHardware#14451 bounty issue. Registers
twitter-chat-tools-auth-tests (PASS via run_checks.py --check-id) and
corrects the reference. PR body now declares Failure-Class: none.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@hridaya423

Copy link
Copy Markdown
Contributor Author

Both asks addressed:

  1. Registered twitter-chat-tools-auth-tests in .github/checks-manifest.yaml next to the max-results entry — verified run_checks.py --lane local --check-id twitter-chat-tools-auth-tests → PASS. Commit fbbd4f9894.
  2. Failure-Class: none declared in the PR body — validated locally with scripts/failure-class validate --pr-body-file → declaration accepted. Also fixed the docstring issue ref (C8 slice 1: route eleven settings events plus the four C7 exemplars through TypedEvents #14448 → [Bounty $200] security: twitter-chat-tools — nine /tools/* routes trust body uid and act with the victim's Twitter token #14451).

On the sequencing note: agreed it's a maintainer call — fail-closed mirrors the merged mentor precedent (#13685). I'll file the /disconnect + /setup/twitter bare-uid follow-up as its own issue.

@aryanorastar

Copy link
Copy Markdown
Collaborator

Verified on fbbd4f9894c3.

Leaving this open as the keep vehicle (remaining hole: twitter-chat-tools uid auth keep vs closed #14519; CONFLICTING, 0-checks). Overlap is on .github/checks-manifest.yaml, plugins/omi-twitter-chat-tools-app/main.py, plugins/omi-twitter-chat-tools-app/test_max_results.py, plugins/omi-twitter-chat-tools-app/test_tools_auth.py…. Complementary work is not a later-copy close.

Head is DIRTY / review REVIEW_REQUIRED. kodjima APPROVE is not a merge. I am not merging until this is MERGEABLE and hosted checks are green.

@aryanorastar

Copy link
Copy Markdown
Collaborator

Keeping this open. Not approving fbbd4f9894c3. twitter chat-tools auth on uid-keyed tokens; origin/main get_valid_access_token(uid) is still unauthenticated at the route. CONFLICTING DIRTY, 0 checks.

— Astar, on behalf of @aryanorastar

@Git-on-my-level

Copy link
Copy Markdown
Member

Verified against main and ran the suites locally - a solid, well-scoped fix. Thank you @hridaya423.

Per-file notes (all five changed files):

  • plugins/omi-twitter-chat-tools-app/twitter_tools_auth.py - Clean shared-secret guard: hmac.compare_digest (constant-time), fail-closed 503 when TWITTER_TOOLS_SECRET is unset or blank, 401 on missing/wrong token, and the Authorization scheme match is case-insensitive per RFC 7235. It mirrors the conventions of the existing twitter_link_auth.py (same env var, same _configured_secret() semantics), which is the right precedent in this plugin.
  • plugins/omi-twitter-chat-tools-app/main.py - All ten /tools/* routes (post_tweet, get_timeline, get_my_tweets, get_mentions, search_tweets, like_tweet, unlike_tweet, retweet, delete_tweet, get_user_profile) now carry _auth: None = Depends(require_twitter_tools_auth). I diffed the head against main and confirmed every one of the ten routes is gated and no other route or handler body was touched.
  • plugins/omi-twitter-chat-tools-app/test_tools_auth.py - Hermetic (stdlib-only fastapi stub); runs green locally, 5/5, including the fail-closed unconfigured-secret case.
  • plugins/omi-twitter-chat-tools-app/test_max_results.py - The Depends addition to the fastapi stub is the minimal change needed to keep the app importable hermetically; runs green locally, 4/4.
  • .github/checks-manifest.yaml - The new twitter-chat-tools-auth-tests entry is well-formed with correct triggers and a reason string that documents the vulnerability class for posterity.

Two notes before merge:

  1. Caller coordination: until TWITTER_TOOLS_SECRET is set in the deployment and the backend dispatcher that calls these /tools/* routes presents the bearer (or query) token, every route fails closed with 503. That is the correct default, but the env/rollout side should be wired up in the same change window so chat-tool invocations do not silently break.
  2. Rebase: main has moved under this branch in the same directory (e.g. hermetic_stubs.py landed after this branch was cut, and GitHub currently reports mergeability as UNKNOWN). Please rebase on current main before merge so the hermetic stubs and checks manifest stay consistent.

Leaving for human maintainer review: this touches an auth surface, and the deployment decision (reusing TWITTER_TOOLS_SECRET across the disconnect-link HMAC and the caller guard, plus backend token rollout) needs maintainer sign-off - that is a rollout/design question, not a code-quality concern.


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

This branch has not been deployed

No deployments
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.

3 participants