Vscode-remote-release: Port forwarded localhost translated to 127.0.0.1 when opened externally, breaks things like self-signed HTTPS

Created on 9 Apr 2020  路  8Comments  路  Source: microsoft/vscode-remote-release

Issue Type: Bug

Extension version: 0.112.0
VS Code version: Code - Insiders 1.44.0-insider (2aae1f26c72891c399f860409176fe435a154b13, 2020-04-07T21:42:32.364Z)
OS version: Darwin x64 18.7.0
Remote OS version: Linux x64 4.19.76-linuxkit


System Info

|Item|Value|
|---|---|
|CPUs|Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz (8 x 2500)|
|GPU Status|2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off_ok
webgl: enabled
webgl2: enabled|
|Load (avg)|3, 3, 3|
|Memory (System)|16.00GB (0.10GB free)|
|Process Argv||
|Screen Reader|no|
|VM|17%|

|Item|Value|
|---|---|
|Remote|Dev Container: C# Sample|
|OS|Linux x64 4.19.76-linuxkit|
|CPUs|Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz (4 x 2492)|
|Memory (System)|3.85GB (0.19GB free)|
|VM|0%|


When clicking on a link in the terminal that contains localhost (e.g. https://localhost:5001), the local browser is always opened to 127.0.0.1 instead. You can also see this same behavior when using serverReadyAction in launch.json. The problem is that this can cause problems with things like self-signed HTTPS certs.

This likely happens for all remote extensions, but I encountered it with Remote - Containers:

Repro:

  1. Use Remote-Containers: Try a Sample... and select .NET Core
  2. Follow the directions to enable HTTPS in the sample here.
  3. Start debugging (F5)
  4. Click on http://localhost:5000 or https://localhost:5001 in the debug window

Expected: Web page appears
Actual: https://127.0.0.1:5001 is opened in the browser which results in a certificate error. If you change this to https://localhost:5001, everything works.

What should happen to avoid this is that "localhost" is preserved if localhost is in the URI and 127.0.0.1 is used instead if this was in the URI.

bug remote-explorer verified

All 8 comments

I have the same problem. any update on this?

Tried to verify in with the following steps:

  • Use Remote-Containers: Try a Sample... and select .NET Core
  • In the remote window, run F5
  • click https://localhost:5001 in the debug window

Browser opens on https://127.0.0.1:5001

Should be https://localhost:5001
(I skipped the container setup setup steps, but I assume to verify the issue that's not needed)

This is in the devcontainer.json for that sample:

    "forwardPorts": [5000, 5001],

which means that the containers extension is already forwarding them with 127.0.0.1. Can you try again, but before you F5 go to the forwarded ports view and Stop Forwarding those ports?

I confirm that when removing [5000, 5001] from the forwarded ports, the browser will open on https://localhost:5001.

I have very similar problem in Wsl2 not remote container's. should I create new issue ?

Updating this for "forwardPorts" in the devcontainer.json too.

@Alirezanet I see @alexr00's fix is in common code, you could try VS Code Insiders to check if it fixes your case too: https://code.visualstudio.com/insiders/

interesting... I did not changed anything and its working correctly in Vscode insiders.
thanks

Verified by @aeschli

Was this page helpful?
0 / 5 - 0 ratings