Skip to content

Implementated global validation of domain strings #638

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

Merged
merged 9 commits into from
Apr 1, 2024
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.21

require (
github.com/breml/rootcerts v0.2.16
github.com/chmike/domain v1.0.1
github.com/containrrr/shoutrrr v0.8.0
github.com/go-chi/chi/v5 v5.0.11
github.com/golang/mock v1.6.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/breml/rootcerts v0.2.16 h1:yN1TGvicfHx8dKz3OQRIrx/5nE/iN3XT1ibqGbd6urc=
github.com/breml/rootcerts v0.2.16/go.mod h1:S/PKh+4d1HUn4HQovEB8hPJZO6pUZYrIhmXBhsegfXw=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/chmike/domain v1.0.1 h1:ug6h3a7LLAfAecBAysbCXWxP1Jo8iBKWNVDxcs1BNzA=
github.com/chmike/domain v1.0.1/go.mod h1:h558M2qGKpYRUxHHNyey6puvXkZBjvjmseOla/d1VGQ=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/containrrr/shoutrrr v0.8.0 h1:mfG2ATzIS7NR2Ec6XL+xyoHzN97H8WPjir8aYzJUSec=
Expand Down
13 changes: 13 additions & 0 deletions internal/params/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"strings"

"github.com/chmike/domain"
"github.com/qdm12/ddns-updater/internal/models"
"github.com/qdm12/ddns-updater/internal/provider"
"github.com/qdm12/ddns-updater/internal/provider/constants"
Expand Down Expand Up @@ -140,6 +141,7 @@ func extractAllSettings(jsonBytes []byte) (

var (
ErrProviderNoLongerSupported = errors.New("provider no longer supported")
ErrDomainBlank = errors.New("domain cannot be blank for provider")
)

func makeSettingsFromObject(common commonSettings, rawSettings json.RawMessage,
Expand All @@ -149,6 +151,17 @@ func makeSettingsFromObject(common commonSettings, rawSettings json.RawMessage,
return nil, nil, fmt.Errorf("%w: %s", ErrProviderNoLongerSupported, common.Provider)
}

if common.Domain == "" && (common.Provider != "duckdns" && common.Provider != "goip") {
return nil, nil, fmt.Errorf("%w: %s", ErrDomainBlank, common.Provider)
}

if common.Domain != "" {
err = domain.Check(common.Domain)
if err != nil {
return nil, nil, fmt.Errorf("validating domain: %w", err)
}
}

providerName := models.Provider(common.Provider)
if providerName == constants.DuckDNS { // only hosts, no domain
if common.Domain != "" { // retro compatibility
Expand Down