IIS Express and Kestrel Debugging Ports May Bind to All Interfaces, Allowing LAN Access
0 reputation · 24 Mar 2024, 19:26 UTC
0 reputation · 24 Mar 2024, 19:26 UTC
Visual Studio launches IIS Express or Kestrel for local web projects, and the browser typically displays localhost.
The underlying socket may listen on 0.0.0.0, making the debugging endpoint reachable from any device on the same LAN.
Verification requires inspecting the site binding in the .vs folder’s applicationHost.config and confirming the listening address with netstat or Get‑NetTCPConnection, then testing access from another LAN machine.
Which IP address and Host header does the debugging port actually use? Can a remote LAN client retrieve the application via the computer’s LAN IP and port? Does the same behavior occur for both IIS Express and Kestrel launch profiles?
35775 reputation · 25 Mar 2024, 05:30 UTC
Whether a remote LAN client can access a debugging port depends on the specific launch profile used and the resulting socket binding. While the browser defaults to localhost, the underlying listener may be configured to accept traffic from any interface.
The IP address and Host header used depend on the server implementation:
.vs/config/applicationHost.config. A common default is *:port:localhost. The * indicates a wildcard IP binding (listening on all interfaces), but the localhost suffix acts as a Host header filter.launchSettings.json via applicationUrl. http://localhost:port binds strictly to the loopback interface. http://0.0.0.0:port or http://*:port binds to all IPv4 interfaces.Potentially, but it depends on the Host header. If a socket is bound to 0.0.0.0 (wildcard), the port is open to the LAN. However, if the server is configured to only respond to Host: localhost (common in IIS Express), a remote client requesting http://[LAN-IP]:port will likely receive a 400 Bad Request or a 404, because the browser sends the LAN IP as the Host header, not localhost.
The behavior is not the same for both profiles:
| Feature | IIS Express | Kestrel (Default) |
|---|---|---|
| Default Binding | Often wildcard (*) |
Usually loopback (localhost) |
| Host Header Check | Strictly enforced via config | Generally permissive unless middleware is added |
| LAN Reachability | Socket open, but Host header often blocks | Socket usually closed to LAN entirely |
To confirm if your specific environment is exposed, use these scoped commands:
0.0.0.0 (All) or 127.0.0.1 (Loopback):Get-NetTCPConnection -LocalPort [YourPort] | Select-Object LocalAddress, LocalPort, State
.vs/config/applicationHost.config for IIS Express bindings or launchSettings.json for Kestrel applicationUrl.http://[Your-LAN-IP]:[Port].Required Diagnostic Detail: To provide a definitive answer for your specific case, please provide the exact binding string found in your applicationHost.config or launchSettings.json.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.