Skip to content

fix(security): require a signed settings session in omi-github-app - #23178

Merged
Git-on-my-level merged 3 commits into
BasedHardware:mainfrom
1132dadf:security/github-app-settings-auth
Nov 8, 2026
Merged

Git-on-my-level merged 3 commits into
BasedHardware:mainfrom
1132dadf:security/github-app-settings-auth

Conversation

@1132dadf

@1132dadf 1132dadf commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

Fixes #23177.

plugins/omi-github-app settings 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 a uid query 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_digest verification, 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.
  • Every settings write now calls require_settings_session(request, uid) before touching SimpleUserStorage.
  • /test-agent runs the session guard above its broad try, so a 401/503 reaches the client instead of being rewritten as a 200 Failed to execute agent test.
  • Deployment docs: the plugin README now documents GITHUB_SETTINGS_SECRET and the deploy order, and the .env.example referenced 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_SECRET to 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

python test_github_settings_auth.py
Ran 8 tests in 0.035s
OK

python test_main.py
Ran 98 tests in 0.039s
OK

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_callback issues 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-agent surfacing 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.

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

Copy link
Copy Markdown
Contributor Author

Checks are green now. The second commit (ce67fc6) updates the existing plugins/omi-github-app/test_main.py for the new request parameter: those direct-call tests now pass a request carrying a valid signed test session, and _StubResponse records the cookie the callback sets. The guard contract itself is covered by the new test_github_settings_auth.py (8 tests). Locally: python test_main.py → 93 tests OK, python -m unittest test_github_settings_auth → 8 OK.

Deployment note: this needs GITHUB_SETTINGS_SECRET set before release. Until then settings writes return 503 by design (fail closed).

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

@Git-on-my-level

Copy link
Copy Markdown
Member

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:

  • github_settings_auth.py — HMAC-SHA256 over the uid, constant-time compare via hmac.compare_digest, rpartition cookie parse, fails closed: 503 when GITHUB_SETTINGS_SECRET is unset, 401 when the cookie is missing, names another uid, or is tampered with. Consistent with the existing github_tools_auth.py shared-secret pattern.
  • main.py — all seven mutating routes (update_repo, refresh_repos, check_repo_access, save_agent_provider, save_agent_key, delete_agent_key, test_agent) call require_settings_session(request, uid) before any SimpleUserStorage access. In test_agent the guard sits after the uid/prompt presence check but before storage — correct ordering.
  • auth_callback — the new rebind guard (is_authenticated(uid) and not session_matches(...) → 403 "Already Connected") is placed after OAuth state validation and before the token exchange, which is the right spot since uid comes from the state map. Cookie is issued with httponly, samesite=lax, secure.
  • Tests — test_github_settings_auth.py covers fail-closed secret, missing cookie, wrong-uid cookie, tampered signature, plus an AST test asserting all seven routes are wired; test_main.py success-path tests now mint a signed session.

Non-blocking notes:

  • The cookie carries no embedded expiry or nonce, so it cannot be revoked server-side within its fixed 30-day max_age. Fine for a mitigation; add an expiry claim if this becomes the permanent mechanism.
  • The AST wiring test hardcodes the PROTECTED route set — a settings route added later would not be caught unless added there too.
  • secure=True means the cookie is not issued over plain HTTP (non-localhost); fine for current https deployments.

Security: this closes the write surface. The remaining known gaps (first-bind spoof via /auth?uid=, read-only uid disclosure on GET / and /setup-completed) are pre-existing and acknowledged in #23177 — not regressions here.
Blast radius: if GITHUB_SETTINGS_SECRET is not configured at deploy time, all settings writes return 503 by design — deployment coordination is required before this merges.

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 GITHUB_SETTINGS_SECRET should be documented for operators.

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 GITHUB_SETTINGS_SECRET must be set in deployment 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.

@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 Oct 22, 2026

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

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).
@1132dadf

Copy link
Copy Markdown
Contributor Author

Addressed the three action items in 88216a8.

1. Same-identity recovery (blocking). /auth/callback now exchanges the code first, reads the token's GitHub login, and compares it case-insensitively with the stored github_username:

  • same identity, no cookie → rebind allowed and a fresh session cookie is minted (pre-upgrade users can self-serve reconnect);
  • different identity, no valid cookie → 403 "Already Connected", nothing saved, no cookie;
  • valid session cookie → rebind allowed, preserving intentional account switching.

The "Unknown" fallback can never satisfy the identity check, so a failed user-info lookup cannot turn into a rebind bypass. Tests: same-identity recovery, different-identity rejection (asserts save_user is not called and no cookie is set), valid-session rebind, and first link.

2. Deployment docs. The README now documents GITHUB_SETTINGS_SECRET in both the local .env block and the Railway variable list, with the deploy order (set it before deploying; rotating it invalidates sessions; missing it makes writes 503). I also added the plugins/omi-github-app/.env.example that the README already referenced. I did not bake a value into railway.toml or Dockerfile — secrets belong in the platform dashboard, not the image.

3. /test-agent guard ordering. The guard now runs above the broad try, so 401/503 propagates instead of being rewritten as a 200 "Failed to execute agent test"; a new test pins that. The rest of the handler is unchanged.

Verification on 88216a8: test_github_settings_auth.py 8/8 OK, test_main.py 98/98 OK. The cookie still has no cryptographic expiry/nonce; as you noted, that belongs with the backend-signed setup URL in #23177 option 1, so I left it as the documented follow-up rather than expanding this mitigation.

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

@1132dadf

Copy link
Copy Markdown
Contributor Author

@josancamon19 @kodjima33 — the one blocking item from the review (existing linked users locked out) is fixed in 88216a8: the callback now exchanges the code first and allows a same-identity reconnect to mint a fresh session cookie, while a different GitHub login still gets 403. The GITHUB_SETTINGS_SECRET docs and the guard-ordering fix are in the same commit. All 41 checks pass on this head. This needs a human sign-off because it is an auth-flow change with a deployment dependency — could one of you take a look?

@Git-on-my-level a re-review of 88216a8 would help close the loop if you have a moment.

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

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 and oauth_states cleaned (covered by OAuthCallbackRebindTests).
  • github_settings_auth.py — HMAC-SHA256 over the uid, hmac.compare_digest, fail-closed 503 (unset secret) / 401 (missing, foreign, or tampered cookie), rpartition parsing 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) call require_settings_session before touching storage, and the AST wiring test pins that set so a future route can't silently miss the guard. /test-agent runs the guard above its broad try, so 401/503 reach the client as themselves.
  • README.md / .env.example — the deploy-order note (set GITHUB_SETTINGS_SECRET before 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):

  1. 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_identity for that uid, rebinding it to the attacker's own account. Comparing the numeric GitHub user id from get_user_info would close that. Impact today is limited (an attacker can only inject their own token), but this anchor backs the whole guard.
  2. 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.

@Git-on-my-level
Git-on-my-level dismissed their stale review October 24, 2026 06:25

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.

@1132dadf

Copy link
Copy Markdown
Contributor Author

Hi
Thanks again for reviewing and merging my PR.
Just a quick note regarding the payment/sponsorship: The previous PayPal account I provided was a Mainland China region account, which unfortunately has strict cross-border restrictions and cannot receive international personal transactions.
To make it easier for you, I have set up a new payment link via Ko-fi. You can now complete the payment using your Credit Card or an international PayPal account at:
👉 https://ko-fi.com/fengyuan_cn
Please kindly process the transfer from this new link. Let me know if you encounter any issues during the checkout.
Thanks for your support and time!
Best regards
FengYuan
If you prefer other payment methods, please let me know and we can figure it out.God bless you for your help.

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

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.

@Git-on-my-level
Git-on-my-level merged commit 5fe0b2d into BasedHardware:main Nov 8, 2026
41 checks passed
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 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.

[Security] omi-github-app: settings routes trust a bare uid — anyone can overwrite another user’s agent key, provider, or repo binding

3 participants