Skip to content

fix(plugins): require a signed uid before Twitter disconnect - #18482

Merged
kodjima33 merged 4 commits into
BasedHardware:mainfrom
aryanorastar:fix/14505-twitter-signed-disconnect
Sep 25, 2026
Merged

kodjima33 merged 4 commits into
BasedHardware:mainfrom
aryanorastar:fix/14505-twitter-signed-disconnect

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • GET /disconnect on the Twitter chat-tools app deleted stored tokens for any uid in the query string.
  • The settings page now puts an HMAC of that uid on the link, and the handler checks it before deleting. Missing secret is 503. Missing or wrong signature is 401, and the tokens stay.

Failure-Class: new

Test plan

  • python3 plugins/omi-twitter-chat-tools-app/test_twitter_link_auth.py (5 tests: unconfigured, bad signature, matching signature, per-uid, delete not called until the signature matches)
  • Not run against a live Twitter account. GET /setup/twitter?uid= is still the platform setup probe (apps.py appends ?uid=), so this change does not lock that route.

Fixes #14505

Review in cubic

aryanorastar and others added 2 commits September 24, 2026 12:50
GET /disconnect deleted stored tokens for any uid in the query string. The settings link now carries an HMAC and the handler rejects a missing or wrong signature.

Co-authored-by: Cursor <[email protected]>

@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 @aryanorastar — this closes a real hole: GET /disconnect previously deleted any user's Twitter tokens from a bare uid, and the signed-link fix matches the pattern already used elsewhere (whoop app, #14454).

Verified per file:

  • plugins/omi-twitter-chat-tools-app/twitter_link_auth.py — correct construction: stripped-secret lookup, HMAC-SHA256 over the uid, hmac.compare_digest with an explicit length pre-check, fail-closed 503 when TWITTER_TOOLS_SECRET is unset and 401 on missing/wrong sig. I exercised the module directly: empty, wrong, truncated, and cross-uid signatures all raise 401; a valid signature passes; the unset secret raises 503.
  • plugins/omi-twitter-chat-tools-app/main.py — the settings page now emits /disconnect?uid=<quoted>&sig=<hmac> (line 1055) and the handler calls require_signed_link(uid, sig) before delete_twitter_tokens (lines 1273–1280); the redirect now URL-encodes the uid. Good.
  • plugins/omi-twitter-chat-tools-app/test_twitter_link_auth.py — the strongest test is the handler-level one: it patches delete_twitter_tokens and proves it is not called until the signature matches. That is exactly the pin this bug class needed.
  • .github/checks-manifest.yaml and .github/failure-classes/FC-unsigned-disconnect-deletes-tokens.json — the failure-class write-up is accurate and the pinned check is the right idea.
  • plugins/omi-twitter-chat-tools-app/README.md — the TWITTER_TOOLS_SECRET row is accurate (required; unset fails closed).

One blocking issue — the new check fails in CI as authored. Hygiene fails because twitter-chat-tools-disconnect-auth-tests hits ModuleNotFoundError: No module named 'fastapi' at test_twitter_link_auth.py:12: the ci lane runs a bare python3, and the sibling check in the same lane (test_max_results.py) only passes because it stubs its imports via importlib/ModuleType instead of importing the app's real deps. As written, this PR ships a red required check and the advertised hermetic pin never actually runs in CI. Please make the check lane-hermetic the same way (stub fastapi.HTTPException, or otherwise avoid the hard fastapi import) and push. For clarity, the other Hygiene annotations (main.py at 1399 lines, the 188-line get_omi_tools_manifest) are pre-existing on main and not caused by this diff.

Two residual points I'm flagging for maintainers rather than blocking on: deployments that haven't provisioned TWITTER_TOOLS_SECRET will fail closed on disconnect (503) after this merges — worth a deploy note; and GET /setup/twitter?uid= still trusts a bare uid, which issue #14505 also names and the PR description consciously leaves alone.

Requesting changes solely for the CI check. The auth logic itself is sound. Security sign-off on the deployment semantics of the new required secret is left for maintainer review.


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 workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior python labels Sep 24, 2026

@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.

Auth logic is sound (Git-on-my-level verified the HMAC signing/verification directly) and closes a real hole (bare-uid Twitter disconnect). Holding at approve, not merging: independently confirmed the CI-blocking defect Git-on-my-level flagged is still present at head 230a225 -- test_twitter_link_auth.py:12 does 'from fastapi import HTTPException', which will ModuleNotFoundError in the hermetic ci lane the same way the sibling test_max_results.py avoids by stubbing. The advertised pinned check does not actually run.

aryanorastar and others added 2 commits September 25, 2026 10:24
twitter-chat-tools-disconnect-auth-tests failed in Hygiene with

  ModuleNotFoundError: No module named 'fastapi'
  test_twitter_link_auth.py:12

That lane runs a bare python3 with only pyyaml installed, so the required check
was red and the hermetic pin it advertises never actually ran. It passed locally
only because a developer machine has fastapi installed.

Two import sites needed covering, not one: the test's own `from fastapi import
HTTPException`, and the same import at module scope in twitter_link_auth.py.
The handler-level test additionally imports main.py, which pulls fastapi,
fastapi.responses, dotenv, requests, db and models.

New plugins/omi-twitter-chat-tools-app/hermetic_stubs.py holds the stubs:

- ensure_fastapi() registers a minimal fastapi when it is absent, so modules
  doing `from fastapi import HTTPException` load.
- http_exception() returns the real HTTPException when installed and a stub
  carrying status_code/detail otherwise, which is what the assertions read.
- load_main() imports main.py against stubs *always*, not only when fastapi is
  missing: a real fastapi validates response models against the stubbed
  models.ChatToolResponse and rejects it, so stubbing one side only moves the
  failure rather than removing it.

The response stubs are classes rather than str/dict because the disconnect path
constructs RedirectResponse(url=...).

Verified 5 passed in both environments -- with fastapi installed, and with
fastapi, dotenv and requests all hidden to reproduce the lane. Mutation-checked
that the security pin still bites: stubbing out the require_signed_link call in
main.py fails the suite in both environments, and main.py is unchanged.

Co-Authored-By: Claude Opus 5 <[email protected]>
@aryanorastar

Copy link
Copy Markdown
Collaborator Author

Blocking CI item fixed on f9c3f59084, plus a merge of current main (66 commits, no conflicts).

You were right that the check shipped red and the advertised pin never ran. Two import sites needed covering, not one — the test's own from fastapi import HTTPException and the same import at module scope in twitter_link_auth.py. The handler-level test also imports main.py, which pulls fastapi, fastapi.responses, dotenv, requests, db and models.

New plugins/omi-twitter-chat-tools-app/hermetic_stubs.py:

  • ensure_fastapi() registers a minimal fastapi when absent, so module-scope from fastapi import … loads.
  • http_exception() returns the real HTTPException when installed, else a stub carrying status_code/detail — the attributes the assertions read.
  • load_main() imports main.py against stubs always, not only when fastapi is missing. That was the non-obvious part: with a real fastapi present, it validates response models against the stubbed models.ChatToolResponse and raises FastAPIError: Invalid args for response field. Stubbing one side only moved the failure. The response stubs are classes rather than str/dict because the disconnect path builds RedirectResponse(url=…).

I put this in its own helper rather than inlining a second copy of the block in test_max_results.py. That sibling is untouched and still passes; whoever migrates it next can reuse the helper.

Verified

environment result
fastapi installed 5 passed
fastapi, dotenv, requests all hidden (reproduces the lane) 5 passed
test_max_results.py (untouched sibling) OK
.github/scripts/test_run_checks.py 56 passed, 10 subtests

The pin was mutation-checked so the hermeticity work cannot have hollowed it out: stubbing out the require_signed_link(uid, sig) call in main.py fails the suite in both environments, and main.py is byte-identical afterwards.

Diff is 7 files, plugins/ and .github/ only.

Your two non-blocking points are untouched and still maintainer calls: the TWITTER_TOOLS_SECRET deploy note for environments that have not provisioned it, and GET /setup/twitter?uid= still trusting a bare uid (#14505 names it; this PR leaves it alone by design).

@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.

Trusted contributor; real auth bug (fixes #14505), tests added, CI currently green.

@kodjima33
kodjima33 merged commit 065d496 into BasedHardware:main Sep 25, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python security-review Touches auth, provider routing, secrets, or security-sensitive surfaces workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

omi-twitter-chat-tools-app: /disconnect and /setup/twitter trust bare uid

3 participants