Skip to content

fix(omi-github-app): resolve short repo names, sanitize inputs, and prevent null field crashes #14223

Closed

Description

@shuoYun114

Summary

plugins/omi-github-app has critical flaws in repository resolution, input sanitization, and response parsing:

  1. Short repo names / voice inputs cause downstream 404s: When users speak or pass short repository names (e.g. "omi" or "backend"), get_repo_for_request previously passed the raw single segment directly. Downstream API calls construct endpoints like /repos/omi/issues, causing 100% HTTP 404 errors.
  2. Ambiguity risks across orgs and forks: Multiple accessible repositories sharing the same short name lacked disambiguation guards, risking operations executing against unintended repositories.
  3. Unhandled TypeError on null fields: github_client.get_issue and list_issues read issue.get("labels", []) and issue.get("assignees", []). When GitHub returns explicit null for these fields, .get() returns None, causing TypeError: 'NoneType' object is not iterable in list comprehensions.
  4. Invalid format submissions in tool_create_issue: Non-list labels payloads (e.g. strings or null from LLMs) resulted in malformed requests and GitHub API 422 errors.
  5. Missing route alias: The Omi tool schema and conventions reference /tools/add_issue_comment, but only /tools/add_comment was bound, returning 404 for standard callers.
  6. URL parsing edge cases & SSH support: Bare split(":") allowed spoofed userinfo hosts in URLs, failed on single-segment URLs, and rejected standard [email protected]: SSH format.
  7. Storage corruption risk: save_users() in simple_storage.py used unbuffered non-atomic write without file locking, risking zero-byte corruption under concurrency.

Root Cause Analysis

  • get_repo_for_request: lacked resolution logic against user["available_repos"] and user["selected_repo"], and lacked whitelist validation (^[a-zA-Z0-9_.-]+$).
  • github_client.py: list comprehensions directly iterated over .get(..., []) without checking for None.
  • main.py:tool_create_issue: expected labels to strictly be a list, failing when strings or None were supplied.
  • simple_storage.py:save_users: used open(USERS_FILE, 'w') directly without tempfile + os.replace or concurrency locks.

Key Changes

  1. Strict Repository Resolution & Disambiguation (main.py):

    • Implemented _validate_owner_repo with strict regex whitelist (^[a-zA-Z0-9_.-]+$), blocking control characters (\n, \r, \t, \0), and forbidding . / ...
    • Added short-name resolution against available_repos and selected_repo with unambiguous match resolution, explicit candidate disambiguation errors, and substring matching threshold (len >= 3).
    • Robust URL handling using urllib.parse.urlparse checking parsed.hostname, blocking spoofed hosts, and supporting [email protected]: SSH URLs.
    • Enforced validation across /update-repo and tool_code_feature.
  2. Null-Safety in Client (github_client.py):

    • Replaced .get("labels", []) with (issue.get("labels") or []) guarded by isinstance(label, dict) and "name" in label.
    • Applied identical guards for assignees and user.
    • Replaced non-ASCII status log emojis (❌, ⚠️) with [ERROR] and [WARN] to prevent encoding crashes on Windows/ASCII environments.
    • Added explicit timeout=self.timeout across all requests network calls.
  3. Input Normalization & Route Aliasing (main.py):

    • Added string-to-list parsing for labels in tool_create_issue.
    • Added @app.post("/tools/add_issue_comment") route alias for full compatibility.
  4. Thread-Safe Atomic File Persistence (simple_storage.py):

    • Wrapped save_users() in threading.Lock() using temporary file creation and atomic os.replace.
  5. Test Suite & CI Manifest (test_main.py, checks-manifest.yaml):

    • Added 73 pure standard-library hermetic unit tests covering all resolution paths, injection attacks, null fields, route aliases, and endpoint contracts.
    • Updated .github/checks-manifest.yaml check definition; verified passing all 52 manifest check tests.

Bounty & Contributor Reward Proposal

US$50 Bounty + 1-PR Contributor DevKit Reward (@josancamon19 @kodjima33):

  • Bitcoin (BTC): 1NkUnv23H65ZYJn64pseAcWRA6sJitxh2f (Network: Bitcoin Mainnet)
  • Contact Email: [email protected]
  • Contributor Reward: Omi DevKit Device (Necklace / Glasses) under official Omi Contribution Guidelines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions