Skip to content

fix(whoop-app): prevent internal exception text from leaking into HTTP responses - #15476

Closed
Evos09 wants to merge 1 commit into
BasedHardware:mainfrom
Evos09:fix/whoop-app-exception-leaks
Closed

Evos09 wants to merge 1 commit into
BasedHardware:mainfrom
Evos09:fix/whoop-app-exception-leaks

Conversation

@Evos09

@Evos09 Evos09 commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Remediates sensitive exception leakage across HTTP and Chat-Tool response boundaries in plugins/omi-whoop-app:

  1. OAuth Initialization (/auth/whoop): Encapsulates state generation and storage in a protected execution block. Unexpected exceptions raise HTTPException(status_code=500, detail="OAuth initialization failed") instead of leaking internal trace or database errors.
  2. OAuth Callback (/auth/whoop/callback): Encapsulates state retrieval, state deletion, and token exchange inside a unified try-except block. Replaced raw Authentication error: {str(e)} HTML reflection with a styled, safe error card (get_css()) returning HTTP 500, preventing XSS and internal exception leakage.
  3. Whoop API Helper (whoop_api_request): Replaced {"error": str(e)} with sanitized {"error": "Whoop API request failed"} to ensure network socket errors, internal IPs, and credentials do not propagate to callers.
  4. Chat-Tool Routes (7 endpoints): Sanitized exception handling across all 7 LLM chat tools:
    • /tools/get_recovery
    • /tools/get_strain
    • /tools/get_sleep
    • /tools/get_workouts
    • /tools/get_weekly_summary
    • /tools/get_body_measurements
    • /tools/get_profile
      All tool endpoints now return fixed, stable ChatToolResponse(error="Failed to get <feature> due to an internal error.") while maintaining server-side error logging.
  5. Hermetic Regression Suite: Added test_error_handling.py covering all 9 endpoints/methods with sensitive trace injection assertions, registered in .github/checks-manifest.yaml.

Verification

  • python plugins/omi-whoop-app/test_error_handling.py: 10/10 passing.
  • Full Whoop suite: 44/44 passing across all 6 test suites (test_callback_error_escaped.py, test_error_handling.py, test_get_workouts.py, test_main.py, test_measurements_and_summary_hardening.py, test_weekly_summary.py, test_whoop_hardening.py).
  • Manifest check validation: test_run_checks.py passing (53 tests passed, 0 failures).

Failure-Class: none

Bounty Payout Destination (EVM - Base Mainnet):
0x7badCdA295Dd7113f374aEA1008e7d5870D48556

Review in cubic

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

Well-scoped fix: replaces raw exception string leakage with generic client-facing messages while preserving server-side logging, across OAuth and 7 chat-tool endpoints. Test suite added and error paths correctly wrapped. Confidence 5/5.

@Git-on-my-level Git-on-my-level added python security-review Touches auth, provider routing, secrets, or security-sensitive surfaces positive-signal Automation verified a genuine fix/quality contribution labels Sep 21, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @Evos09 — focused, well-scoped hardening pass. I verified the change end to end and ran the new suite; two small non-blocking notes below.

Verification

  • Reviewed all three changed files (plugins/omi-whoop-app/main.py, plugins/omi-whoop-app/test_error_handling.py, .github/checks-manifest.yaml).
  • Ran python3 plugins/omi-whoop-app/test_error_handling.py in a clean container: 10/10 pass in an environment where requests is importable (as in CI).

What's good

  • All seven chat-tool handlers (/tools/get_recovery, /tools/get_strain, /tools/get_sleep, /tools/get_workouts, /tools/get_weekly_summary, /tools/get_body_measurements, /tools/get_profile) now return fixed Failed to get <feature> due to an internal error. strings while the real exception still reaches server-side log(...) — debuggability preserved.
  • whoop_api_request no longer echoes str(e) (which can embed URLs/socket details) into caller-visible dicts.
  • The callback's Authentication error: {str(e)} HTML reflection — the worst leak here, writing exception text into an HTML body — is replaced by a static styled error card with HTTP 500.
  • Control-flow check: all explicit early returns in whoop_callback (expired state, missing code/state, token-exchange failure, missing access token) still run outside any exception conversion, and no HTTPException is raised inside the new unified try, so no status-code semantics changed.

Two small notes (non-blocking)

  1. In test_error_handling.py, test_whoop_api_request_sanitizes_raw_exception patches "requests.request" on the real requests module, but main.py was loaded with a fake requests module injected via patch.dict(sys.modules, ...), so the injected RuntimeError(self.sensitive_leak) never fires — the test actually passes because the fake stub returns None and response.status_code raises AttributeError into the new except. The assertion still guards the except-path, but patching the module the code actually uses (e.g. patch.object(app.requests, "request", ...)) would make the test do what it says.
  2. The suite docstring says "standard library only", but that same patch("requests.request") needs the real requests package importable — in a stdlib-only environment the test errors with ModuleNotFoundError. Harmless in CI where the plugin's deps exist; just noting the "hermetic" claim isn't literal.

Optional follow-up (pre-existing, not from this PR): the callback's token-exchange failure responses (Token exchange failed: {status_code}, No access token received) are still unstyled plain text — reusing the error card there would be a nice consistency win.

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

@Evos09

Evos09 commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @kodjima33 and @Git-on-my-level for the thorough review and approval! Rebased onto current main to resolve the .github/checks-manifest.yaml merge conflict and addressed the test note by switching to patch.object(app.requests, 'request', ...) with persistent stub registration. Verified under python -S: 10/10 tests passing hermetically.

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

Whoop on main still returns str(e) from the API helper, chat tools, and OAuth HTML. This head clears those and the tests pin recovery, strain, and OAuth. Hygiene is green on 35f6015bb815.

aryanorastar added a commit that referenced this pull request Sep 22, 2026
…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. -->

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

Verified: whoop-app OAuth+7 chat-tool handlers now return generic error text, raw exceptions only logged server-side; new test_error_handling.py asserts sensitive strings never leak. Scoped, real root cause. 5/5.

@aryanorastar

Copy link
Copy Markdown
Collaborator

Whoop on main still returns str(e). 35f6015bb815 clears those returns and is DIRTY against main. Rebase before approval.

— Astar, on behalf of @aryanorastar

…P responses

- Hide raw str(e) from /auth/whoop and whoop_api_request exception handlers
- Return generic 'Failed to get ... due to an internal error.' across 7 chat tool endpoints (recovery, strain, sleep, workouts, weekly summary, body measurements, profile)
- Sanitize whoop_callback OAuth error page to render themed error template without leaking raw exception string
- Encapsulate state lookup and code exchange in whoop_callback within unified try-except block
- Add hermetic stdlib-only unit test suite test_error_handling.py and register in .github/checks-manifest.yaml

Failure-Class: none
@Evos09
Evos09 force-pushed the fix/whoop-app-exception-leaks branch from 35f6015 to f33c207 Compare September 23, 2026 03:33
@aryanorastar

Copy link
Copy Markdown
Collaborator

Keeping this open on f33c207.

Whoop on main still returns {"error": str(e)} and the chat tools interpolate {str(e)}. This head returns Whoop API request failed and fixed chat-tool strings. Desktop Swift is still queued, so merge is UNSTABLE.

Not approving this SHA.

— Astar, on behalf of @aryanorastar

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

Whoop still returns {"error": str(e)} and chat tools interpolate {str(e)}. This head returns Whoop API request failed and fixed chat-tool strings. Tests load main.py. Hygiene passed on f33c207ba954.

@Git-on-my-level

Copy link
Copy Markdown
Member

Verified on this head — solid, well-scoped hardening pass. Detail for the record:

  • plugins/omi-whoop-app/main.py — all 7 chat-tool endpoints (/tools/get_recovery, get_strain, get_sleep, get_workouts, get_weekly_summary, get_body_measurements, get_profile) now return fixed "Failed to get due to an internal error." messages while keeping full detail in server-side logs; whoop_api_request returns a generic "Whoop API request failed" instead of str(e), so socket errors, internal addresses, and credential fragments no longer propagate; /auth/whoop wraps state generation/storage and raises a clean 500 "OAuth initialization failed"; /auth/whoop/callback replaces the reflected Authentication error: {str(e)} body — which was both an info leak and an unescaped-HTML vector — with a styled error card at 500. The refactor folding state lookup/deletion/token exchange into one try block preserves the early-return "Session Expired" (400) path.
  • plugins/omi-whoop-app/test_error_handling.py — hermetic stdlib-only suite (fastapi/db/models stubbed) with a sensitive-string canary (/var/secrets/... 10.0.0.1:8080) asserted absent from every response surface, including component checks ("/var/secrets", "whoop_privkey", "10.0.0.1"). Ran it locally: 10/10 pass.
  • .github/checks-manifest.yaml — registers the suite as whoop-error-handling-tests with local+ci lanes, matching the existing slack/notion plugin-check pattern.

One minor non-blocking note: the fixed whoop_api_request error string means chat-tool errors can no longer distinguish e.g. rate-limiting from an outage ("Failed to get recovery: Whoop API request failed"). If richer user-facing diagnostics matter later, a safe error-code field alongside the generic message would be the way to add it back.

Nice work — thanks for the careful remediation.

— automated maintainer review, posted on behalf of the Omi 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.

@Evos09

Evos09 commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Closing and withdrawing this pull request. Our prior 7 merged contributions totaling $350 (Support Tickets #141289328 / #141291126) remain unpaid by BasedHardware. We are freezing all pending contributions.

@Evos09 Evos09 closed this Oct 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hey @Evos09 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

positive-signal Automation verified a genuine fix/quality contribution 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.

4 participants