vscode-remote-release icon indicating copy to clipboard operation
vscode-remote-release copied to clipboard

Localhost links clicked in terminal are automatically forwarding ports (as User Forwarded)

Open DominikSerafin opened this issue 3 years ago • 4 comments

  • VSCode Version: 1.69.1 (Remote-Containers: v0.241.3)
  • Local OS Version: Windows_NT x64 10.0.19044
  • Remote OS Version: node:18.6-bullseye (https://hub.docker.com/_/node)
  • Remote Extension/Connection Type: Containers
  • Logs: N/A
  • Does this issue occur when you try this locally?: Not sure how to answer this
  • Does this issue occur when you try this locally and all extensions are disabled?: Not sure how to answer this

Steps to Reproduce:

  1. Open project in remote dev container.
  2. Follow 127.0.0.1 or localhost link with port that's shown in the integrated terminal.
  3. The port of clicked link will be forwarded as "User Forwarded".
    • If that port is already taken, then 1 will be added to it, (e.g. 9300→9301), which results in VSCode actually opening a different link that was clicked.

vscode-terminal-port-forward_zZTgaFFXoH

My devcontainer.json:

{
  "dockerComposeFile": "./docker-compose.yml",
  "service": "stack-core-express",
  "remoteUser": "root",
  "workspaceFolder": "/wd/stack-core",
  "customizations": {
    "vscode": {
      "settings": {
        "remote.autoForwardPorts": false,
        "remote.restoreForwardedPorts": false
      }
    }
  },
  "portsAttributes": {
    "9300": {
      "onAutoForward": "ignore"
    }
  }
}

Problem:

Inability to disable this behavior (I couldn't find any way) is troublesome and maybe even potentially insecure. Especially when the port is already forwarded outside dev container (e.g. via docker-compose).

DominikSerafin avatar Jul 20 '22 14:07 DominikSerafin

There is no setting to disable this behavior. I'll take it as a feature request to add a setting for it.

alexr00 avatar Jul 21 '22 11:07 alexr00

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 10 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

vscodenpa avatar Jul 21 '22 11:07 vscodenpa

This feature request has not yet received the 10 community upvotes it takes to make to our backlog. 10 days to go. To learn more about how we handle feature requests, please see our documentation.

Happy Coding

vscodenpa avatar Sep 10 '22 03:09 vscodenpa

:slightly_frowning_face: In the last 60 days, this feature request has received less than 10 community upvotes and we closed it. Still a big Thank You to you for taking the time to create this issue! To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

vscodenpa avatar Sep 20 '22 03:09 vscodenpa

This could be related to this issue https://github.com/microsoft/vscode/issues/161045 which also deals with "remote.autoForwardPorts": false being ignored regardless where it is set.

In my scenario I do not click on the link. However the CRA script npm run start which is react-scripts start automatically opens the browser at the link at which the webapp is served. It may be possible the CRA script triggers the same behavior in VS Code as described in this issue here.

In contrast, when I run up an expressjs webapp, it doesn't open the browser automatically. It prints the port at which it is listening, though. Still, in that case the port is not automatically forwarded as expected.

ManfredLange avatar Oct 23 '22 23:10 ManfredLange

Further to this, I just tested the following for a CRA webapp. I modified the start script as follows (in package.json):

{
   ...
   "start": "PORT=21017 BROWSER=none react-scripts start",
   ...
}

In this case the browser won't be opened and as a result the port won't be forwarded. This observation appears to support this issue. I wouldn't call it a feature request, though, but a bug since it appears to contradict the specs of devcontainer.json as published here. Officially VS Code supports those specs. The observed behavior, however, is not in line with those specs.

Here is the relevant section of the devcontainer.json file I'm using:

// See https://aka.ms/vscode-remote/devcontainer.json for format details.
{
   ...
   "settings": {
      "remote.autoForwardPorts": false,
      "remote.restoreForwardedPorts": false
   },
   "portsAttributes": {
      "0-65535": {
         "label": "Application",
         "onAutoForward": "ignore"
      }
   },
   "otherPortsAttributes": {
      "onAutoForward": "ignore"
   }
}

It'd be good if this behavior could be fixed. Thank you!

ManfredLange avatar Oct 23 '22 23:10 ManfredLange

The new setting is remote.forwardOnOpen.

alexr00 avatar Dec 07 '22 14:12 alexr00