Skip to content

fix(whoop-app): escape callback error and quote uid across OAuth endpoints - #20399

Open
kaleidoscopeAI wants to merge 3 commits into
BasedHardware:mainfrom
kaleidoscopeAI:fix/whoop-app-security-encoding-v2
Open

kaleidoscopeAI wants to merge 3 commits into
BasedHardware:mainfrom
kaleidoscopeAI:fix/whoop-app-security-encoding-v2

Conversation

@kaleidoscopeAI

@kaleidoscopeAI kaleidoscopeAI commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #14890

Fresh branch off current main (d536878). The original branch was
cut from an older main and could no longer compute mergeability, so
its checks never ran; this rebase restores a clean merge base so CI
runs.

Summary

Hardens plugins/omi-whoop-app/main.py against reflected XSS and
parameter injection:

  1. HTML Escaping: escapes the error query parameter in the OAuth
    callback error box (safe_error = html.escape(error)) and the
    exception string in the OAuth exception handler
    (Authentication error: {safe_error}), plus isinstance(..., str)
    guards on the callback query params.

  2. URL Encoding & Attribute Escaping: quotes uid via
    quote(uid, safe='') in the connect link (auth_url), disconnect
    link, and continue-to-settings link; escapes every href attribute
    target with html.escape(..., quote=True); quotes uid in the
    /disconnect RedirectResponse.

  3. Hermetic Regression Suite: adds
    plugins/omi-whoop-app/test_settings_page_encoding.py (6 tests)
    covering connect-URL quoting, disconnect-link escaping, reflected
    callback-error escaping, callback-success URL quoting, exception
    message escaping, and redirect quoting. Registered as
    whoop-app-settings-encoding-tests in .github/checks-manifest.yaml.

Note on the manifest

Only whoop-app-settings-encoding-tests is registered. The
companion test_whoop_hardening.py does a bare from main import
that requires real fastapi/requests/dotenv, so it cannot run in the
hermetic pyyaml-only Hygiene lane; registering it would turn CI red.
The security fix itself is fully covered by the hermetic suite above.

Verification

  • 6/6 in the dependency-free CI lane (pyyaml only) - the suite stubs
    fastapi/requests/dotenv/db/models so it runs in the hermetic lane.
  • All whoop-triggered manifest checks pass (whoop-measurements-tests,
    whoop-weekly-summary-hardening-tests, whoop-app-settings-encoding-tests).
  • Mutation-checked: reverting the disconnect uid quoting fails
    test_disconnect_redirect_quotes_uid.

Review in cubic

Failure-Class: FC-oauth-error-params-reflected-into-html

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@kaleidoscopeAI
kaleidoscopeAI force-pushed the fix/whoop-app-security-encoding-v2 branch from 15c8b23 to 2e7a681 Compare October 3, 2026 02:52
@kaleidoscopeAI

Copy link
Copy Markdown
Contributor Author

CI is green on this head — ready to merge.

Head: 2e7a68102ec97899d1fa5e11ee0c37371a27027a
Hygiene: success

Fix (plugins/omi-whoop-app/main.py): HTML-escape the OAuth callback error parameter and the exception string (reflected XSS on an unauthenticated route), percent-encode uid with quote(uid, safe='') in the connect/disconnect/continue links and the /disconnect redirect, and escape every href attribute target. Resolves #14890.

Tests (plugins/omi-whoop-app/test_settings_page_encoding.py): 6 hermetic tests driving hostile error/uid values through the real handlers, asserting escaped forms, percent-encoding, and intact attributes — registered as whoop-app-settings-encoding-tests in .github/checks-manifest.yaml (triggers on plugins/omi-whoop-app/**).

Failure-Class: FC-oauth-error-params-reflected-into-html

Fresh branch off current main (d536878); supersedes #14891, whose branch was cut from an older main and could no longer compute mergeability, so its checks never ran.

@Git-on-my-level

Copy link
Copy Markdown
Member

Verified the security fix end to end and ran the new hermetic suite locally (6/6 passing) - nice work, and thanks for rebasing onto current main so CI could actually run.

Per-file notes:

  • plugins/omi-whoop-app/main.py - the real wins are the four quote(uid, safe='') sinks: the connect href (main.py:1054), the disconnect href (main.py:1097), the callback "Continue to Settings" href (main.py:1246), and the /disconnect RedirectResponse Location (main.py:1297). On current main these interpolate raw uid into URLs and href attributes, so this closes genuine parameter-injection/attribute-escape gaps. The exception handler (main.py:1282) now escapes str(e) before rendering into the 500 body - also a real reflected-content fix. One note: the safe_error hunk in the OAuth error box (main.py:1167) is behavior-neutral, since main already rendered html.escape(error or "", quote=True) and html.escape's default is quote=True - fine to keep, just flagging it's a refactor rather than a new fix. All quote() call sites are correctly guarded upstream (root() early-returns on missing uid; the callback resolves uid from the state store with its own guard), so no None-handling regressions.
  • plugins/omi-whoop-app/test_settings_page_encoding.py - solid hermetic design: framework-only doubles for fastapi/requests/dotenv/db/models matching the repo's hermetic lane pattern, with 6 tests covering each escaping sink including the redirect Location header. Ran it standalone: 6/6 pass.
  • .github/checks-manifest.yaml - registering only whoop-app-settings-encoding-tests is the right call; the pre-existing test_whoop_hardening.py does a bare from main import that needs real third-party deps, so registering it would break the hermetic lane.

Housekeeping: this supersedes #14891 (same change, older merge base) - a maintainer may want to close that one in favor of this.

Since this touches the OAuth/uid flow, leaving formal sign-off to a human maintainer; the security-sensitive auth-surface change needs maintainer review before merge.

Feedback generated by review automation 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.

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

Copy link
Copy Markdown
Member

Verified end-to-end against main @ d536878 — this is a complete, correct fix for the reflected XSS / parameter injection in #14890. Thank you for the clean rebase and the accurate manifest note.

Per file:

  • plugins/omi-whoop-app/main.py — every raw sink on main is closed at this head: the connect href (quote(uid, safe='') + html.escape(..., quote=True)), the disconnect href, the callback error box (html.escape(error) is the right form for element-text context), the Authentication error: exception path, the continue-to-settings href, and the /disconnect RedirectResponse now percent-encodes uid. I diffed head against main and found no remaining unescaped uid/error HTML sinks in the file (the ChatToolResponse(error=...) strings are JSON tool results, not HTML sinks). The isinstance(..., str) guards on callback params are harmless hardening.
  • plugins/omi-whoop-app/test_settings_page_encoding.py — real regression tests rather than behavioral stubs: the suite loads the production module with framework-only doubles and asserts both that the escaped form is present and that the raw payload is absent for all six sinks, including the redirect Location header. I ran it locally in a stripped, dependency-free environment: 6/6 pass (only the pre-existing datetime.utcnow DeprecationWarning noise).
  • .github/checks-manifest.yaml — correct hermetic-lane registration; the body's explanation for not registering test_whoop_hardening.py (its bare from main import needs real fastapi/requests/dotenv) checks out.

Relationship to #14891: I verified this branch carries the identical security changes (the test file is byte-identical; the escapes are unchanged) rebased onto current main, with the old branch's stale-base problem gone. Since #14891 was previously kept open deliberately as a landing vehicle, which PR lands is a maintainer call — once one is chosen, the other can be closed with credit.

This touches the OAuth callback/auth surface, so it needs maintainer sign-off before merge despite the verified fix; the positive signal stands.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

Match the notion-app hardening: a truthy non-string `error` was previously
ignored (`if error and isinstance(error, str)`) and could fall through to
token exchange when code/state were present. Treat any truthy error as
terminal and escape it when it is a string.

Add a regression test asserting no token exchange occurs for a non-string
error.
@Git-on-my-level

Copy link
Copy Markdown
Member

Reviewed this head in full (head 016ba1a) and ran the new hermetic suite locally — 7/7 pass.

plugins/omi-whoop-app/main.py

  • All three uid href sinks (connect link, disconnect link, continue-to-settings) now apply quote(uid, safe='') + html.escape(..., quote=True) — this closes the attribute-breakout/parameter-injection path, and the disconnect test asserts &test=1 becomes %26test%3D1.
  • /disconnect redirect percent-encodes uid; the OAuth exception handler escapes str(e).
  • The callback now fails closed on a non-string error and adds isinstance guards on code/state; the test confirms requests.post and get_uid_from_oauth_state are not called in that case. Nice catch.
  • I also swept the remaining interpolations: the other {str(e)} uses are ChatToolResponse JSON payloads, not HTML contexts, so leaving them unescaped is correct. root() returns JSON before any quote() when uid is missing, so no None path.

plugins/omi-whoop-app/test_settings_page_encoding.py — clean hermetic design: framework-only stubs, no third-party deps, no network, and assertions check both escaped output present and raw payload absent.

.github/checks-manifest.yaml — whoop-app-settings-encoding-tests registration matches the neighboring entry pattern, and the note about not registering test_whoop_hardening.py (needs real fastapi) is the right call for the hermetic lane.

Two small PR-description notes (non-blocking): main already escaped the callback error parameter before this change (html.escape(error or "", quote=True)), so the real delta there is the fail-closed guard; and the body says 6 tests while the suite has 7.

This is a genuine, well-tested hardening of a reflected-XSS surface — thank you. Since it modifies the OAuth callback/disconnect flow, I'm keeping security-review for a maintainer security sign-off on that flow before merge rather than sign-off from automation alone.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

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

On 016ba1aba6142e2585829039164b39f05d4a6c20, plugins/omi-whoop-app/main.py still returns html.escape(str(e)) in the callback 500. Use a fixed message.

@Git-on-my-level

Copy link
Copy Markdown
Member

The production change is correct, well scoped, and the fixed 500 message requested in the earlier maintainer review is now in place — leaving formal sign-off to a human maintainer since this is an auth-flow security fix.

plugins/omi-whoop-app/main.py

  • root() connect link: quote(uid, safe='') then html.escape(..., quote=True) — correct layering (percent-encode the query value, then escape for the attribute context); same treatment for the disconnect link and the callback "Continue to Settings" link.
  • whoop_callback(): a non-string error now fails closed with a fixed message instead of falling through to token exchange; string errors are escaped; code/state get isinstance guards.
  • The 500 handler now returns a fixed "Authentication error" and logs only the exception type — this resolves the specific change requested on the previous head (html.escape(str(e)) removed), and dropping traceback.print_exc() avoids leaking internals.
  • /disconnect redirect Location is now percent-encoded — closes header/parameter injection via a crafted uid.
  • I checked the rest of the module at this head: no remaining raw {uid}/{error} interpolation in HTML contexts (the remaining {e} uses are log lines and ChatToolResponse payloads).

plugins/omi-whoop-app/test_settings_page_encoding.py

  • 7 hermetic tests that load the production module with framework stubs; I ran the suite locally in a clean environment — 7/7 pass. The non-string-error test also asserts token exchange is never attempted, which is the right fail-closed check. Nit: the file is missing a trailing newline.

.github/checks-manifest.yaml

  • whoop-app-settings-encoding-tests registration matches the neighboring entries' shape; the stated reason accurately describes the suite.

Security: closes reflected-XSS and URL-injection paths in the Whoop OAuth plugin. UX: OAuth failures now show a generic message instead of raw exception text (the exception type is still logged server-side). Blast radius: plugins/omi-whoop-app only.

USER IMPACT: Whoop connect/disconnect pages can no longer be tricked into rendering attacker-controlled text or links via crafted uid/error parameters; OAuth errors show a clean generic message.

Nothing blocking from my side. Since the earlier human review was filed against a previous head and its specific concern is addressed here, leaving re-review and sign-off with the maintainer.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

This branch has not been deployed

No deployments
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.

[Bounty proposal] security(whoop-app): unescaped error reflection in OAuth callback and raw uid parameter injection ($75 proposed)

4 participants