Skip to content

fix(shipbob-app): serialize uid in inline script and url-encode links (#15014) - #15015

Open
kaleidoscopeAI wants to merge 5 commits into
BasedHardware:mainfrom
kaleidoscopeAI:fix/shipbob-app-script-xss-hardening
Open

kaleidoscopeAI wants to merge 5 commits into
BasedHardware:mainfrom
kaleidoscopeAI:fix/shipbob-app-script-xss-hardening

Conversation

@kaleidoscopeAI

@kaleidoscopeAI kaleidoscopeAI commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #15014

Summary

Harden the ShipBob app settings page and OAuth callback against script-context breakouts and attribute injection in plugins/omi-shipbob-app/:

  1. Script-context breakout in setup.html:
    uid: '{{ uid }}' in an inline <script> allowed single quotes to break out into JS syntax and </script> to terminate the script element in the HTML parser. Now safely JSON-serialized via json.dumps(str(uid)).replace("</", "<\\/") as const currentUid = {{ safe_uid_json|default('""')|safe }};.
  2. URL encoding and attribute breakout in links:
    Disconnect and Connect links now use safe_uid_param = quote(str(uid), safe='') and the /disconnect endpoint URL-encodes uid in its redirection header.
  3. Callback error reflection (regression guard only):
    handle_shipbob_callback already passes error through Jinja2 autoescape ({{ error }} in templates/setup.html), so this path was already neutralised on main. This PR adds a test asserting that guard stays in place rather than changing the callback code.

Verification

  • Added plugins/omi-shipbob-app/test_shipbob_security.py covering:
    • test_setup_escapes_script_tag_breakout_in_uid
    • test_setup_escapes_single_quotes_in_uid
    • test_setup_url_encodes_links
    • test_callback_escapes_error_message
  • Registered shipbob-app-security-tests in .github/checks-manifest.yaml.
  • All 88 unit tests in plugins/omi-shipbob-app pass.

Payment & Claim

Failure-Class: none

Review in cubic

@kaleidoscopeAI

Copy link
Copy Markdown
Contributor Author

💳 Bounty Disbursement Details

Upon review and merge, the bounty reward can be disbursed directly via:

Thank you!

Copy link
Copy Markdown
Contributor Author

@kodjima33 — requesting maintainer review of this ShipBob security fix. The PR includes the $75 bounty claim, security hardening, regression coverage, and Failure-Class: none. Please review the current head and merge if it satisfies the bounty requirements.

@Git-on-my-level Git-on-my-level added security-review Touches auth, provider routing, secrets, or security-sensitive surfaces python labels Sep 20, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Verified this end to end - the fix is correct and well-tested. Thanks for the clean security hardening.

Per-file notes:

  • plugins/omi-shipbob-app/main.py - safe_uid_json = json.dumps(str(uid)).replace("</", "<\\/") (line 430) is the right pattern: json.dumps closes the JS-string breakout (quotes, backslashes, control chars) and the </ replacement stops the HTML parser from terminating the inline <script>. safe_uid_param = urllib.parse.quote(str(uid), safe='') and the /disconnect redirect change (line 606) correctly percent-encode uid in hrefs and the Location header. One nit: import html (line 11) is unused now - feel free to drop it in a follow-up.
  • plugins/omi-shipbob-app/templates/setup.html - const currentUid = {{ safe_uid_json|default('""')|safe }} (line 404) is the correct way to inject server-sanitized JSON into a script context; the href changes at lines 398/459 are right (Jinja autoescape still applies on top of the percent-encoding). Nit: the |default(uid) fallbacks are dead since home() always passes the safe vars.
  • plugins/omi-shipbob-app/test_shipbob_security.py - good hermetic coverage of the three breakout classes (script-tag termination, quote breakout, URL encoding). I ran it plus the rest of the plugin suite in a clean venv with the pinned fastapi 0.111.1: 4/4 new and 88/88 total pass, matching your verification note. Minor: html and os imports are unused.
  • .github/checks-manifest.yaml - shipbob-app-security-tests entry is correctly registered (triggers, local+ci lanes, reason) and the command runs standalone.

One accuracy note on the description: summary item 3 ("guarded callback failure messages") has no corresponding code change - the diff doesn't touch handle_shipbob_callback. That path was already safe via Jinja2 autoescape on {{ error }} (templates/setup.html:349), so the new test is a welcome regression guard rather than a fix. No action needed, just keeping the changelog honest.

This touches the OAuth setup page of an auth flow, so I'm leaving the merge sign-off (and the bounty claim) to the maintainers.

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

@aryanorastar

Copy link
Copy Markdown
Collaborator

Verified on f12cf592afca.

Leaving this open as the unique remaining-hole vehicle (.github/checks-manifest.yaml, plugins/omi-shipbob-app/main.py, plugins/omi-shipbob-app/templates/setup.html, plugins/omi-shipbob-app/test_shipbob_security.py). unique shipbob uid serialize+tests remaining hole but 0 CI.

Not approving: hosted CI has not gone green on this SHA. kodjima APPROVE is not a merge. I am not merging.

Copy link
Copy Markdown
Contributor Author

Maintainer action requested: this ShipBob security fix has completed technical review, including uid serialization, URL encoding, and callback handling. Please review/merge if accepted and confirm the $75 bounty payout. Payout details can be provided privately.

@aryanorastar

Copy link
Copy Markdown
Collaborator

ShipBob setup on main still puts uid: '{{ uid }}' inside the inline script. This head JSON-serializes that uid. f12cf592afca conflicts and the only check is cubic, so rebase it. This stays open and unapproved.

— Astar, on behalf of @aryanorastar

@aryanorastar

Copy link
Copy Markdown
Collaborator

Keeping this open. Not approving f12cf592afca. origin/main plugins/omi-shipbob-app/templates/setup.html still has uid: '{{ uid }}' and /auth/shipbob?uid={{ uid }}. DIRTY and a single check (not approvable). mergeable: CONFLICTING/DIRTY

— Astar, on behalf of @aryanorastar

@kaleidoscopeAI

Copy link
Copy Markdown
Contributor Author

@aryanorastar — the DIRTY state you flagged is resolved.

51954fec is a merge commit (parents: this branch + main), so no history was rewritten and your reviewed commit is intact.

Conflict scope: .github/checks-manifest.yaml was the only overlapping file. Every other file in this branch is untouched by main. Resolution keeps main's manifest verbatim and appends this branch's check entry (shipbob-app-security-tests) at the end of the checks list — verified valid YAML, no duplicate ids, top-level keys still exactly {checks, exempt}.

CI: checks are now actually running on this head (Repo Checks, Hygiene, Formatting, Typecheck, backend shards). Hygiene, Formatting and Typecheck were all in flight when I looked. That should clear the 0-CI concern too.

mergeable is now true — previously CONFLICTING/DIRTY.

No assertion was weakened and no test was skipped; the branch head is otherwise byte-identical to what you verified on f12cf592afca.

Tree starts from main and applies this branch's changes on top, so every change main made since this branch was cut is preserved. Six plugin main.py files had moved on main; each was resolved as a real three-way merge (in omi-dropbox-app both sides touched the same disconnect href, keeping main's uid_q quoting and this branch's &sig=).

.github/checks-manifest.yaml resolved by keeping main's manifest verbatim and appending shipbob-app-security-tests at the end of the checks list. Valid YAML, no duplicate ids.
@kaleidoscopeAI
kaleidoscopeAI force-pushed the fix/shipbob-app-script-xss-hardening branch from aef91bc to 6a7bdbc Compare October 2, 2026 23:07
@kaleidoscopeAI

Copy link
Copy Markdown
Contributor Author

Correction: the merge I posted earlier was wrong — please use 6a7bdbce

My previous comment pointed at a merge built from a stale snapshot of this branch. It was broken: it dropped part of the PR and made ~1,488 unrelated main files look deleted. Do not merge it.

Use 6a7bdbcef5f119fed8858ed20e6bfe333a466d56. Parents: f12cf592 (this branch's pre-merge head) and 829727f2 (current main).

  • Tree starts from main; only this PR's own 4 changed paths are re-applied on top.
  • plugins/omi-shipbob-app/main.py had also moved on main, so it was resolved as a real three-way merge, not by taking either side.
  • .github/checks-manifest.yaml: main's manifest verbatim plus this PR's shipbob-app-security-tests id appended. 318 checks, no duplicate ids.

Verified on 6a7bdbce: 4 files — 1 added, 3 modified, 0 removed. python3 plugins/omi-shipbob-app/test_shipbob_security.py → 4/4 OK. No conflict markers.

Heads-up: #15667 and #15019 also touch omi-shipbob-app, so coordinate if both land.

…lane

The Hygiene lane installs only pyyaml, so `import main` died on
`from fastapi import Depends, FastAPI, HTTPException, Request, Query`
before any assertion ran. This registers stdlib stubs for fastapi,
fastapi.responses, fastapi.staticfiles, fastapi.templating,
fastapi.exceptions, requests, dotenv and pydantic in sys.modules before
loading main.py, mirroring plugins/omi-shipbob-app/test_main.py and
plugins/chatgpt/test_main.py. omi_plugin_sdk is MagicMock'd for the same
reason its own test_main.py does it: the SDK is first-party but imports
pydantic, which the lane also lacks.

jinja2 cannot be stubbed faithfully without writing a template engine, so
Jinja2Templates captures the render context instead and the assertions target
what main.py feeds the template: safe_uid_json, safe_uid_param, and the
wiring that keeps Jinja autoescape in charge of the error string (the error is
passed through untouched and {{ error }} must not gain a |safe filter). That
is exactly where this PR's escaping is enforced.

The assertions are load-bearing, not decorative: verified by mutation that
removing the '</' -> '<\/' escaping in safe_uid_json fails
test_uid_cannot_close_a_script_block, and dropping urllib.parse.quote from
safe_uid_param fails test_uid_is_url_encoded_in_action_links. Passes both
hermetically (stdlib + pyyaml only) and with fastapi/jinja2/pydantic
installed.
@kaleidoscopeAI

Copy link
Copy Markdown
Contributor Author

CI is green on this head — ready to merge.

Head: 7cc4cefdbdfac97d3b628d9ab808624e94330f05
Hygiene: success

Fix (plugins/omi-shipbob-app): the client-controlled uid was
reflected raw into the setup page — into href attributes, an inline JS
variable, and the disconnect redirect (reflected XSS).

  • safe_uid_json = json.dumps(uid).replace("</", "<\/") for the script
    context, safe_uid_param = urllib.parse.quote(uid, safe="") for URLs.
  • setup.html interpolates {{ safe_uid_param }} in the disconnect and
    auth hrefs and {{ safe_uid_json }} in the JS, never the raw uid.
  • The disconnect redirect percent-encodes the uid.

Tests (plugins/omi-shipbob-app/test_shipbob_security.py):

  • 4/4 in the dependency-free CI lane and 4/4 with real
    fastapi/jinja2/pydantic installed.
  • Hermetic stubs for fastapi, responses, staticfiles, templating, requests,
    dotenv, pydantic and the SDK, so the suite runs in CI.
  • Mutation-checked: reverting either the script escaping or the URL
    encoding causes a failure.

Registered in .github/checks-manifest.yaml (triggers on
plugins/omi-shipbob-app/**).

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @kaleidoscopeAI — reviewed file by file and ran the plugin's full test suite in a clean container: all 88 tests pass, including the 4 new hermetic security tests.

plugins/omi-shipbob-app/main.py — safe_uid_json = json.dumps(str(uid)).replace("</", "<\\/") plus safe_uid_param = urllib.parse.quote(str(uid), safe="") is the right shape: JSON round-trips the uid faithfully, and the </ escape blocks </script> termination even though the value is marked |safe. The added str() in the /disconnect redirect is a harmless robustness tweak. One nit: import html (line 11) is added but never used.

plugins/omi-shipbob-app/templates/setup.html — moving from uid: '{{ uid }}' to const currentUid = {{ safe_uid_json|default('""')|safe }}; fixes a real correctness bug beyond injection: with Starlette's Jinja environment (autoescape on by default), the old interpolation HTML-escaped the uid, so a uid containing & or quotes was posted to /select-channel in corrupted form. The |default(...) fallbacks also degrade safely in the callback renders, which don't pass safe_uid_*. For issue-triage context: because autoescape was already enabled, the </script>/quote breakout described in #15014 was already neutralized on main — the main value here is correct JSON serialization and explicit URL encoding rather than fixing an exploitable XSS.

plugins/omi-shipbob-app/test_shipbob_security.py — good hermetic design (stdlib-only stubs following the existing test_main.py pattern), and the assertions pin exactly the invariants this PR introduces, including the round-trip check that json.loads(safe_uid_json) still equals the original uid.

.github/checks-manifest.yaml — the new shipbob-app-security-tests entry is scoped correctly (plugin dir + manifest triggers, local+ci lanes).

One description/diff mismatch: the summary's item 3 ("guarded callback failure messages against unescaped markup") doesn't correspond to any change in the diff — handle_shipbob_callback still passes error through untouched, and the new test only asserts that autoescape stays applied. Please either drop that claim or add the actual guard, since #15014 lists error reflection as one of the items.

Given the security-review label and the linked bounty, this needs maintainer sign-off before merge.


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

The script-context hardening no longer uses html.escape; remove the dead
import flagged in review.
@Git-on-my-level

Copy link
Copy Markdown
Member

Reviewed the security hardening in plugins/omi-shipbob-app at head 3ae9ae2 — the approach is correct and well-executed. File-by-file:

  • plugins/omi-shipbob-app/main.py: json.dumps(str(uid)).replace("</", "<\\/") is the right pattern for embedding untrusted data in an inline <script> — it produces a valid JS string literal that cannot terminate the script element, and quote(str(uid), safe="") percent-encodes everything (including & and quotes) for URL/attribute contexts. The added str() in the /disconnect redirect is a harmless defensive touch.
  • plugins/omi-shipbob-app/templates/setup.html: |safe is now applied only to the pre-escaped JSON payload, never to raw uid; both action links use the encoded parameter with a safe default(uid) fallback. I confirmed no raw {{ uid }} interpolation remains in the template, and the callback/error render paths never pass uid at all.
  • plugins/omi-shipbob-app/test_shipbob_security.py: good hermetic design (stdlib-only, HTTP stubbed to refuse real requests), and the coverage note about asserting on template-context values rather than reimplementing Jinja is honest and reasonable. I ran the suite plus the existing plugin suites in isolation: 4/4 new tests pass, test_main.py 66/66, test_create_wro_disambiguation.py 7/7. (test_shipbob_tools_auth.py has 2 pre-existing errors from importing main without omi_plugin_sdk available — unrelated to this PR.)
  • .github/checks-manifest.yaml: registration of shipbob-app-security-tests matches the existing entries' shape (command, triggers, lanes, reason).

Thanks for the careful work and the honest framing that the callback error path was already neutralised by autoescape and is only pinned by a regression test. Since this touches an OAuth setup page and inline-script escaping, it should get a maintainer's security sign-off before merge — leaving for human maintainer review 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.

@Git-on-my-level Git-on-my-level added the positive-signal Automation verified a genuine fix/quality contribution label Oct 13, 2026
@kaleidoscopeAI

Copy link
Copy Markdown
Contributor Author

Gentle ping for maintainer review — this fix is verified end-to-end with the hermetic security test suite clean and green. Ready to land whenever convenient!

@Git-on-my-level

Copy link
Copy Markdown
Member

Since my last review: addressed — the only new commit since head 3ae9ae2 is a merge of upstream/main; the four PR-owned files are byte-identical to what I verified file-by-file, and hosted CI is now green on 3d99cc3 (Hygiene, Backend Hermetic Merge Gate, guard), which clears the no-CI and conflict blockers earlier reviews flagged · still open — nothing · newly introduced — nothing.

Verdict: the change is technically correct and, from a code-review standpoint, ready for a maintainer's security sign-off.

  • plugins/omi-shipbob-app/main.py — safe_uid_json = json.dumps(str(uid)).replace("</", "<\\/") and safe_uid_param = urllib.parse.quote(str(uid), safe="") are the right encodings for the two output contexts; the /disconnect redirect keeps full percent-encoding, so no header-injection character survives.
  • plugins/omi-shipbob-app/templates/setup.html — |safe is applied only to the pre-escaped JSON payload; both action links use the encoded parameter; no raw {{ uid }} interpolation remains. I re-confirmed current main still ships the raw script interpolation and unencoded hrefs (setup.html lines 398/410/458 on main), so this is not superseded.
  • plugins/omi-shipbob-app/test_shipbob_security.py — hermetic stdlib-only suite (the requests stub refuses real HTTP); assertions pin the script-termination, JS-string-breakout, and URL-encoding invariants plus JSON round-trip fidelity. (The PR body lists pre-rename test names; the file's current names differ — harmless.)
  • .github/checks-manifest.yaml — additive shipbob-app-security-tests entry matching the existing entries' shape; guard check green on this head.

Security: closes the script-context and attribute-injection paths on the OAuth setup page. As noted before, autoescape made the inline-script path corrupted-but-not-exploitable, so the practical gain is faithful uid round-tripping plus explicit context-correct encoding. Blast radius: ShipBob plugin setup page only.

USER IMPACT: ShipBob users whose uid contains special characters can now connect/disconnect and select channels correctly; otherwise no visible change.

Nothing further needed from review; the one optional cleanup is dropping the dead |default(uid) fallbacks in a follow-up. Leaving for human maintainer review — security sign-off on an OAuth setup page (and the linked bounty claim) is a maintainer decision.


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.

ShipBob setup.html still embeds uid in the inline script. This head JSON-encodes it and escapes </. test_shipbob_security.py pins a </script> uid. Hygiene and Backend Hermetic Merge Gate passed on 3d99cc39.

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

3d99cc39b81397b76b1079388a9521b41790e8d9

plugins/omi-shipbob-app/templates/setup.html — template falls open to raw uid.

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(shipbob-app): script-context breakout in uid and unescaped auth error reflection (5 proposed)

3 participants