Skip to content

security: P0 uid-as-auth + ADMIN_KEY default-off - #13463

Draft
undivisible wants to merge 5 commits into
mainfrom
security/p0-uid-auth-admin-key-default
Draft

undivisible wants to merge 5 commits into
mainfrom
security/p0-uid-auth-admin-key-default

Conversation

@undivisible

@undivisible undivisible commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Draft fix for the two omi P0s from the 2026-09-11 Grok audit (.grok-audits/grok-audit-omi-20260911.md on the auditor checkout). Based on current origin/main (worktree /Users/undivisible/projects/omi-sec-p0).

P0-2 — ADMIN_KEY_AUTH_ENABLED fail-closed

  • verify_token now defaults ADMIN_KEY_AUTH_ENABLED to off (false).
  • Feature retained: set ADMIN_KEY_AUTH_ENABLED=true intentionally for local/dev/CI/break-glass that need Authorization: Bearer <ADMIN_KEY><uid>.
  • Admin router auth via secret-key: ADMIN_KEY is unchanged (separate path).
  • Prod overlays leave the flag unset → stay fail-closed.
  • First-party harnesses (listen_pusher_stack, sync_cloud_tasks_stack, replay_harness_phase0a) set the flag explicitly.

P0-1 — Plugin fleet uid-as-auth (shared pattern)

  • Restored omi_plugin_sdk.auth HMAC helpers (X-Omi-Uid / X-Omi-Timestamp / X-Omi-Signature).
  • Backend signs outbound plugin webhooks/tools/setup_completed checks when OMI_PLUGIN_WEBHOOK_SECRET is set (backend/utils/plugin_auth.py mirrors the SDK algorithm).
  • Wired reject-bare-uid on high-risk surfaces:
    • GitHub: mutations (/save-agent-key JSON body only, no key-in-query), tools, etc.
    • Dropbox: disconnect / settings / conversation webhook; opaque OAuth state→uid map
    • hey_omi: inbound webhook requires Authorization: Bearer <HEY_OMI_APP_SECRET>
    • Legacy Notion OAuth: HMAC-signed state (not bare uid)

How to enable ADMIN_KEY impersonation intentionally

# backend/.env (local/dev/CI/break-glass only)
ADMIN_KEY=<long-random-secret>
ADMIN_KEY_AUTH_ENABLED=true

Do not set ADMIN_KEY_AUTH_ENABLED=true in prod overlays unless you have a dedicated break-glass plan.

How to enable plugin HMAC

# Same value on API + plugin services that enforce auth
OMI_PLUGIN_WEBHOOK_SECRET=<long-random-secret>

Until this secret is deployed to both backend and enforcing plugins, signed delivery is optional on the backend (warns once if unset) and enforcing plugin endpoints return 401 on bare uid (fail-closed).

Residual risk / follow-ups (out of scope for this PR)

  • Product call required: Omi must pass a signed uid / auth headers when opening plugin app_home_url / OAuth start (?uid= alone is still forgeable for setup/OAuth-start binding). TODOs left in GitHub/Dropbox setup + auth-start handlers.
  • Remaining omi-*-app fleet (Notion app, Slack, Whoop, Shopify, …) not mass-migrated — SDK is ready; migrate per app.
  • P1s deferred: developer webhook SSRF, Firestore plaintext integration tokens, macOS BYOK Keychain, BLE GATT encrypt, platform-integration issues.

Test plan

  • plugins/omi-plugin-sdk/tests/test_auth.py (8 passed)
  • backend/tests/unit/test_plugin_auth.py + test_verify_token_admin_and_local_dev_gating.py (14 passed)
  • Deploy OMI_PLUGIN_WEBHOOK_SECRET to backend + GitHub/Dropbox plugins before relying on 401 enforcement in prod
  • Confirm web admin / desktop release workflows that use secret-key: ADMIN_KEY still work (impersonation flag does not gate them)
  • Do not admin-merge until product signs setup URLs or accepts temporary setup-UI breakage (GitHub/Dropbox browser mutations now need HMAC)

Review in cubic

Line-Count-Exception: backend/testing/listen_pusher_stack/run.py | 1843 -> 1844 | ADMIN_KEY_AUTH_ENABLED=true harness env line required so the hermetic listen/pusher stack keeps impersonation auth under the new fail-closed default

Failure-Class: FC-fixture-mock-signature-drift

P0-2 from the 2026-09-11 Grok audit: ADMIN_KEY impersonation
(Bearer <ADMIN_KEY><uid>) now requires an intentional opt-in.
Prod overlays leave the flag unset so they stay fail-closed.
First-party test stacks that rely on impersonation set the
flag explicitly. Admin router secret-key auth is unchanged.
P0-1 from the 2026-09-11 Grok audit: restore omi_plugin_sdk.auth
HMAC helpers, sign backend→plugin webhooks/tools when
OMI_PLUGIN_WEBHOOK_SECRET is set, and reject uid-only auth on
GitHub mutations/tools, Dropbox disconnect/settings/webhook,
hey_omi inbound webhook, and legacy Notion OAuth state.
Setup/OAuth-start identity still needs a product-signed uid.

@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 @undivisible — the direction here is right and the substance is strong: fail-closed ADMIN_KEY_AUTH_ENABLED, shared HMAC identity for the plugin fleet, opaque OAuth state, and key-out-of-query-string are all real improvements. I did a full pass over the diff plus triage of the four failing checks; root causes below so you don't have to dig.

Blocking (CI — all small fixes)

  1. Hermetic Backend E2E: 99 failures, one root cause. The account_deletion_identity fixture in backend/testing/e2e/test_account_deletion_cloud_tasks.py sets ADMIN_KEY and authenticates via Bearer <ADMIN_KEY><uid>, but never sets ADMIN_KEY_AUTH_ENABLED. With the new fail-closed default the token no longer matches the admin prefix path, falls through to Firebase, raises InvalidIdTokenError, and the LOCAL_DEVELOPMENT bypass returns the shared dev uid 123. The delete-account call then writes a marker to account_deletions/123, which neither the fixture (it cleans account_deletions/<fresh_uid>) nor isolate_e2e_state's clear_user_data(DEV_UID) (users-subtree scoped) removes — so every subsequent test in the suite 403s with account_deletion_in_progress. You updated the three stack runners (listen_pusher_stack/run.py, sync_cloud_tasks_stack/run.py, replay_harness_phase0a/runner.py) but this fourth consumer was missed: add ADMIN_KEY_AUTH_ENABLED=true in the fixture (or conftest._set_e2e_env).
  2. Backend unit: two stale-contract tests in tests/unit/test_async_app_integrations.py after app_integrations.py correctly switched json=payload → content=body_bytes (so the signature covers the exact delivered bytes):
    • test_finalization_delivery_sends_the_durable_idempotency_key asserts headers == {'X-Omi-Idempotency-Key': ...}; the code now also sets Content-Type: application/json.
    • test_creation_webhook_payload_strips_geolocation reads call_args.kwargs['json'] → KeyError; it should json.loads(kwargs['content']).
  3. Hygiene ratchet: backend/testing/listen_pusher_stack/run.py grew 1843 → 1844 lines; add the Line-Count-Exception: line to the PR body or absorb the line.

Design questions before merge

  • Rollout coupling: with OMI_PLUGIN_WEBHOOK_SECRET unset anywhere, resolve_authenticated_uid raises on the plugin side (secret=None is fail-closed; allow_uid_only defaults False) and the backend signs nothing — so github-app/dropbox-app webhooks and tools hard-fail 401 until the same secret is deployed to both the API and the plugin services, and the webhook circuit breaker may then disable those apps. This needs a coordinated config rollout plan (or an explicit short allow_uid_only migration window) as part of landing it.
  • hey_omi uses a different scheme than the fleet: plugins/notifications/hey_omi.py now requires Authorization: Bearer <HEY_OMI_APP_SECRET>, but the backend's outbound realtime-integration call ({"session_id": uid, "segments": ...} in app_integrations.py) sends only the X-Omi-* HMAC headers — no bearer. Unless something else furnishes that header, the "hey omi" webhook 401s post-deploy. Can hey_omi also accept the shared HMAC (omi_plugin_sdk.auth.verify_headers), or should the backend send an app-level bearer?
  • Setup-UI flows are intentionally disabled pending product work: the TODO(security) comments on omi-github-app/main.py (/, /auth, and the /save-agent-key JS which now surfaces an auth-required alert) and omi-dropbox-app/main.py (/settings, /disconnect) mean browser-driven mutations can't mint the plugin HMAC. Right security call, but save-key / update-repo / settings flows stay broken until setup URLs are signed on the product side — worth an explicit tracking issue so it isn't discovered in production.

What looks good (verified)

  • backend/utils/other/endpoints.py: the default flip to 'false' is exactly the fail-closed behavior the title promises; constant-time compare and audit logging retained; the admin-router secret-key path untouched.
  • backend/utils/plugin_auth.py ↔ plugins/omi-plugin-sdk/src/omi_plugin_sdk/auth.py: algorithms match (HMAC-SHA256(secret, "{uid}.{timestamp}." + body)), 300s max age, compare_digest everywhere, uid-mismatch rejection, and both new test files cover roundtrip/tamper/skew/mismatch.
  • plugins/oauth/client.py: HMAC-signed state with 600s expiry replaces bare-uid state; the callback in conversation_created.py rejects invalid state with a restart-setup page.
  • plugins/omi-dropbox-app/db.py: opaque token:<state> → uid map with 10-min TTL and pop-once semantics, legacy uid:nonce fallback retained.
  • Docs (plugins/README.md, SDK README, backend/.env.template) accurately describe the new env vars and the uid-is-a-hint rule.

Requesting changes only for the CI items above — the security substance is in good shape. Leaving for human maintainer review: the coordinated OMI_PLUGIN_WEBHOOK_SECRET rollout decision across backend + plugin services, and the product call on signed setup URLs.


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 backend Backend Task (python) labels Sep 11, 2026
hridaya423 added a commit to hridaya423/omi that referenced this pull request Sep 17, 2026
/zapier/trigger/memory/sample returned the caller-chosen uid's latest
conversation including the full transcript; /zapier/action/memories
wrote an arbitrary conversation into any uid's account; the trigger
subscribe/unsubscribe pair stored an attacker-controlled target_url
against any uid; /zapier/memories accepted webhooks with no caller
binding; /zapier/me answered status probes. All six trusted the
client-supplied uid with no credential.

Add require_zapier_webhook_auth (same fail-closed pattern as the
merged mentor session fix, BasedHardware#13685): Authorization bearer or
zapier_webhook_token query param checked against ZAPIER_WEBHOOK_SECRET
with hmac.compare_digest; 503 when unconfigured, 401 on missing or
mismatched token.

Residual, tracked in BasedHardware#14428: the browser control-plane endpoints
(/setup-zapier, /zapier/connect, /zapier/disconnect, /setup/zapier)
remain uid-keyed because the Omi app opens them without a credential;
with the data plane closed, toggling enabled state grants no data
access. Binding them needs a capability token issued by the Omi
backend link (the direction of BasedHardware#13463).

Deployment note: ZAPIER_WEBHOOK_SECRET must be set and the Zapier app
/ Omi webhook callers configured to send it, matching the mentor
precedent.

Verification: python3 test_webhook_auth.py (10 tests incl. boundary
cases) and python3 test_zapier_hardening.py (18 tests) all pass.

Failure-Class: new — client-supplied uid accepted as authorization on unauthenticated plugin routes
hridaya423 added a commit to hridaya423/omi that referenced this pull request Sep 17, 2026
/zapier/trigger/memory/sample returned the caller-chosen uid's latest
conversation including the full transcript; /zapier/action/memories
wrote an arbitrary conversation into any uid's account; the trigger
subscribe/unsubscribe pair stored an attacker-controlled target_url
against any uid; /zapier/memories accepted webhooks with no caller
binding; /zapier/me answered status probes. All six trusted the
client-supplied uid with no credential.

Add require_zapier_webhook_auth (same fail-closed pattern as the
merged mentor session fix, BasedHardware#13685): Authorization bearer or
zapier_webhook_token query param checked against ZAPIER_WEBHOOK_SECRET
with hmac.compare_digest; 503 when unconfigured, 401 on missing or
mismatched token.

Residual, tracked in BasedHardware#14428: the browser control-plane endpoints
(/setup-zapier, /zapier/connect, /zapier/disconnect, /setup/zapier)
remain uid-keyed because the Omi app opens them without a credential;
with the data plane closed, toggling enabled state grants no data
access. Binding them needs a capability token issued by the Omi
backend link (the direction of BasedHardware#13463).

Deployment note: ZAPIER_WEBHOOK_SECRET must be set and the Zapier app
/ Omi webhook callers configured to send it, matching the mentor
precedent.

Verification: python3 test_webhook_auth.py (10 tests incl. boundary
cases) and python3 test_zapier_hardening.py (18 tests) all pass.

Failure-Class: new — client-supplied uid accepted as authorization on unauthenticated plugin routes
undivisible and others added 3 commits September 25, 2026 12:17
- account_deletion_identity now sets ADMIN_KEY_AUTH_ENABLED=true so the
  hermetic e2e fixture authenticates via Bearer <ADMIN_KEY><uid> again;
  without it the token falls through to the LOCAL_DEVELOPMENT dev uid,
  writes the deletion marker to account_deletions/123, and 403s the rest
  of the suite with account_deletion_in_progress.
- test_async_app_integrations: assert the Content-Type header the signed
  body path now sets, and read the delivered bytes via kwargs['content']

Amp-Thread-ID: https://ampcode.com/threads/T-01a0d867-2f0a-75f2-838d-07056aadf229
Co-authored-by: Max Carter <[email protected]>
Preserves both fail-closed auth layers on the github-app /tools/* routes:
main's shared-secret bearer guard (require_github_tools_auth) and this
PR's per-request plugin HMAC (_require_uid). Takes main's hardened
input normalization (hey_omi webhook session/uid stripping, github-app
issue-number coercion, repo short-name resolution, oauth.py setup URL
query separator) while keeping the PR's HMAC fleet identity, signed
OAuth state, and key-out-of-query-string save-agent-key POST body.

Amp-Thread-ID: https://ampcode.com/threads/T-01a0d867-2f0a-75f2-838d-07056aadf229
Co-authored-by: Max Carter <[email protected]>
The plugin apps now import omi_plugin_sdk.auth, which the stdlib-only
hermetic suites cannot import (package __init__ pulls pydantic-dependent
models). File-load the real stdlib-only auth.py into each suite's stubs
so the genuine HMAC scheme stays under test:

- omi-github-app/test_main.py: _Request now carries request.body(),
  query_params, and real signed X-Omi-* headers (secret pinned via
  OMI_PLUGIN_WEBHOOK_SECRET); tool/JSON-endpoint tests updated to the
  new (request, body-uid) contracts.
- omi-dropbox-app test_main + test_token_refresh_and_tools: real SDK
  auth stub + new db symbols (store_oauth_state_by_token,
  pop_oauth_uid_for_state).
- plugins/test_oauth_error_params_escaped.py +
  test_uid_reflection_remaining_apps.py: permissive omi_plugin_sdk stub
  replaced with the real auth module; dropbox disconnect test now signs
  its request (HMAC required, query uid is a hint only).
- notifications/test_hey_omi_extraction.py: webhook() takes
  (http_request, request) and requires inbound bearer auth; calls send
  an authenticated Starlette-style request and a new test pins the 401
  fail-closed path. Pin a non-empty test secret (empty secret rejects
  all requests by design).

Also fix a real reflected-XSS vector the uid-reflection suite caught:
the github-app root page embedded the raw uid into the save-agent-key
JS body string, where a uid containing </script> breaks out of the
script block. Use the percent-encoded safe_uid like every other JS
embedding in that template.

TODO(security) markers now cite #13463 where the deferred signed-setup-
URL work is tracked (deferred-work-markers gate).

Amp-Thread-ID: https://ampcode.com/threads/T-01a0d867-2f0a-75f2-838d-07056aadf229
Co-authored-by: Max Carter <[email protected]>
@undivisible

undivisible commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

@/tmp/pr-comment-current.md

logger.warning(
'%s unset — outbound plugin calls are unsigned; '
'plugins that enforce omi_plugin_sdk.auth will reject bare uid',
WEBHOOK_SECRET_ENV,
@Git-on-my-level
Git-on-my-level dismissed their stale review October 2, 2026 00:27

Dismissing as stale: the blocking items in this review (missing ADMIN_KEY_AUTH_ENABLED in the account_deletion_identity E2E fixture, the two stale-contract tests in test_async_app_integrations.py, and the Hygiene line ratchet) are all verified fixed and green on the current head 69fc79b. Current follow-up is tracked in the new review (hey_omi inbound auth mismatch + a CodeQL false positive).

@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 @undivisible — this head resolves every blocking item from my earlier review. Verified on 69fc79b: the account_deletion_identity fixture in backend/testing/e2e/test_account_deletion_cloud_tasks.py now sets ADMIN_KEY_AUTH_ENABLED=true (Hermetic Backend E2E green); the two stale-contract tests in backend/tests/unit/test_async_app_integrations.py were updated for the content=/signed-bytes change (Backend unit + Hermetic Merge Gate green); Hygiene green.

The fail-closed core is in good shape: backend/utils/other/endpoints.py defaults the flag to 'false' while keeping the constant-time compare and audit logging; backend/utils/plugin_auth.py and plugins/omi-plugin-sdk/src/omi_plugin_sdk/auth.py agree on HMAC-SHA256(secret, "{uid}.{timestamp}." + body) with a 300s skew window and compare_digest throughout, and both new test files (backend/tests/unit/test_plugin_auth.py, plugins/omi-plugin-sdk/tests/test_auth.py) cover roundtrip/tamper/skew/mismatch from each side. plugins/oauth/client.py HMAC-signs the Notion state with a 600s window and plugins/oauth/conversation_created.py rejects invalid state with a restart-setup page; plugins/omi-dropbox-app/db.py adds the opaque token:<state> -> uid map with pop-once semantics; backend/routers/oauth.py, backend/utils/app_integrations.py, and backend/utils/retrieval/tools/app_tools.py now sign outbound plugin calls over the exact delivered bytes (GET signs an empty body — query params uncovered, as the code comment notes).

Two items before this moves forward:

  1. hey_omi webhook will 401 every backend call. plugins/notifications/hey_omi.py _require_hey_omi_inbound_auth requires Authorization: Bearer <HEY_OMI_APP_SECRET> and rejects everything else (fail-closed when unset), but the only caller, _async_trigger_realtime_integrations in backend/utils/app_integrations.py (payload {"session_id": uid, "segments": ...}), sends only the X-Omi-* HMAC headers, and nothing in the backend reads HEY_OMI_APP_SECRET. Post-deploy every realtime hey-omi delivery 401s, the journey fails, and the webhook circuit breaker will disable the app. Either have hey_omi also accept the shared plugin HMAC (omi_plugin_sdk.auth.verify_headers) alongside the bearer, or have the backend send an app-level bearer for this app.

  2. The CodeQL failure is a false positive. Alert 364 flags backend/utils/plugin_auth.py:67 as clear-text secret logging, but that line logs WEBHOOK_SECRET_ENV, the env-var name constant, not the value. It needs to be dismissed on the Code Scanning tab (a re-run alone won't clear it) so the check can go green.

Still maintainer decisions, non-blocking from my side: the coordinated OMI_PLUGIN_WEBHOOK_SECRET rollout across API + plugin services before enforcement flips live, and the product call on signing setup URLs — the TODO(security) comments in plugins/omi-github-app/main.py and plugins/omi-dropbox-app/main.py leave those browser flows intentionally broken pending that work, which deserves its own tracking issue so it isn't discovered in production.

I've dismissed my earlier changes-requested review since its blocking items were exactly those CI failures, all verified fixed. Requesting changes now only for the hey_omi auth mismatch. Because this changes the fleet-wide auth model and the ADMIN_KEY bypass default, it still needs maintainer sign-off on rollout sequencing 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.

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

backend Backend Task (python) needs-maintainer-review Needs a human maintainer to sign off before merge 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