Skip to content
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

Disallow names that start with '.' in IsDomainName() #1376

Merged
merged 2 commits into from May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions defaults.go
Expand Up @@ -218,6 +218,11 @@ func IsDomainName(s string) (labels int, ok bool) {

wasDot = false
case '.':
if i == 0 && len(s) > 1 {
// leading dots are not legal except for the root zone
return labels, false
}

if wasDot {
// two dots back to back is not legal
return labels, false
Expand Down
5 changes: 4 additions & 1 deletion labels_test.go
Expand Up @@ -176,7 +176,10 @@ func TestIsDomainName(t *testing.T) {
lab int
}
names := map[string]*ret{
"..": {false, 1},
".": {true, 1},
"..": {false, 0},
"double-dot..test": {false, 1},
".leading-dot.test": {false, 0},
"@.": {true, 1},
"www.example.com": {true, 3},
"www.e%ample.com": {true, 3},
Expand Down
5 changes: 5 additions & 0 deletions msg.go
Expand Up @@ -265,6 +265,11 @@ loop:

wasDot = false
case '.':
if i == 0 && len(s) > 1 {
// leading dots are not legal except for the root zone
return len(msg), ErrRdata
}

if wasDot {
// two dots back to back is not legal
return len(msg), ErrRdata
Expand Down