Skip to content

Commit 30539b2

Browse files
authored
config: disallow same server url and base_domain (#2544)
* config: disallow same server url and base_domain Signed-off-by: Kristoffer Dalby <[email protected]> * changelog Signed-off-by: Kristoffer Dalby <[email protected]> --------- Signed-off-by: Kristoffer Dalby <[email protected]>
1 parent 098ab03 commit 30539b2

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ towards this code.
7373
The new policy can be used by setting the environment variable
7474
`HEADSCALE_EXPERIMENTAL_POLICY_V2` to `1`.
7575

76+
#### Other breaking
77+
78+
- Disallow `server_url` and `base_domain` to be equal
79+
[#2544](https://github.com/juanfont/headscale/pull/2544)
80+
7681
### Changes
7782

7883
- Use Go 1.24 [#2427](https://github.com/juanfont/headscale/pull/2427)

hscontrol/types/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const (
3333
var (
3434
errOidcMutuallyExclusive = errors.New("oidc_client_secret and oidc_client_secret_path are mutually exclusive")
3535
errServerURLSuffix = errors.New("server_url cannot be part of base_domain in a way that could make the DERP and headscale server unreachable")
36+
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")
3637
errInvalidPKCEMethod = errors.New("pkce.method must be either 'plain' or 'S256'")
3738
)
3839

@@ -999,6 +1000,10 @@ func isSafeServerURL(serverURL, baseDomain string) error {
9991000
return err
10001001
}
10011002

1003+
if server.Hostname() == baseDomain {
1004+
return errServerURLSame
1005+
}
1006+
10021007
serverDomainParts := strings.Split(server.Host, ".")
10031008
baseDomainParts := strings.Split(baseDomain, ".")
10041009

hscontrol/types/config_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ func TestSafeServerURL(t *testing.T) {
423423
{
424424
serverURL: "https://headscale.com",
425425
baseDomain: "headscale.com",
426+
wantErr: errServerURLSame.Error(),
426427
},
427428
{
428429
serverURL: "https://headscale.com",

0 commit comments

Comments
 (0)