omi icon indicating copy to clipboard operation
omi copied to clipboard

omi-twitter-app: reflected XSS — /auth/callback error page interpolates the raw `state` query param into its HTML ($25 bounty proposed)

Open Suyann opened this issue 2 months ago • 0 comments

Symptom

plugins/omi-twitter-app/main_simple.py → GET /auth/callback reflects the state query parameter, unescaped, into the HTML of its error page. Opening

https://<twitter-app-host>/auth/callback?code=x&state=%22%3E%3Cscript%3Ealert(1)%3C/script%3E

returns a 500 page whose markup is

<p><a href="/auth?uid="><script>alert(1)</script>">Try again</a></p>

so the script runs in the victim's browser on the plugin's origin (reflected XSS). The route is unauthenticated and the error branch is reachable by anyone: any state without a stored OAuth handler makes get_access_token() raise OAuth session not found, which is exactly the branch that renders the page. A benign & or # in state corrupts the retry link the same way.

Evidence

plugins/omi-twitter-app/main_simple.py:525-538 (current main):

    except Exception as e:
        error_uid = state if state else "unknown"
        return HTMLResponse(
            content=f"""
            ...
                    <p><a href="/auth?uid={error_uid}">Try again</a></p>

state is Query(None) straight from the request (main_simple.py:195); nothing between the query string and the f-string escapes it.

The setup page at GET /?uid= has the same shape (main_simple.py:32: auth_url = f"/auth?uid={uid}", interpolated into <a href="{auth_url}" class="btn">). PR #13658 fixes this pattern in six other plugin apps but does not touch omi-twitter-app.

Hermetic reproduction (stubs FastAPI and the sibling modules, drives the real auth_callback handler):

$ PYTHONUTF8=1 python3 plugins/omi-twitter-app/test_callback_error_escaping.py   # against current main
FAIL test_script_in_state_is_not_reflected_raw: ... <a href="/auth?uid="><script>alert(1)</script>">Try again</a> ...
FAIL test_try_again_link_round_trips_state: ('"><script>alert(1)</script>', '/auth?uid=')
FAIL test_setup_page_encodes_uid_in_connect_link: ['/auth?uid=']

Fix

Percent-encode the reflected value for the query (urllib.parse.quote(value, safe="")) and HTML-escape the result for the attribute (html.escape(..., quote=True)) on the callback error page, and the same on the setup page's Connect link (separate commit, same file). Plus a hermetic regression test that renders both pages through the real handlers and pins that no <script> element opens, the href is percent-encoded and the uid round-trips, registered in .github/checks-manifest.yaml. PR incoming.

Bounty

Per the Contribution guide ("No bounties available? … suggest your own"), proposing a US$25 bounty for this fix + regression test. cc @josancamon19 @kodjima33

Investigated and fixed with Claude Code on behalf of @Suyann; every command above was actually run.

Suyann avatar Sep 17 '26 15:09 Suyann