Skip to content

fix(api): reject non-object JSON bodies across bridge, scraper detective, and x402 endpoints - #2269

Merged
Scottcjn merged 2 commits into
Scottcjn:mainfrom
Cid-oe:fix/bridge-detective-json-body-shape
Sep 18, 2026
Merged

Scottcjn merged 2 commits into
Scottcjn:mainfrom
Cid-oe:fix/bridge-detective-json-body-shape

Conversation

@Cid-oe

@Cid-oe Cid-oe commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #2262 and issue Scottcjn/rustchain-bounties#16976:
request.get_json(silent=True) or {} only replaces falsy parse results. Truthy non-dict JSON bodies (lists, numbers, strings, booleans) survive the or {} and trigger an unhandled 500 (AttributeError: 'list' object has no attribute 'get') when .get() is subsequently called on them.

This PR adds standardized object-body shape guards returning deterministic 400 with {"error": "JSON body must be an object"} across:

  1. wrtc_bridge.py:
    • POST /api/bridge/deposit
    • POST /api/bridge/withdraw (along with robust float conversion for amount)
  2. scraper_detective.py:
    • POST /api/admin/scrapers/block
    • POST /api/admin/scrapers/unblock
  3. bottube_x402.py:
    • POST /api/agents/me/coinbase-wallet

Verification

  • Added tests/test_json_object_body_guards.py covering all 5 endpoints against truthy non-dict JSON payloads ([1, 2, 3], "just-a-string", 42, 3.14, True).
  • 25/25 tests passing:
    pytest tests/test_json_object_body_guards.py -v -> 25 passed.
  • Regression suite passing:
    pytest tests/test_wrtc_bridge_py_debit_rtc_toctou_poc.py tests/test_scraper_detective_bt_proof.py -v -> 6 passed.

Disclosed wallet: RTC8b1fb717791b0a7b72649342b5c7c7bd822786af

@Scottcjn Scottcjn left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Approved. All 25 new tests fail on main and pass here. Note that only the x402 routes are live: wrtc_bridge.py and scraper_detective's scraper_bp aren't registered by bottube_server (it imports wrtc_bridge_blueprint), so most of this hardens code that isn't served. Still correct.

@Scottcjn
Scottcjn merged commit 3a64ae9 into Scottcjn:main Sep 18, 2026
6 checks passed
@Scottcjn

Scottcjn commented Sep 18, 2026 •

Copy link
Copy Markdown
Owner

RTC Reward (sent manually)

The automatic merge reward for this PR failed silently: our reward workflow's credentials had gone stale (being fixed now; failures are also now announced on the PR instead of passing silently). We've now paid it by hand: 2 RTC, pending_id 4671 (24h hold, then confirmed). Sorry for the delay, @Cid-oe, and thank you for the contribution. — Sophia Elya

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants