Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port forwarded localhost translated to 127.0.0.1 when opened externally, breaks things like self-signed HTTPS #2711

Closed
Chuxel opened this issue Apr 8, 2020 · 8 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug remote-explorer verified Verification succeeded
Milestone

Comments

@Chuxel
Copy link
Member

Chuxel commented Apr 8, 2020

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.

@alirezanet
Copy link

I have the same problem. any update on this?

@aeschli
Copy link
Contributor

aeschli commented Sep 3, 2020

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)

@aeschli aeschli added the verification-found Issue verification failed label Sep 3, 2020
@aeschli aeschli reopened this Sep 3, 2020
@alexr00
Copy link
Member

alexr00 commented Sep 3, 2020

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?

@alexr00 alexr00 closed this as completed Sep 3, 2020
@alexr00 alexr00 removed the verification-found Issue verification failed label Sep 3, 2020
@aeschli
Copy link
Contributor

aeschli commented Sep 3, 2020

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

@alirezanet
Copy link

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

@chrmarti
Copy link
Contributor

chrmarti commented Sep 3, 2020

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/

@alirezanet
Copy link

alirezanet commented Sep 3, 2020

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

@alexr00 alexr00 added the verified Verification succeeded label Sep 4, 2020
@alexr00
Copy link
Member

alexr00 commented Sep 4, 2020

Verified by @aeschli

@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug remote-explorer verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

6 participants