Skip to content

fix(github-app): require shared-secret auth on chat-tool routes - #15012

Merged
kodjima33 merged 2 commits into
BasedHardware:mainfrom
TheRWX:security/github-tools-auth
Sep 20, 2026
Merged

kodjima33 merged 2 commits into
BasedHardware:mainfrom
TheRWX:security/github-tools-auth

Conversation

@TheRWX

@TheRWX TheRWX commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #15010
/claim #15010

Summary

The server-to-server /tools/* chat-tool routes in plugins/omi-github-app accepted uid directly from unauthenticated JSON request bodies and performed authorized GitHub actions using the victim's stored OAuth credentials (SimpleUserStorage.get_user(uid)["access_token"]).

Any unauthenticated caller knowing or guessing a target user's uid could:

  • List all private and public repositories (POST /tools/list_repos)
  • List repository issues (POST /tools/list_issues)
  • Read full details of any repository issue (POST /tools/get_issue)
  • List repository labels (POST /tools/list_labels)
  • Post comments on issues under the victim's GitHub identity (POST /tools/add_issue_comment, POST /tools/add_comment)
  • Create issues in repositories under the victim's GitHub identity (POST /tools/create_issue)
  • Trigger AI agent coding tasks and PR creations using the victim's GitHub identity (POST /tools/code_feature)

Fix

Follows the maintainer-approved plugin shared-secret authorization pattern (established in #13685, #14455, and #14700):

  1. Added plugins/omi-github-app/github_tools_auth.py:
    • Enforces GITHUB_TOOLS_SECRET via Authorization: Bearer <secret> header or ?github_tools_token= query parameter fallback.
    • Constant-time comparison using hmac.compare_digest.
    • Fails closed with HTTP 503 if GITHUB_TOOLS_SECRET is unset or blank so endpoints are never left silently open in production.
    • Rejects unauthenticated or invalid tokens with HTTP 401.
  2. Applied dependencies=[Depends(require_github_tools_auth)] in plugins/omi-github-app/main.py across all 8 chat-tool routes:
    • POST /tools/create_issue
    • POST /tools/list_repos
    • POST /tools/list_issues
    • POST /tools/get_issue
    • POST /tools/list_labels
    • POST /tools/add_issue_comment
    • POST /tools/add_comment
    • POST /tools/code_feature
  3. Scope boundary preservation: Browser-facing setup and settings endpoints (/, /auth, /auth/callback, /setup-completed, /update-repo, /refresh-repos, /check-repo-access, /save-agent-provider, /save-agent-key, /delete-agent-key, /test-agent, /health, /.well-known/omi-tools.json, /manifest.json) are intentionally left unguarded to avoid functional UI regressions.
  4. Added hermetic test suite plugins/omi-github-app/test_github_tools_auth.py (10 tests) covering:
    • 503 when unconfigured or whitespace
    • 401 when missing, wrong bearer, wrong query token, or non-bearer scheme
    • Acceptance of valid Bearer header and valid query token
    • Route wiring verification ensuring all 8 chat-tool routes carry the dependency and browser setup routes do not.
  5. Registered github-app-tools-auth-tests in .github/checks-manifest.yaml.

Verification

All test suites pass standalone and under discovery:

python3 plugins/omi-github-app/test_github_tools_auth.py
# Ran 10 tests in 0.120s (OK)

python3 plugins/omi-github-app/test_main.py
# Ran 73 tests in 0.128s (OK)

python3 plugins/omi-github-app/test_github_client.py
# Ran 10 tests in 0.019s (OK)

python3 plugins/omi-github-app/test_create_issue_auto_labels.py
# Ran 5 tests in 0.441s (OK)

python3 -m unittest discover -s plugins/omi-github-app
# Ran 98 tests in 0.569s (OK)

python3 .github/scripts/test_run_checks.py
# Ran 53 tests in 8.022s (OK)

Failure-Class: none

Payout Details

Review in cubic

The server-to-server /tools/* chat-tool routes in plugins/omi-github-app
accepted uid directly from unauthenticated JSON request bodies and performed
authorized GitHub actions using the victim's stored OAuth credentials.

Requires callers to present GITHUB_TOOLS_SECRET via Authorization: Bearer
header or ?github_tools_token= query parameter. Fails closed (503) when unset,
401 on missing or invalid token. Preserves browser setup/settings endpoints
without auth to prevent functional regressions.

Failure-Class: none

@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 for this — the underlying issue is real, and the overall shape matches the shared-secret pattern we've merged for the other tool plugins (#13685, #14455, #14684, #14700). The /tools/* routes in plugins/omi-github-app/main.py do act on stored OAuth credentials with only a body-supplied uid, so closing that gap here is the right call, and I appreciate you catching that this app was left out of the earlier sweep. I verified the route wiring independently (all eight chat-tool routes guarded, browser/setup routes left open as intended) and ran the suites locally: test_github_tools_auth.py (10), test_main.py (73), test_github_client.py (10), test_create_issue_auto_labels.py (5) — all green, matching the PR description.

One blocking issue and one should-fix:

1. The import fallback fails open (blocking) — plugins/omi-github-app/main.py:

try:
    from .github_tools_auth import require_github_tools_auth
except (ImportError, AttributeError):
    try:
        from github_tools_auth import require_github_tools_auth
    except (ImportError, AttributeError):
        require_github_tools_auth = lambda request=None: None

If github_tools_auth.py is ever missing at runtime (partial deploy, packaging mistake), the module still boots and every /tools/* route silently loses its guard — exactly the exposure this PR exists to close. The merged precedents (notion/linear in #14455, shipbob in #14684) stop at two levels and let the import fail loudly. Please drop the third fallback so the guard fails closed at startup. Nothing depends on it: with the third level removed, all 98 tests still pass (I checked). The wrapped Depends import just above is also dead weight — the unwrapped from fastapi import FastAPI, ... on the preceding line already fails first if fastapi were absent — but that one is harmless.

2. Document GITHUB_TOOLS_SECRET (should-fix) — the .env block in plugins/omi-github-app/README.md doesn't mention the new secret. #14684 added both the env line and a short "Chat Tool Authentication" section to the shipbob README; doing the same here keeps docs moving with the code.

On github_tools_auth.py itself and the tests: no concerns. The guard mirrors mentor_webhook_auth.py (constant-time compare via hmac.compare_digest, 503 when unconfigured / 401 on invalid, Bearer header plus query-param fallback), and test_github_tools_auth.py covers both the unit behavior and the route wiring — the AST wiring test is a nice touch given the hermetic harness calls handlers directly. The github-app-tools-auth-tests entry in .github/checks-manifest.yaml is correctly registered with both lanes and matching triggers.

Note for maintainers: same deployment coordination as the earlier shared-secret rollouts — once this lands, GITHUB_TOOLS_SECRET must be configured on the service and the backend caller must present it, or the GitHub chat tools will (correctly) start failing closed. Since this is an auth-surface change, maintainer sign-off on the final shape before merge would be good.

🤖 Automated review on behalf of the maintainers.


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 python labels Sep 19, 2026
…ent secret

- Drop third import fallback in main.py so auth guard fails closed loudly if github_tools_auth cannot be imported.
- Document GITHUB_TOOLS_SECRET in README.md .env example and add Chat Tool Authentication section.
- Add test_import_fails_closed_without_noop_lambda_fallback in test_github_tools_auth.py.

Failure-Class: none
@TheRWX

TheRWX commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

Review Remediation: Fail-Closed Import Guard & Secret Documentation (Commit bbdf38125b)

Thanks @Git-on-my-level for the review. Addressed both items in commit bbdf38125b:

  1. Fail-Closed Import Guard (plugins/omi-github-app/main.py:20-23):

    • Dropped the third fallback (require_github_tools_auth = lambda request=None: None).
    • The import now stops at two levels (try: from .github_tools_auth ... except: from github_tools_auth ...), matching the merged precedent in fix(shipbob): require shared secret on chat-tool routes #14684 and failing loudly (ImportError) at startup if the module is ever absent.
    • Added unit test test_import_fails_closed_without_noop_lambda_fallback in plugins/omi-github-app/test_github_tools_auth.py asserting no no-op lambda fallback exists in main.py.
  2. Secret Documentation (plugins/omi-github-app/README.md:124-125, 190, 346-353):

    • Added GITHUB_TOOLS_SECRET to the .env example block and Railway dashboard environment variables list.
    • Added a dedicated "Chat Tool Authentication" section documenting token delivery via Authorization: Bearer <secret> header or ?github_tools_token= query parameter, explicit status code semantics (401 invalid/missing, 503 unconfigured), and the exemption boundary for browser setup/settings routes.

Verification

  • python3 -m unittest discover -s plugins/omi-github-app -p "test_*.py": Passed (99/99 tests OK).
  • scripts/pr-preflight --lane ci --base upstream/main --pr-body-file /tmp/pr_body.txt: Passed (17/17 manifest checks passed in 171.02s).

PayPal: [email protected]

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

Reviewed and approved by automated PR pipeline.

@kodjima33
kodjima33 merged commit 0cbf04a into BasedHardware:main Sep 20, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bounty proposal] security(github-app): require shared-secret auth on chat-tool routes ($50 proposed)

3 participants