fix(explorer): restrict proxy endpoint to public read-only routes (#4904)#7789
Conversation
FakerHideInBush
left a comment
There was a problem hiding this comment.
Three concerns before merging:
1. Prefix matching with startswith over-matches — 'infos' also proxies infos_admin, 'api/miners' also proxies api/miners_backup, etc.
if not any(path.startswith(p) for p in ALLOWED_PREFIXES):Since this is an allowlist, over-matching is a security flaw. If the backing RustChain node ever adds an endpoint like /infos_private, /infos_admin, /api/miners_admin, or /api/miners_bulk_export, they would all be unintentionally proxied without any change to the allowlist.
Fix: require that the path either exactly equals the prefix or starts with prefix + '/':
ALLOWED_PATHS = {
"epoch", "health", "infos", "lottery",
"api/miners", "api/blocks", "api/state",
}
ALLOWED_PREFIXES = tuple(p + '/' for p in ALLOWED_PATHS)
if not (path in ALLOWED_PATHS or any(path.startswith(p) for p in ALLOWED_PREFIXES) or path.startswith('balance/')):
return jsonify({'error': 'Proxy access denied'}), 4032. ALLOWED_PREFIXES is re-built on every request — should be a module-level constant
Defining a tuple literal inside the route function allocates a new tuple object on every HTTP request. Since the allowlist never changes at runtime, move it to module scope alongside the existing NODE_API constant:
# Module level
_PROXY_ALLOWED_PREFIXES = (
"epoch", "health", "infos", "lottery", "balance/",
"api/miners", "api/blocks", "api/state",
)3. This PR addresses URL-path injection but not query-parameter injection — PR #7564 (same issue #4904, still open) covers the query-parameter side and should be noted here
PR #7564 (fix(#4904): close unauthenticated SSRF in keeper_explorer proxy) restricts which query parameter keys are forwarded to the upstream node. This PR restricts which URL paths are proxied. Both fixes are needed together to fully close issue #4904. Please add a reference to #7564 in the PR description so maintainers know to merge both (or confirm that #7564 is superseded by this approach).
385e955 to
d94ed9e
Compare
jaxint
left a comment
There was a problem hiding this comment.
Security Review
This PR implements a critical security fix for the proxy endpoint.
Security Analysis:
- SSRF Prevention: Adds ALLOWED_PREFIXES whitelist to restrict proxy access
- Whitelist Approach: Only allows safe public routes (epoch, health, infos, lottery, balance, api/miners, api/blocks, api/state)
- Admin Protection: Blocks access to sensitive endpoints (wallet/transfer, wallet/review, etc.)
- Clean Implementation: Returns 403 for disallowed paths with clear error message
Code Quality:
- Simple whitelist check before proxying
- No changes to core wallet/payout behavior
- Test updated to use allowed endpoint
Additional Changes:
- fetchall-ok annotations (consistent with other PRs)
- tkinter skip for test compatibility
- UTC timezone fix
✅ APPROVED - Essential security hardening.
RTC RewardThis merged PR earned 5 RTC — sent to |
Closes #4904
RTC wallet: RTCfe13452d122263caf633ab1876bd9631133b68b1
Changes
Security Impact
Testing