Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions policy/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ func TestNamePolicyEngine_matchDomainConstraint(t *testing.T) {
want: false,
wantErr: false,
},
{
name: "fail/empty-domain",
domain: "",
constraint: "host.example.com",
want: false,
wantErr: false,
},
{
name: "fail/single-asterisk-domain",
domain: "*",
constraint: "host.example.com",
want: false,
wantErr: false,
},
{
name: "fail/period-domain",
domain: ".host.example.com",
Expand Down
7 changes: 6 additions & 1 deletion policy/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,18 @@ func (e *NamePolicyEngine) matchDomainConstraint(domain, constraint string) (boo
return false, nil
}

// An empty domain never matches a constraint.
if domain == "" {
return false, nil
}

// Block domains that start with just a period
if domain[0] == '.' {
return false, nil
}

// Block wildcard domains that don't start with exactly "*." (i.e. double wildcards and such)
if domain[0] == '*' && domain[1] != '.' {
if domain[0] == '*' && (len(domain) < 2 || domain[1] != '.') {
return false, nil
}

Expand Down