Repository navigation
fix(twitter-app): escape the state param reflected on the OAuth callback error page - #14352
Conversation
…ack error page
GET /auth/callback?code=x&state=<value> rendered its error page with
f'<a href="/auth?uid={state}">', so the attacker-controlled state query
param landed raw inside an HTML attribute. A state of
"><script>alert(1)</script> closed the attribute and executed as script
(reflected XSS), and & or # in the value corrupted the retry query.
The value is now percent-encoded for the query (urllib.parse.quote with
safe="") and HTML-escaped for the attribute, so the Try again link still
carries the original value but can no longer break out of the href.
Adds a hermetic regression test that stubs FastAPI and the sibling
modules, drives the real auth_callback handler down its error branch and
pins that no <script> element opens, the href is percent-encoded and the
uid round-trips; registered in .github/checks-manifest.yaml.
Verification:
- PYTHONUTF8=1 python3 plugins/omi-twitter-app/test_callback_error_escaping.py -> 4 tests passed
- same test against the previous main_simple.py -> 2 FAIL
(href="/auth?uid="><script>alert(1)</script>" reaches the page raw)
Failure-Class: none
…t link
GET /?uid=<value> built the "Connect Twitter Account" link as
f"/auth?uid={uid}" inside an href attribute, the same raw reflection the
callback error page had: a quote in uid broke out of the attribute (HTML
injection) and & or # corrupted the query. Percent-encode the value for
the query and escape it for the attribute, mirroring the callback fix.
Covered by a fifth case in test_callback_error_escaping.py that renders
the real root handler and pins the encoded, round-trippable href.
Verification:
- PYTHONUTF8=1 python3 plugins/omi-twitter-app/test_callback_error_escaping.py -> 5 tests passed
- same test against the previous commit -> FAIL test_setup_page_encodes_uid_in_connect_link: ['/auth?uid=']
Failure-Class: none
|
Thanks @Suyann — verified end to end; this is a clean fix for a real reflected XSS. The bug is real on main. Rendering the callback error page with the pre-fix Per file:
The description's scoping claims also check out: #13658's six-app sweep doesn't include Left for human maintainer review: this changes rendering inside the OAuth callback of a user-facing auth flow — worth a maintainer's sign-off before merge even though the fix itself looks correct. Automated maintainer-assistant feedback; final merge decisions rest with the human maintainers. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
…ts entry in a stable section Moves the checks-manifest.yaml entry out of the tail of the checks list, where several concurrent PRs insert at the same spot and every merge conflicts, into the stable section after desktop-backend-drift-fixtures. No behaviour change; the check still runs in both lanes with the same triggers.
|
Resolved the merge conflict: the only conflicting file was .github/checks-manifest.yaml (several PRs append at the same spot before exempt:). The entry is now registered in a stable section of the checks list (after desktop-backend-drift-fixtures) with the same command, triggers and lanes; no code change. The branch merges cleanly against current main (git merge-tree), the regression test passes, and pr-preflight passes locally. |
|
Follow-up verification on the current head (bfcaf7d):
No blocking concerns from my side; CI has not reported on this head, so the local run above is the execution evidence. Since this modifies an OAuth callback error path, leaving the merge sign-off to a maintainer. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
Conflict-free again: another PR landed at the manifest spot I had moved to, so the checks-manifest.yaml entry now sits next to the firestore checks (untouched on main). No code change; git merge-tree against current main is clean, the 5 hermetic tests pass, pr-preflight passes locally. Ready for the human sign-off flagged in the review. |
34b0694 to
b9cd46d
Compare
|
Correction to my previous note: that push still conflicted (the manifest section I had moved to changed on main in the meantime). The entry is now placed in a section verified untouched on main; git merge-tree against current main reports no conflict, tests 5/5, pr-preflight passes locally. Sorry for the noise. |
…ntry after diff-hygiene The previous locations (tail of the list, then after desktop-backend-drift-fixtures) collided with other PRs inserting at the same spots; this section is untouched on main. Same command, triggers and lanes; no behaviour change.
b9cd46d to
569c0f3
Compare
aryanorastar
left a comment
There was a problem hiding this comment.
Verified on 569c0f393f4c.
The OAuth callback error page percent-encodes state and HTML-escapes the Try-again href; the setup Connect link does the same for uid. twitter-app-callback-error-escaping-tests is registered. I ran that suite against this tip: 5/5 OK.
I am not merging.
What
The Twitter voice-posting plugin's OAuth callback error page (
plugins/omi-twitter-app/main_simple.py,GET /auth/callback) now percent-encodes and HTML-escapes thestatequery param before building its "Try again" link, instead of reflecting the raw value into anhrefattribute. Fixes #14350.Why
Any token-exchange failure renders the error page, and its link was
f'<a href="/auth?uid={error_uid}">'witherror_uid = state, wherestateisQuery(None)straight from the request. On currentmain:The quote closes the attribute and the script executes on the plugin's origin (reflected XSS). The branch is reachable without any session: a
statewith no stored OAuth handler makesget_access_token()raiseOAuth session not found, which is the path that renders the page. A benign&or#instatecorrupted the retry query the same way.The value is now encoded at both boundaries it crosses —
urllib.parse.quote(value, safe="")for the query,html.escape(..., quote=True)for the attribute — so the link still carries the original value (it round-trips throughparse_qs) but can no longer break out of thehref.Changes
plugins/omi-twitter-app/main_simple.py: importhtmlandurllib.parse.quote; the callback error page interpolateshtml.escape(quote(state, safe=""), quote=True).GET /?uid=built its "Connect Twitter Account" link asf"/auth?uid={uid}"inside anhref— the same raw reflection. Encoded the same way. omi-twitter-app is not among the six apps the pattern-wide PR fix(plugins): encode reflected uid in setup/auth pages across six apps #13658 covers; no overlap with that diff. Open PR fix(plugins): sanitize sensitive logging of tokens, credentials, and user data (#13777) #13782 also editsmain_simple.py, but only its logging lines (hunks atmainlines 222-231, 638-649, 665-671 and 697-752); this branch touches the import block,root()(main_simple.py:29-35) and theauth_callbackerror branch (:523-536), so the two do not overlap textually either.plugins/omi-twitter-app/test_callback_error_escaping.py(new): hermetic regression test — stubs FastAPI, dotenv and the sibling modules, drives the realauth_callbackhandler down its error branch and the realroothandler, parses the page withhtml.parserthe way a browser would and pins that no<script>element opens, thehrefis percent-encoded,&/#cannot corrupt the query, and the uid round-trips; plain and missingstatekeep their links unchanged..github/checks-manifest.yaml: registerstwitter-app-callback-error-escaping-tests(local + ci lanes, triggered byplugins/omi-twitter-app/**).Tests
Same test against
main'smain_simple.pyfails as intended (control cases pass):Also run:
python3 plugins/oauth/test_client_log_safety.py(OK, 5 tests),git diff --check main..fix/twitter-app-callback-xss(clean),bash scripts/pr-preflight --pr-body-file <this body>(passed). The live path (a real Twitter OAuth round trip on a deployed instance with client credentials) needs a Railway deployment and X app keys I do not have; the handlers were exercised through the hermetic harness above, which calls the real functions with only FastAPI and the network-bound siblings stubbed.Failure-Class
Failure-Class: none
(
scripts/failure-class preparevalidates the declaration (OK: prepare, patch operation=none) and none of the 253 registry definitions describes client input reflected unescaped into HTML; the advisory candidates it surfaced for this path — nonexecuting-verification-command, runtime-image-boundary, secret-printed-to-plugin-logs — do not apply.)Invariants
scripts/pr-preflight --suggestreports no affected product invariants for this diff (plugin-only change).Bounty
Claims the US$25 proposed in #14350; payout details will be sent to [email protected] after merge as the Contribution guide asks.
Authored with Claude Code on behalf of @Suyann; every command listed was actually run on this branch.