Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions plugin/sign/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"math/rand"
"path/filepath"
"strings"
"time"

"github.com/coredns/caddy"
Expand Down Expand Up @@ -50,6 +51,11 @@ func parse(c *caddy.Controller) (*Sign, error) {
dbfile = filepath.Join(config.Root, dbfile)
}

// Validate dbfile token to avoid infinite signing loops caused by invalid paths
if strings.ContainsRune(dbfile, '\uFFFD') {
return nil, fmt.Errorf("dbfile %q contains invalid characters", dbfile)
}

origins := plugin.OriginsFromArgsOrServerBlock(c.RemainingArgs(), c.ServerBlockKeys)
signers := make([]*Signer, len(origins))
for i := range origins {
Expand Down
11 changes: 11 additions & 0 deletions plugin/sign/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,14 @@ func TestParse(t *testing.T) {
}
}
}

// With setup validation in place, an invalid utf-8 dbfile token must cause parse() to error.
func TestParseRejectsInvalidDbfileToken(t *testing.T) {
input := "sign \"\xff\" 8.44.in-addr.arpa. 9.44.in-addr.arpa. {}"
c := caddy.NewTestController("dns", input)

_, err := parse(c)
if err == nil {
t.Fatalf("expected parse to fail for invalid dbfile token")
}
}
Loading