diff --git a/CHANGELOG.md b/CHANGELOG.md index f39c3a2b..0eff4ad7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,11 @@ towards this code. The new policy can be used by setting the environment variable `HEADSCALE_EXPERIMENTAL_POLICY_V2` to `1`. +#### Other breaking + +- Disallow `server_url` and `base_domain` to be equal + [#2544](https://github.com/juanfont/headscale/pull/2544) + ### Changes - Use Go 1.24 [#2427](https://github.com/juanfont/headscale/pull/2427) diff --git a/hscontrol/types/config.go b/hscontrol/types/config.go index 588d6a71..a0fcfd45 100644 --- a/hscontrol/types/config.go +++ b/hscontrol/types/config.go @@ -33,6 +33,7 @@ const ( var ( errOidcMutuallyExclusive = errors.New("oidc_client_secret and oidc_client_secret_path are mutually exclusive") errServerURLSuffix = errors.New("server_url cannot be part of base_domain in a way that could make the DERP and headscale server unreachable") + errServerURLSame = errors.New("server_url cannot use the same domain as base_domain in a way that could make the DERP and headscale server unreachable") errInvalidPKCEMethod = errors.New("pkce.method must be either 'plain' or 'S256'") ) @@ -999,6 +1000,10 @@ func isSafeServerURL(serverURL, baseDomain string) error { return err } + if server.Hostname() == baseDomain { + return errServerURLSame + } + serverDomainParts := strings.Split(server.Host, ".") baseDomainParts := strings.Split(baseDomain, ".") diff --git a/hscontrol/types/config_test.go b/hscontrol/types/config_test.go index e7afee69..7ae3db59 100644 --- a/hscontrol/types/config_test.go +++ b/hscontrol/types/config_test.go @@ -423,6 +423,7 @@ func TestSafeServerURL(t *testing.T) { { serverURL: "https://headscale.com", baseDomain: "headscale.com", + wantErr: errServerURLSame.Error(), }, { serverURL: "https://headscale.com",