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

Listen to localhost, handle request with arbitrary Host headers #165

Closed
MrDigit opened this issue Jun 10, 2018 · 6 comments
Closed

Listen to localhost, handle request with arbitrary Host headers #165

MrDigit opened this issue Jun 10, 2018 · 6 comments
Labels

Comments

@MrDigit
Copy link

MrDigit commented Jun 10, 2018

Hello,

I want that embedio bind to localhost interface, (URL prefix: http://localhost:12345) but it should handle all incoming requests, independent of the host header.

Currently, if the host header is not localhost (i.e. 127.0.0.1 or something different) it doesn't handle the request.

Is this feature, a bug, my fault ?

Best regards
MrDigit

@MrDigit MrDigit changed the title Listen to localhost, handle request with arbitryry Host: headers Listen to localhost, handle request with arbitrary Host headers Jun 10, 2018
@geoperez
Copy link
Member

This is not a bug, this is how Httpsys works. If you change your binding to http://+:12345 you can connect using localhost or 127.0.0.1.

Some useful links:

https://www.codeproject.com/Articles/437733/Demystify-http-sys-with-HttpSysManager
https://msdn.microsoft.com/en-us/library/windows/desktop/aa364698(v=vs.85).aspx

@MrDigit
Copy link
Author

MrDigit commented Jun 11, 2018

Strong binding with "+" understood, But when using "http://+:12345" the webserver binds to 0.0.0.0.

My goal: bind to localhost, serve all requests.
Any hints to to achieve this ?

@geoperez
Copy link
Member

Yeah, because 0.0.0.0 is a placeholder to say anything is valid.

I'm not understanding, why don't you use '+' or '*'? Is it because of permissions?

@MrDigit
Copy link
Author

MrDigit commented Jun 11, 2018

For security reasons embedio should listen only on internal loop interface but should handle requests independently of the Host-Header (another process forwards external HTTP requests to embedio that listens on localhost):

What I tried:

  1. If I use http://+:12345 or * it listens to 0.0.0.0 and it handles all requests as wanted, not 100% what I want as I want it to listen only on loopback.
  2. If I use http://localhost:12345 it listens to loopback as wanted but handles only requests which have "localhost" in the Host-Header field.

Is there a simple solution for what I want ?

@geoperez
Copy link
Member

You can add both loopback in the WebServer constructor:

var server = new WebServer(new [] { "http://localhost:8787/", "http://127.0.0.1:8787/" });

@willks
Copy link

willks commented Sep 19, 2020

Yeah, because 0.0.0.0 is a placeholder to say anything is valid.

I'm not understanding, why don't you use '+' or '*'? Is it because of permissions?

2+ years later, I am deploying EmbedIO into docker for a health check for a console C# dotnetcore app. I had issues with binding to http://0.0.0.0:, but once I set my config to use http://*: - my app finally started working with Kubernetes. Yes, 2 years late but I only started with the dotnet world 2 weeks ago.

Good framework really! Very light (bah, lite) framework. Hardly added anything to my Docker image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants