alibaba / alibaba/ROCK

Proxy: Custom port routing fails when connecting directly to host_ip:port

Open
#1,092 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
485
Forks
81
Avg merge
16h 12m
Merged PRs (30d)
8

Description

## Bug Description

When users specify a custom port (not the default 8080) in HTTP or WebSocket proxy requests via Path/Header/Query parameters, the proxy attempts to connect directly to `host_ip:{custom_port}`. This fails because arbitrary container ports are not mapped to the host network.

## Root Cause

In `sandbox_proxy_service.py`:
- `http_proxy()` line 939-946: When a custom port is specified, it constructs `target_url = f"http://{host_ip}:{port}/..."` directly
- `get_sandbox_websocket_url()` line 757-762: Same issue for WebSocket connections

However, only the default SERVER port (8080) is mapped from container to host. Custom ports like 9000, 3000 exist inside the container but are not accessible via `host_ip:9000` from outside.

## Expected Behavior

Custom ports should be routed through Rocklet (which runs on Port.PROXY=22555 and is mapped to host), since Rocklet lives inside the container and can access `localhost:{custom_port}`.

## Actual Behavior

Proxy attempts direct connection to unmapped host port, resulting in connection timeout/failure.

## Impact

Users cannot expose services running on non-8080 ports inside sandboxes to external clients, limiting the flexibility of the sandbox environment.

## Proposed Fix

1. Add proxy endpoints to Rocklet (`local_api.py`): `/proxy/{port}/{path}` for both HTTP and WebSocket
2. Modify `sandbox_proxy_service.py` to route custom ports through Rocklet's proxy port (22555) instead of direct connection
3. Keep default port (8080) using direct connection for backward compatibility

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in sandbox_proxy_service.py at http_proxy() and get_sandbox_websocket_url(), then inspect local_api.py and the existing Rocklet proxy setup. Confirm how custom ports currently form direct host URLs and route both HTTP and WebSocket requests through Rocklet, while preserving direct routing for port 8080.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.