Repository navigation
fix(github-app): map internal exceptions to stable client errors and escape OAuth HTML (#13912) - #13912
Conversation
There was a problem hiding this comment.
3 issues found across 5 files
Confidence score: 2/5
.github/checks-manifest.yamlintroduces a check that will fail in the canonical CI environment before assertions run becauserequestsanddotenvare unavailable; stub those dependencies as intest_github_client.pyor provision the required plugin dependency.plugins/omi-github-app/github_client.pycan send an unsupportedstateasopenwhile labeling the response with the invalid original value, causing misleading results; reject invalid states or propagate the canonical state.plugins/omi-github-app/test_github_client.pyuses aFakeResponsethat always returns five items regardless ofper_page, so its headroom assertions cannot catch a regression; make the mock response depend on the requested page size.
You’re at about 95% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name=".github/checks-manifest.yaml">
<violation number="1" location=".github/checks-manifest.yaml:1000">
P1: This new check will fail in the canonical CI environment before running any assertions. Stub `requests` and `dotenv` in `test_issue_tools.py` like `test_github_client.py`, or otherwise provision the plugin requirements before invoking this manifest check.</violation>
</file>
<file name="plugins/omi-github-app/test_github_client.py">
<violation number="1" location="plugins/omi-github-app/test_github_client.py:206">
P2: This test cannot detect a regression in the headroom fix it claims to verify. The mock FakeResponse returns the fixed 5-item page regardless of the per_page request param, so the behavioral assertions (success=True, issues==[102,104]) pass identically whether list_issues requests 2 or 30 items per page; only the direct params assertion guards the headroom. It also never exercises the failure mode the PR targets: a page with more PRs than the limit, or a repo with more items than one page. list_issues makes a single non-paginated request capped at min(max(per_page*2,30),100), so when PRs dominate a page or items exceed one page it returns fewer than `per_page` issues while still reporting success=True — the same misleading short/empty result the PR aims to eliminate. Add a test where the mock honors per_page and the first fetched items are all PRs (more PRs than the limit), asserting the requested number of issues is still returned, plus a case with more items than fit in one page to document the single-page cap.</violation>
</file>
<file name="plugins/omi-github-app/github_client.py">
<violation number="1" location="plugins/omi-github-app/github_client.py:241">
P2: When an unsupported `state` reaches the endpoint, this request uses `open` but the tool labels the response with the original value. Reject invalid states or propagate the canonical state so results are not mislabeled.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| lanes: ["local", "ci"] | ||
| reason: "#13545: repository labels silently truncated at 100 because fetchers never followed next links; the suite asserts pagination and fail-closed item handling and must run in CI to catch a regression" | ||
| - id: github-app-issue-tools-tests | ||
| command: ["python3", "plugins/omi-github-app/test_issue_tools.py"] |
There was a problem hiding this comment.
P1: This new check will fail in the canonical CI environment before running any assertions. Stub requests and dotenv in test_issue_tools.py like test_github_client.py, or otherwise provision the plugin requirements before invoking this manifest check.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .github/checks-manifest.yaml, line 1000:
<comment>This new check will fail in the canonical CI environment before running any assertions. Stub `requests` and `dotenv` in `test_issue_tools.py` like `test_github_client.py`, or otherwise provision the plugin requirements before invoking this manifest check.</comment>
<file context>
@@ -996,6 +996,11 @@ checks:
lanes: ["local", "ci"]
reason: "#13545: repository labels silently truncated at 100 because fetchers never followed next links; the suite asserts pagination and fail-closed item handling and must run in CI to catch a regression"
+ - id: github-app-issue-tools-tests
+ command: ["python3", "plugins/omi-github-app/test_issue_tools.py"]
+ triggers: ["plugins/omi-github-app/**", ".github/checks-manifest.yaml"]
+ lanes: ["local", "ci"]
</file context>
| Returns dict with success status and list of issue dicts or error message. | ||
| """ | ||
| try: | ||
| valid_state = state if state in ("open", "closed", "all") else "open" |
There was a problem hiding this comment.
P2: When an unsupported state reaches the endpoint, this request uses open but the tool labels the response with the original value. Reject invalid states or propagate the canonical state so results are not mislabeled.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At plugins/omi-github-app/github_client.py, line 241:
<comment>When an unsupported `state` reaches the endpoint, this request uses `open` but the tool labels the response with the original value. Reject invalid states or propagate the canonical state so results are not mislabeled.</comment>
<file context>
@@ -218,29 +232,31 @@ def list_issues(
+ Returns dict with success status and list of issue dicts or error message.
"""
try:
+ valid_state = state if state in ("open", "closed", "all") else "open"
+ fetch_count = min(max(per_page * 2, 30), 100)
response = requests.get(
</file context>
| self.assertEqual(len(result["issues"]), 2) | ||
| self.assertEqual([i["number"] for i in result["issues"]], [102, 104]) | ||
| # Verify requested fetch count gives headroom to filter PRs | ||
| self.assertEqual(get.call_args.kwargs["params"]["per_page"], 30) |
There was a problem hiding this comment.
P2: This test cannot detect a regression in the headroom fix it claims to verify. The mock FakeResponse returns the fixed 5-item page regardless of the per_page request param, so the behavioral assertions (success=True, issues==[102,104]) pass identically whether list_issues requests 2 or 30 items per page; only the direct params assertion guards the headroom. It also never exercises the failure mode the PR targets: a page with more PRs than the limit, or a repo with more items than one page. list_issues makes a single non-paginated request capped at min(max(per_page*2,30),100), so when PRs dominate a page or items exceed one page it returns fewer than per_page issues while still reporting success=True — the same misleading short/empty result the PR aims to eliminate. Add a test where the mock honors per_page and the first fetched items are all PRs (more PRs than the limit), asserting the requested number of issues is still returned, plus a case with more items than fit in one page to document the single-page cap.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At plugins/omi-github-app/test_github_client.py, line 206:
<comment>This test cannot detect a regression in the headroom fix it claims to verify. The mock FakeResponse returns the fixed 5-item page regardless of the per_page request param, so the behavioral assertions (success=True, issues==[102,104]) pass identically whether list_issues requests 2 or 30 items per page; only the direct params assertion guards the headroom. It also never exercises the failure mode the PR targets: a page with more PRs than the limit, or a repo with more items than one page. list_issues makes a single non-paginated request capped at min(max(per_page*2,30),100), so when PRs dominate a page or items exceed one page it returns fewer than `per_page` issues while still reporting success=True — the same misleading short/empty result the PR aims to eliminate. Add a test where the mock honors per_page and the first fetched items are all PRs (more PRs than the limit), asserting the requested number of issues is still returned, plus a case with more items than fit in one page to document the single-page cap.</comment>
<file context>
@@ -186,6 +186,63 @@ def test_get_repo_labels_with_details_returns_empty_on_malformed_item(self):
+ self.assertEqual(len(result["issues"]), 2)
+ self.assertEqual([i["number"] for i in result["issues"]], [102, 104])
+ # Verify requested fetch count gives headroom to filter PRs
+ self.assertEqual(get.call_args.kwargs["params"]["per_page"], 30)
+
+ def test_list_issues_returns_error_dict_on_failure(self):
</file context>
|
Updated in 478ec2e:
All 15 manifest checks in |
|
Thanks @TheRWX — this is a solid, well-scoped fix. Reviewed each changed file: plugins/omi-github-app/main.py — plugins/omi-github-app/github_client.py — plugins/omi-github-app/test_github_client.py — good coverage of PR filtering, multi-page traversal (page params asserted), and error-dict returns on 401/403/404; the plugins/omi-github-app/test_issue_tools.py — hermetic production-handler suite with a clean stubbing harness; asserting .github/checks-manifest.yaml — the new Two non-blocking observations:
Both suites pass locally on this head and checks are green. Leaving for human maintainer review before merge. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
aryanorastar
left a comment
There was a problem hiding this comment.
Verified on 478ec2ecb519.
plugins/omi-github-app/main.py still interpolates str(e) into chat-tool errors, JSON error payloads, an HTTPException detail, and the OAuth HTML page (Failed to complete authentication: {str(e)}).
That is the same unauthenticated HTML/exception sink this repo has been closing elsewhere. Map failures to stable client errors; HTML-escape if anything must render. Head is also CONFLICTING — rebase after the sink is fixed. I am not merging.
…escape OAuth HTML (BasedHardware#13912) - Closes unauthenticated HTML and exception sinks in plugins/omi-github-app/main.py and github_client.py as requested in maintainer review. - Chat-tool endpoints (tool_create_issue, tool_list_repos, tool_list_issues, tool_get_issue, tool_list_labels, tool_add_comment, tool_code_feature) now map unhandled exceptions to stable client errors ("Failed to ... due to an internal error.") while preserving server-side traceback logging. - auth_start maps unhandled initialization exceptions to a generic HTTPException(500, detail="OAuth initialization failed"). - auth_callback error HTML page replaces str(e) interpolation with stable error prose, URL-encodes uid in retry and redirection links, and HTML-escapes reflected username. - JSON error endpoints (update-repo, refresh-repos, check-repo-access, save-agent-provider, save-agent-key, delete-agent-key, test-agent) return stable error messages instead of leaking str(e). - Root endpoint escapes uid in both unauthenticated and authenticated views. - github_client.py maps unexpected exceptions in create_issue and add_issue_comment to stable error responses. - Extends test_main.py (93/93 tests passing) and test_github_client.py (12/12 tests passing) with comprehensive regression coverage. Fixes BasedHardware#13911 Failure-Class: none PayPal: [email protected]
478ec2e to
59d0c98
Compare
|
Updated in
|
kodjima33
left a comment
There was a problem hiding this comment.
Fixes unauthenticated exception/HTML leakage in omi-github-app (str(e) reflected to clients, unescaped uid/username in HTML). Maintainer aryanorastar's CHANGES_REQUESTED review (submitted 15:01:51Z) was against an earlier commit; the current head (59d0c98, committed 15:34:48Z, after that review) removes all 18 remaining str(e) interpolations verified by direct diff/file inspection - the cited concern is resolved. Fixes #13911, 93+12+11 tests passing, CI green.
…chat tool responses (#15484) ## Summary `plugins/omi-shopify-app` returned raw exception text to its callers. The shared `shopify_api_request` helper answered any `requests` failure with `f"Request failed: {str(e)}"`, and all six chat-tool handlers answered any unhandled exception with `f"...: {str(e)}"`. ## Impact Whatever internal detail the exception carried — provider/socket errors, filesystem paths, connection details — was reflected back into the chat-tool response the OMI backend hands to the model/client. Same failure class as the recent ClickUp app (#15361 / #15360), Slack app (#15471 / #15469), Whoop app (#15477 / #15476) and GitHub app (#13912) hardening. ## Fix - `shopify_api_request`: logs `❌ Shopify API request failed: {e}` server-side and returns `{"error": "Shopify API request failed"}`. - `tool_get_analytics`, `tool_get_orders`, `tool_get_order_details`, `tool_create_order` (outer handler and the token-auth block), `tool_get_customers`, `tool_create_customer`: log the exception detail server-side and answer with a fixed, non-reflective message. No behavior changes other than the error text; success paths are untouched. ## Tests `plugins/omi-shopify-app/test_error_handling.py` (new, stdlib-only: `main.py` is loaded against stub `fastapi`/`requests`/`db`/`models` modules and the real handlers are driven against raising seams). It asserts a sentinel trace (`/srv/app/.secrets/shopify_token_store.json`, the exception class name, `Traceback`) never reaches a response for the API helper and each of the six tool endpoints, and pins that no `str(e)`/`str(exc)` response interpolation remains in `main.py`. Registered as `shopify-error-handling-tests` in `.github/checks-manifest.yaml`. ## Verification ``` python3 plugins/omi-shopify-app/test_error_handling.py # 8 passed python3 plugins/omi-shopify-app/test_limit_inputs.py # ok python3 plugins/omi-shopify-app/test_create_order_disambiguation.py # ok python3 plugins/omi-shopify-app/test_create_order_pagination.py # ok python3 plugins/omi-shopify-app/test_oauth_callback_auth.py # ok ``` Against `origin/main` `main.py` the new suite fails 8/8 (each response contains the sentinel trace). Failure-Class: none <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/15484?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
Summary
Remediates unauthenticated HTML and exception sinks in
plugins/omi-github-app/main.pyandplugins/omi-github-app/github_client.pyas requested in maintainer review (@aryanorastar):tool_create_issue,tool_list_repos,tool_list_issues,tool_get_issue,tool_list_labels,tool_add_comment,tool_code_feature) now map unhandled exceptions to stable client errors ("Failed to ... due to an internal error."), preventing rawstr(e)leakages while preserving server-side traceback logging.auth_startmaps unhandled exceptions toHTTPException(status_code=500, detail="OAuth initialization failed")without leakingstr(e).str(e)interpolation with stable client error text ("Failed to complete authentication. Please try again."), URL-encodesuidin retry links (quote(..., safe="")), and HTML-escapes reflected usernames.update-repo,refresh-repos,check-repo-access,save-agent-provider,save-agent-key,delete-agent-key, andtest-agentreturn stable error responses on unexpected failures.uidreflections across both unauthenticated and authenticated views and client-sidefetch()scripts.create_issueandadd_issue_commentto stable error dictionaries.Verification
python3 plugins/omi-github-app/test_main.py: 93 tests passing (20 new tests asserting stable error mapping, HTML escaping, and exception isolation).python3 plugins/omi-github-app/test_github_client.py: 12 tests passing (asserting stable error returns on exceptions).python3 plugins/omi-github-app/test_github_tools_auth.py: 11 tests passing.bash scripts/pr-preflight --lane ci --base upstream/main: All 17 manifest checks passed cleanly in 165.46s on commit59d0c98a45.Product invariants affected
none
Fixes #13911
Failure-Class: none
PayPal: [email protected]