Skip to content

Unix socket admin endpoint doesn't accept "localhost" as host name. #6832

@NiklasBeierl

Description

@NiklasBeierl

Hey everyone,

the documentation states:

origins configures the list of origins that are allowed to connect to the endpoint.
A default is intelligently chosen:
if the listen address is loopback (e.g. localhost or a loopback IP, or a unix socket) then the allowed origins are localhost, ::1 and 127.0.0.1, joined with the listen address port (so localhost:2019 is a valid origin).

However, it seems like localhost as hostname gets rejected:

/etc/caddy # caddy --version
v2.9.1 h1:OEYiZ7DbCzAWVb6TNEkjRcSCRGHVoZsJinoDR/n9oaY=
/etc/caddy # curl --version
curl 8.12.0 (x86_64-alpine-linux-musl) libcurl/8.12.0 OpenSSL/3.3.2 zlib/1.3.1 brotli/1.1.0 zstd/1.5.6 c-ares/1.33.1 libidn2/2.3.7 libpsl/0.21.5 nghttp2/1.62.1
Release-Date: 2025-02-05
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp ws wss
Features: alt-svc AsynchDNS brotli HSTS HTTP2 HTTPS-proxy IDN IPv6 Largefile libz NTLM PSL SSL threadsafe TLS-SRP UnixSockets zstd
/etc/caddy # echo $CADDY_ADMIN
unix//var/run/caddy.sock
/etc/caddy # caddy reload
2025/02/09 19:22:57.702 INFO    using adjacent Caddyfile
2025/02/09 19:22:57.703 INFO    adapted config to JSON  {"adapter": "caddyfile"}
/etc/caddy # curl --unix-socket /var/run/caddy.sock http://127.0.0.1/reverse_proxy/upstreams
[]
/etc/caddy # curl --unix-socket /var/run/caddy.sock http://localhost/reverse_proxy/upstreams
{"error":"host not allowed: localhost"}

I can also observe this behaviour with caddy 2.8.4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions