r/openbsd•
2kittens

httpd.conf defaults for unspecified requests

I run a couple of sites at home with the help of OpenBSD 6.5, httpd and letsencrypt. Situation: one.example.com and two.example.com both resolve to 192.0.2.1.

httpd.conf:

myip = "192.0.2.1"

server "default" {
  listen on $myip port 80
  block return 403
}

server "one.example.com" {
  listen on $myip port 80
  root "/htdocs/one.example.com"
}

server "two.example.com" {
  listen on $myip port 80
  block return 301 "https://two.example.com$REQUEST_URI"
  location "/.well-known/acme-challenge/*" {
    pass
    root "/acme"
    request strip 2
  }
}

server "two.example.com" {
  listen on $myip tls port 443
  root "/htdocs/two.example.com"
  tls {
    certificate "/etc/ssl/two.example.com.pem"
    key "/etc/ssl/private/two.example.com.key"
  }
}

When i go to http://192.0.2.1 i get served a 403 (default block). http://one.example.com serves its content correctly and so does http://two.example.com after redirecting me to https.

Next, when i go to https://192.0.2.1 i end up on https://two.example.com along with certificate warning. https://one.example.com also sends me to https://two.example.com. This is probably because it's the first tls block in my config? So how do i counter this correctly?

I tried putting a second "default" server block at the top of the config (see below) but it appears to require a tls {} part along with a certificate otherwise httpd won't respond to anything at all (even though it does start). I could add a self signed cert to make it work but i'm starting to wonder if i'm still on the right path here. I just want unspecified requests to be dropped or returned 403 (and not "leak" vhosts running on my ip because of how it selects what to serve by default). Any advice is appreciated.

server "default" {
  listen on $myip tls port 443
  block return 403
}

Posted Sep 28, 2019, 2:52 AM UTC

14
upofadown•

This is probably because it's the first tls block in my config?

I only see one tls block in your supplied config.

Added: Does httpd support SNI yet?

Added2: Yes, apparently httpd supports SNI.

1
gumnos•

And my understanding is that relayd will support SNI in the next release (already in -CURRENT). Very much looking forward to this.

edit: added link/citation

3
2kittensOP•

I only see one tls block in your supplied config.

Correct, only one of the vhosts serves tls, the other should not respond to it.

1
kgober•

For https, certificate validation is going to occur even before you find out what URL they are trying to connect to (in other words, the SSL session gets set up first, *then* within the secure session the client tells you what host/path they want). This means your server cert (which contains the vhost dns name) is going to leak information about what vhost you're serving unless it's a wildcard certificate.

To prevent https://one.example.com from serving anything useful, you could try putting a location clause inside your server "two.example.com" block, something kind of like this:

location "one.example.com/*" { block return 403 }

Or this:

location "two.example.com/*" { root "/htdocs/two.example.com" }
location * { block return 403 }

I haven't tried either of the above, the above suggestions were just from reading the httpd.conf man page. So I can't guarantee they actually work. Try them and see.

1