fix: restrict OTC bridge CORS origins#5063
Conversation
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
965fde8 to
0ad68ee
Compare
|
Follow-up: the first CI run exposed a test-harness collision, not a production failure. Another test module had left a Current head: Validation after the fix:
GitHub checks are now green on the updated head. |
loganoe
left a comment
There was a problem hiding this comment.
Approved. The change replaces the blanket CORS(app) with a restricted default allowlist, supports OTC_CORS_ORIGINS, and deliberately drops * entries so an accidental wildcard does not reopen the bridge.
Validation performed:
git diff --check origin/main...HEADpassedpython3 -m py_compile otc-bridge/otc_bridge.py tests/test_otc_bridge_query_validation.pypassedPYTEST_DISABLE_PLUGIN_AUTOLOAD=1 /tmp/review-5058-venv/bin/python -m pytest tests/test_otc_bridge_query_validation.py -qpassed (7 passed)- Loaded the app with real Flask-CORS and confirmed
https://bottube.ai/ configured trusted origins receiveAccess-Control-Allow-Origin, whilehttps://evil.examplereceives no CORS allow-origin header.
TJCurnutte
left a comment
There was a problem hiding this comment.
Approved after a focused review of this PR's diff against origin/main.
Scope checked:
- PR title: fix: restrict OTC bridge CORS origins
- Changed files: otc-bridge/otc_bridge.py, tests/test_otc_bridge_query_validation.py
- Review finding: Reviewed otc-bridge/otc_bridge.py, tests/test_otc_bridge_query_validation.py; diff adds regression test coverage.
Validation run locally from a clean checkout of pull/5063/head:
git diff --check origin/main...HEAD→ exit 0 (no output)python3 tools/bcos_spdx_check.py --base-ref origin/main→ exit 0 (BCOS SPDX check: OK)python3 -B -m py_compile otc-bridge/otc_bridge.py tests/test_otc_bridge_query_validation.py→ exit 0 (no output)python3 -B -m pytest tests/test_otc_bridge_query_validation.py -q→ exit 0 (7 passed, 1 warning in 1.34s)- Added-line secret-pattern scan → pass
I did not find a merge-blocking issue in this focused pass. The change is small enough to review directly, and the targeted gates above passed.
himanalot
left a comment
There was a problem hiding this comment.
Reviewed the OTC bridge CORS restriction.
The PR replaces the wildcard CORS(app) with a parsed allowlist, defaults to the two expected public origins, and filters out * entries from OTC_CORS_ORIGINS so wildcard-only or empty configuration falls back to restricted defaults. The tests cover the default and wildcard-env parsing behavior without depending on a real Flask-CORS installation.
I do not see a blocking issue in this PR.
jaxint
left a comment
There was a problem hiding this comment.
PR Review
✅ Approved
- Code is correct
- No obvious issues
- Good contribution
Thanks! 🙏
Reviewed by jaxint
HCIE2054
left a comment
There was a problem hiding this comment.
LGTM! Thanks for contributing!
Summary
Fixes #5054 by removing wildcard CORS from the OTC bridge.
What changed
https://bottube.aiandhttps://rustchain.org.OTC_CORS_ORIGINSas a comma-separated allowlist for deployments that need additional trusted origins.*entries and fell back to restricted defaults if the env value is empty or wildcard-only.Why
CORS(app)allowed any website origin to read OTC bridge API responses. The bridge exposes order/trade APIs, so keeping cross-origin access to trusted frontends only reduces CSRF-style and data-exposure risk for browser users.Validation
python -m pytest .\tests\test_otc_bridge_query_validation.py -q-> 7 passedpython -m pytest .\tests\test_otc_bridge_query_validation.py -q -k cors-> 2 passed, 5 deselectedpython -m py_compile .\otc-bridge\otc_bridge.py .\tests\test_otc_bridge_query_validation.py-> passedgit diff --check-> passedpython .\tools\bcos_spdx_check.py --base-ref origin/main-> BCOS SPDX check: OKotc-bridge/requirements.txt: allowed origin gotAccess-Control-Allow-Origin; unlisted origin got no CORS allow header.Note: the older
otc-bridge/test_otc_bridge.pysuite still has a Windows tempfile/SQLite teardown issue in this environment (PermissionErrordeleting the shared temp DB), which then causes cascading rate-limit failures. That appears independent of this CORS change.No production OTC bridge, live wallet, private key, token transfer, or destructive request was used.
Bounty #71 payout wallet if eligible:
RTCda4841be5b2d109da5d995fb864c09676bb5b7c7