Repository navigation
fix(security): require a signed settings session in omi-github-app - #23178
Git-on-my-level merged 3 commits into
Conversation
The settings routes wrote per-user state from a bare `uid` query parameter, so anyone who knew a uid could overwrite that user's agent API key or provider, delete the key, or repoint issue creation at another repository. `/auth?uid=` also let a caller bind their own GitHub account to someone else's uid. After a successful OAuth callback the plugin now issues an HMAC-SHA256 signed session cookie bound to the uid, verifies it on every settings write, and refuses to rebind a uid that already has a stored access token without that session. Fail closed: 503 when `GITHUB_SETTINGS_SECRET` is unset, 401 on a missing, foreign, or tampered cookie. Refs BasedHardware#23177.
The settings routes now take `request` and verify the session cookie before touching storage. The direct-call tests keep their error-path assertions by passing a request carrying a valid signed cookie; `_StubResponse` records the cookie the OAuth callback sets.
|
Checks are green now. The second commit ( Deployment note: this needs @josancamon19 @kodjima33 — if you would rather wait for the backend-signed setup URL (option 1 in #23177) and close this, that is fine; this PR is the self-contained mitigation so the settings surface is not open in the meantime. |
|
Verdict: solid, correctly scoped security fix — this closes the unauthenticated settings-write surface from #23177, and I found no defects. Leaving formal sign-off to a human maintainer because it is an auth-flow change with a deployment dependency. What I verified:
Non-blocking notes:
Security: this closes the write surface. The remaining known gaps (first-bind spoof via USER IMPACT: users reconnect GitHub once; after that, settings changes behave as before but can no longer be made by anyone who merely knows a user ID. What I'd still want as a reviewer (none blocking): a test for the "Already Connected" 403 callback path, and a note in the PR or plugin README on where Maintainer note: this is the self-contained plugin-side mitigation (option 2 in #23177); the backend-signed setup URL (option 1) remains the complete fix, so this needs a maintainer decision on whether to take the mitigation now — and by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
Git-on-my-level
left a comment
There was a problem hiding this comment.
Verdict: the security direction is right and the guard implementation is careful — but one availability regression needs fixing before merge: every user who already has GitHub linked gets permanently locked out of the settings page.
What's good (verified on this head):
- github_settings_auth.py — HMAC-SHA256 over the uid, hmac.compare_digest, fail-closed 503 (unset secret) / 401 (missing, foreign, or tampered cookie), and rpartition parsing that survives uids containing dots.
- All seven mutating routes are wired: require_settings_session at main.py:1560, 1584, 1615, 1661, 1688, 1714, 1743 — and the AST test in test_github_settings_auth.py enforces the wiring, which is a nice touch.
- The rebind guard at main.py:1418 closes the "start OAuth for someone else's uid and overwrite their binding" path; cookie flags (httponly, secure, samesite=lax) are right.
- I ran the new suite locally: 8/8 pass.
Blocking — existing linked users are locked out with no recovery path:
- A user linked before this ships has no omi_github_settings cookie, so every settings write returns 401. Their only route to a cookie is the OAuth callback, which now 403s at main.py:1418 ("Already Connected"), and main.py:1505 is the only place a cookie is minted. With no unlink route, the lockout is permanent without manual storage intervention — the entire existing user base loses settings.
- Suggested fix: you already store github_username per user. In the callback, after a successful token exchange, compare the new token's GitHub login to the stored github_username; when the same GitHub identity re-authenticates, allow the rebind and mint the cookie. A different GitHub login still 403s, preserving the takeover protection while giving existing users a self-serve path.
Also needed (deployment):
- GITHUB_SETTINGS_SECRET is now required but undocumented — the README env section covers GITHUB_TOOLS_SECRET but not this, and .env.example/railway.toml/Dockerfile are untouched. Merging before the var is set bricks every settings write with 503 and prevents OAuth from minting sessions. Please add the docs and call out the deploy order.
Minor:
- In test_agent the guard at main.py:1743 sits inside the try, so its 401/503 is swallowed by the except Exception at main.py:1841 into a misleading 200 "Failed to execute agent test". The write is still blocked, but moving the guard above the try would match the other six routes' status semantics.
- The cookie value never expires cryptographically (no timestamp/nonce in the HMAC input) — valid until the secret rotates; the 30-day max_age is browser-side only. Acceptable as a mitigation; worth folding into the backend-signed fix (#23177 option 1).
Security: strictly reduces exposure vs. main — the uid-only write surface and the OAuth-rebind overwrite are both closed; the residual first-link binding attack is real but pre-existing and correctly deferred to the backend-signed setup URL.
USER IMPACT: users who already connected GitHub would permanently lose the ability to change their repo/provider/key settings (401 on every save, 403 on reconnect) until fixed; brand-new users are unaffected.
Action items: (1) same-identity re-auth recovery for already-linked users, (2) document GITHUB_SETTINGS_SECRET + deploy-order note, (3) move the test_agent guard above its try block. The core guard design is solid — with those, this is close.
This touches an auth flow that guards stored GitHub tokens and agent API keys, so maintainer sign-off is needed before merge regardless of the fixes.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
…ecret - /auth/callback now allows an already-linked uid to rebind when the fresh OAuth token belongs to the stored GitHub username (case-insensitive, never the "Unknown" fallback). A different identity still gets 403 and nothing is saved, so the takeover protection is unchanged while pre-upgrade users get a self-serve recovery path. - Move the /test-agent session guard above the broad try so 401/503 reaches the client instead of being rewritten as a 200 "Failed to execute agent test". - Document GITHUB_SETTINGS_SECRET, its deploy order, and recovery behaviour in the plugin README; add the missing .env.example referenced by the README. - Tests: same-identity recovery, different-identity rejection without a session, valid-session rebind, first link, and 401 propagation (98 + 8 pass).
|
Addressed the three action items in 88216a8. 1. Same-identity recovery (blocking).
The 2. Deployment docs. The README now documents 3. Verification on @Git-on-my-level could you take another look? This still needs a human maintainer sign-off because it is an auth-flow change with a deployment dependency. |
|
@josancamon19 @kodjima33 — the one blocking item from the review (existing linked users locked out) is fixed in @Git-on-my-level a re-review of |
Git-on-my-level
left a comment
There was a problem hiding this comment.
Since my last review: addressed (the lockout blocker — already-linked users can now recover by reconnecting with the same GitHub account, verified on this head) · still open (nothing blocking) · newly introduced (nothing blocking; two hardening notes below).
The production change here is correct and nicely scoped; the availability regression from my earlier review is fixed. This is a security-sensitive auth change, so it still needs maintainer sign-off before merge.
Verified on this head:
- main.py
auth_callback— the rebind guard refuses only when the browser holds no valid session AND the fresh OAuth login differs (casefold-compared; empty or "Unknown" stored names never match) from the stored username. A legitimate user re-linking the same account gets a fresh signed cookie; a different account gets a 403 with nothing saved andoauth_statescleaned (covered byOAuthCallbackRebindTests). - github_settings_auth.py — HMAC-SHA256 over the uid,
hmac.compare_digest, fail-closed 503 (unset secret) / 401 (missing, foreign, or tampered cookie),rpartitionparsing that survives uids containing dots. Cookie issued httponly + samesite=lax + secure. - All seven settings writes (
update_repo,refresh_repos,check_repo_access,save_agent_provider,save_agent_key,delete_agent_key,test_agent) callrequire_settings_sessionbefore touching storage, and the AST wiring test pins that set so a future route can't silently miss the guard./test-agentruns the guard above its broadtry, so 401/503 reach the client as themselves. - README.md / .env.example — the deploy-order note (set
GITHUB_SETTINGS_SECRETbefore deploying) matches the code: without it, writes fail closed with 503 and the callback cannot mint a session.
Security (non-blocking, worth a maintainer's eyes):
- The identity-recovery path anchors on the GitHub login name. If a user renames their GitHub account, the freed login can be re-registered by someone else and then pass
same_identityfor that uid, rebinding it to the attacker's own account. Comparing the numeric GitHub user id fromget_user_infowould close that. Impact today is limited (an attacker can only inject their own token), but this anchor backs the whole guard. - The cookie MAC embeds no expiry, so a leaked cookie value stays valid until the secret rotates. A timestamp inside the MACed value would bound that.
Blast radius: plugins/omi-github-app only; the complete backend-signed setup URL fix (#23177 option 1) remains compatible as described.
USER IMPACT: users who already linked GitHub will be asked to reconnect once from the settings page; after that everything works as before, and nobody can change their settings by guessing their user id.
Still wanted as a reviewer: consider the numeric-id identity anchor above, and a test for the stored-username-is-empty-or-"Unknown" edge (those users cannot self-recover via the identity path).
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
Dismissed: the blocking concern from this review (already-linked users permanently locked out of the settings page) is resolved on head 88216a8 - same-identity re-auth now re-issues the session cookie, verified in auth_callback and covered by OAuthCallbackRebindTests.
|
Hi |
aryanorastar
left a comment
There was a problem hiding this comment.
plugins/omi-github-app check_setup and update_repo still take a uid query, and github_settings_auth.py is absent on main. This head requires a signed settings session. test_github_settings_auth.py pins the 401 and 403 paths. Hygiene passed.
What changed and why
Fixes #23177.
plugins/omi-github-appsettings routes (/update-repo,/refresh-repos,/check-repo-access,/save-agent-provider,/save-agent-key,/delete-agent-key,/test-agent) wrote per-user state keyed only by auidquery parameter. Anyone who knew a uid could overwrite or delete that user’s stored agent API key, change their provider, repoint issue creation at another repository, or run agent tests with their stored GitHub token.This PR adds the plugin-side mitigation from the issue:
github_settings_auth.py— HMAC-SHA256 signed session cookie (GITHUB_SETTINGS_SECRET),hmac.compare_digestverification, fails closed with 503 when the secret is unset and 401 when the cookie is missing, names another uid, or is tampered with./auth/callback— issues the signed cookie and guards rebinding: a uid that already has a stored token may be rebound only by a browser holding its valid session cookie, or when the fresh OAuth token belongs to the same stored GitHub username (case-insensitive, and the"Unknown"fallback never matches). A different GitHub identity gets 403 with nothing saved and no cookie. This keeps the takeover protection while giving users who linked before this guard a self-serve recovery path.require_settings_session(request, uid)before touchingSimpleUserStorage./test-agentruns the session guard above its broadtry, so a 401/503 reaches the client instead of being rewritten as a 200Failed to execute agent test.GITHUB_SETTINGS_SECRETand the deploy order, and the.env.examplereferenced by the README now exists.The complete fix is still the backend-signed setup URL (
uid+ HMAC from Omi) described as option 1 in #23177; this change is self-contained and can land without a backend deploy, and is compatible with that later change.Rollout note
The plugin now requires
GITHUB_SETTINGS_SECRETto be set. Until it is, settings writes return 503 (fail closed) and OAuth callbacks cannot issue a session. Set the variable in the Railway dashboard before deploying this version. Existing linked users recover by reconnecting GitHub once with the same account; a different account is still rejected unless the browser already has a valid session.Product invariants affected
none
How it was verified
The settings suite covers the fail-closed unconfigured secret, missing cookie, cookie for another uid, tampered signature, the valid accept path, and two AST checks (all seven settings writes call the guard;
auth_callbackissues the cookie). The main suite adds coverage for same-identity recovery without a cookie, different-identity rejection with no save and no cookie, a valid session rebinding a different identity, first-link, and/test-agentsurfacing 401 instead of a generic 200.I could not exercise the OAuth flow against a live deployment from this environment; the unit tests cover the guard and callback contracts, and the callback wiring is pinned by the AST test.
Tests
plugins/omi-github-app/test_github_settings_auth.py(new),plugins/omi-github-app/test_main.py(callback and guard-ordering cases).UI evidence
UI-Evidence: none -- backend/plugin auth change only; the existing fetch calls are same-origin and send the cookie automatically.
Failure class (fixes)
Failure-Class: none
No registered failure class covers a per-user settings route that trusts a bare uid; this is the uid-as-identifier-not-credential hardening already tracked in #23177.