Repository navigation
fix(plugins): require auth on iq-rating routes keyed only by uid - #14431
hridaya423 wants to merge 2 commits into
Conversation
The iq_rating router mounted in the plugins monolith trusts the client-supplied uid with no credential: - GET /iq-rating/iq/preload and /iq/refresh trigger a scrape of ALL memories and conversations for any uid via the server-side OMI_APP_SECRET - GET /iq-rating/iq and /iq/api serve the extracted people names and scores for any uid (the HTML page embeds them publicly) - POST /iq/hide, /iq/unhide, /iq/adjust mutate any uid's data Same contract violation as the merged mentor session fix, wider blast radius: one request converts a uid into a full memory/conversation scrape. Adds plugins/iq_rating/iq_auth.py mirroring the mentor/zapier pattern: IQ_RATING_SECRET env secret, Bearer or iq_rating_token query param, hmac.compare_digest, fail-closed 503 when unconfigured. Wired onto the six uid-keyed data routes; the uid-less /iq landing state and /iq/setup-status stay public. Also escapes the uid embedded in the page JS (was a reflected-XSS sink) and threads the query token into the page's hide/adjust fetches so authenticated page actions keep working. Deployment note: IQ_RATING_SECRET must be set and the Omi app/webview caller must pass iq_rating_token, matching the mentor precedent. Verification: python3 plugins/iq_rating/test_iq_auth.py — 11 tests (fail-closed unconfigured, missing/wrong/non-bearer token, bearer and query token accepted, uid trimming, optional-uid page gate, route wiring) all pass. Failure-Class: new — client-supplied uid accepted as authorization on unauthenticated plugin routes
The query token was interpolated raw inside a single-quoted JS literal — a token containing ' would break out of the string. json.dumps keeps it inside a double-quoted literal with proper escaping, same as the uid fix. Verified: render check with token x'-alert(1)-' produces const tokenParam = "iq_rating_token=x'-alert(1)-'&";; 11 iq auth tests pass.
Git-on-my-level
left a comment
There was a problem hiding this comment.
Verified against main and the head - this is a real fix for a real hole. Leaving merge sign-off to a human maintainer since it changes auth on a conversation-derived-data surface and needs deployment coordination.
What I verified
- The vulnerability is real on main:
plugins/main.pymounts theiq_ratingrouter, and every data route took a bare client-supplieduidwith no credential.load_and_process_user_data(uid)pages memories and conversations server-side usingOMI_APP_SECRET, so one unauthenticated GET could scrape any uid, and/iq/apiread the extracted names back. plugins/iq_rating/iq_auth.py- a faithful mirror of the merged mentor pattern (plugins/basic/mentor_webhook_auth.py, #13665):hmac.compare_digest,Authorization: Beareroriq_rating_tokenquery param, fail-closed 503 whenIQ_RATING_SECRETis unset or blank (the blank-string check is a nice touch), 401 otherwise, uid trimmed with 422 on empty.plugins/iq_rating/main.py- all six uid-keyed routes (/iq/api,/iq/hide,/iq/unhide,/iq/adjust,/iq/preload,/iq/refresh) now resolveuidviaDepends(require_iq_auth); the/iqpage usesrequire_iq_auth_if_uid, so the uid-less landing state (empty-state hint only - no data path) stays public while any real uid requires the token. The reflected-XSS sinkconst uid = '{uid}'is gone -json.dumps(uid)emits a quoted JS string literal - and the hide/adjust fetches nowencodeURIComponent(uid)and threadiq_rating_tokenthrough, so authenticated page actions keep working.plugins/iq_rating/test_iq_auth.py- ran the suite in a sandbox against the head sources: 11/11 pass. Good coverage: fail-closed 503 (missing and blank secret), 401 (missing/wrong/non-Bearer token), Bearer and query-param acceptance, uid trimming, the if-uid variant, plus a static wiring test asserting every data route declares the dependency and the raw'{uid}'sink stays gone.
Notes for the maintainer
- Merge requires deployment coordination:
IQ_RATING_SECRETmust be set and the app/webview caller updated to send it, otherwise the plugin fails closed with 503 by design (same rollout shape as the mentor fix). /iq/setup-statusand the uid-less/iqlanding state remain public by design - correct: neither touches user data.- Non-blocking hardening nit:
json.dumpsdoes not escape/, so a uid (or an extracted person name) containing</script>can still terminate the script block in the rendered page. With the route now token-gated this is only reachable by callers holding the secret, but escaping<as\u003cat the embed sites would close it. The pre-existing error path also interpolates{e}into HTML. - The shared-secret-in-query tradeoff is inherited from the mentor pattern (tokens can land in access logs); the per-user capability direction noted on #14430 is the longer-term answer.
Since #14430 publicly documents the scrape primitive, prompt human sign-off and rollout would close that window; bounty adjudication also belongs to a human. Thanks for the clean fix and the hermetic test suite - it made this easy to verify.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
|
Verified on Leaving this open as the remaining-hole vehicle on Not approving from here: hosted checks are not green (0-check / UNSTABLE / FTC). kodjima APPROVE is not a merge. I am not merging. |
aryanorastar
left a comment
There was a problem hiding this comment.
Reviewed b8bfade.
plugins/iq_rating/main.py iq_rating_api still raises HTTPException(..., detail=str(e)). This head wires Depends(require_iq_auth) and does not change that except. test_iq_auth.py never imports the route module. Mask the detail and import the route in the test.
|
Keeping this open. Not approving — Astar, on behalf of @aryanorastar |
|
Thanks for this fix, @hridaya423! Your commits are being carried forward in #20223 (cherry-picked with your original authorship intact) so they can land with the current CI and repo conventions. Closing this in favor of that branch — your contribution is credited there and in the git history. |
|
Hey @hridaya423 👋 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:
Before your next PR, please skim:
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! |
Fixes #14430
Summary
The
iq_ratingrouter mounted inplugins/main.pytrusts the client-supplieduidwith no credential:GET /iq-rating/iq/preload?uid=/GET /iq-rating/iq/refresh?uid=OMI_APP_SECRET; extracted names stored in the plugin DBGET /iq-rating/iq?uid=/GET /iq-rating/iq/api?uid=POST /iq/hide,/iq/unhide,/iq/adjustOne GET request converts a bare uid into a full conversation-history scrape with public read-back. Same contract violation as the merged mentor session fix (#13665), wider blast radius.
Fix
plugins/iq_rating/iq_auth.pymirrors the mentor/zapier pattern:IQ_RATING_SECRETenv secret,Authorization: Beareroriq_rating_tokenquery param,hmac.compare_digest, fail-closed 503 when unconfigured, 401 on missing/mismatched token. Wired viaDependsonto all six uid-keyed routes.Left public deliberately: the uid-less
/iqlanding state (renders only the "add ?uid=" hint, no data path) and/iq/setup-status(Omi directory metadata).Also fixed here
const uid = '{uid}'reflected-XSS sink, nowjson.dumps(uid).iq_rating_tokenquery param so authenticated page actions keep working.Residual + deployment note
/iqHTML page is browser-facing: legitimate opens neediq_rating_tokenappended to the URL. Deployment must setIQ_RATING_SECRETand configure the Omi app/webview caller to send it, same shape as the merged mentor fix.Tests
python3 plugins/iq_rating/test_iq_auth.py: 11 tests, fail-closed unconfigured (503 incl. blank secret), missing/wrong/non-bearer token (401), bearer + query token accepted, uid trimming, optional-uid page gate, and a labeled static wiring check across all six routes plus the raw-uid JS sink.Failure-Class: new — client-supplied uid accepted as authorization on unauthenticated plugin routes