Skip to content

fix(whoop-app): escape OAuth error parameter in callback failure page (#14603) - #14604

Merged
kodjima33 merged 4 commits into
BasedHardware:mainfrom
Mateidslx:fix/whoop-oauth-callback-error-xss
Sep 19, 2026
Merged

kodjima33 merged 4 commits into
BasedHardware:mainfrom
Mateidslx:fix/whoop-oauth-callback-error-xss

Conversation

@Mateidslx

@Mateidslx Mateidslx commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why

GET /auth/whoop/callback?error=... is an unauthenticated route. The current
main branch interpolates the error OAuth parameter directly into <p>{error}</p>
without html.escape, so an attacker can craft a URL that injects arbitrary
HTML/JS into the callback page (reflected XSS, no preconditions required).

Closes #14603

Fix

Two-line minimal change (stdlib only, zero new dependencies):

+import html
 ...
-                        <p>{error}</p>
+                        <p>{html.escape(error or "", quote=True)}</p>

Deconfliction

Open PR Sink covered Conflict?
#13658 uid in redirect URLs via quote() ✅ Different lines — no conflict
#14504 str(e) in except Exception block ✅ Different lines — no conflict

The sink ({error} in <p>) is not covered by either open PR.

Tests

New hermetic suite test_callback_error_escaped.py (stdlib only, no network, no FastAPI runtime):

$ python3 plugins/omi-whoop-app/test_callback_error_escaped.py
test_benign_error_still_renders .......... ok
test_breakout_payload_is_not_reflected_raw ok
test_double_quote_is_entity_encoded ...... ok
test_empty_string_does_not_crash ......... ok
test_escaped_representation_is_present ... ok
test_script_tag_is_not_in_output ......... ok

Ran 6 tests in 0.000s   OK
Test What it confirms
test_breakout_payload_is_not_reflected_raw Script tag cannot break out of <p>
test_script_tag_is_not_in_output Classic XSS payload neutralized
test_escaped_representation_is_present Error text still readable after escaping
test_benign_error_still_renders access_denied etc. pass through unchanged
test_empty_string_does_not_crash error or "" guard handles None/empty
test_double_quote_is_entity_encoded " becomes &quot; (attribute-safe)

Review in cubic

`GET /auth/whoop/callback?error=...` is unauthenticated. The current
`main` branch interpolates the `error` OAuth parameter directly into
`<p>{error}</p>` without `html.escape`, so an attacker can craft a URL
that injects arbitrary HTML/JS into the callback page (reflected XSS,
no preconditions).

Fix: add `import html` (stdlib, no new dependency) and replace
`<p>{error}</p>` with `<p>{html.escape(error or "", quote=True)}</p>`.

Deconfliction:
- PR BasedHardware#13658 encodes uid in redirect URLs (different sink, different lines)
- PR BasedHardware#14504 escapes str(e) in except block (different sink, different lines)
- This sink ({error} in <p>) is not covered by either open PR
Six stdlib-only tests confirm that the `error` OAuth parameter is
now HTML-escaped before insertion into <p>, and that benign error
codes still render correctly.
@Git-on-my-level Git-on-my-level added security-review Touches auth, provider routing, secrets, or security-sensitive surfaces python labels Sep 18, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Verified the fix and the diff shape on this head.

plugins/omi-whoop-app/main.py — the real change is exactly two lines: import html (line 8) and <p>{html.escape(error or "", quote=True)}</p> in the error branch of whoop_callback (line 1134). The diff shows ~2.7k changed lines only because the file was rewritten with CRLF line endings (base is all-LF); after normalizing line endings, the content diff is those two lines and nothing else. I also checked the rest of the callback handler: the other HTML branches render fixed strings, and the remaining interpolated value (uid in the success-page href) comes from the get_uid_from_oauth_state DB lookup rather than from the request — so this error reflection was the only unescaped request-sourced sink in the handler. If you push more commits anyway, restoring LF endings would keep blame/history clean, but that's cosmetic and not blocking.

plugins/omi-whoop-app/test_callback_error_escaped.py — hermetic and stdlib-only; I ran it locally and all 6 tests pass. One caveat worth knowing: _build_callback_error_html re-creates the template instead of importing main.py's handler (importing main.py would pull in db/fastapi/requests), so the suite pins the escaping pattern rather than the shipped line itself. Fine for a hermetic regression test; if you ever want it to guard the real handler, extracting the callback's error HTML into a small importable function would let the test exercise the production code path directly.

The deconfliction notes in the description check out: #13658 covers uid in redirect URLs and #14504 covers provider/exception strings in OAuth failure pages — neither touches this {error} sink.

This is a correct, minimal fix for a real reflected XSS on an unauthenticated route, with a clean write-up and a regression test — thank you. Since it modifies a security-sensitive OAuth callback, it needs maintainer sign-off before merge rather than automated approval.


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

@Mateidslx

Copy link
Copy Markdown
Contributor Author

Normalized line endings to LF — plugins/omi-whoop-app/main.py diff is now strictly +2/-1 lines. Thank you for the review!

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

Two-line reflected-XSS fix (unauthenticated route), well-tested, no CI gate. 5/5.

@Mateidslx

Mateidslx commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review and merge @kodjima33!

/claim #14603

Payout options for the $25 bounty:

Much appreciated!

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(whoop-app): error OAuth parameter reflected raw into callback HTML (reflected XSS, no preconditions) ($25 proposed)

3 participants