Skip to content

Commit f292eff

Browse files
committed
use exact matching of allowed domain entries, issue #489
1 parent 7c971ca commit f292eff

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

cors_filter.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package restful
55
// that can be found in the LICENSE file.
66

77
import (
8+
"fmt"
89
"regexp"
910
"strconv"
1011
"strings"
@@ -191,11 +192,15 @@ func (c CrossOriginResourceSharing) isValidAccessControlRequestHeader(header str
191192
return false
192193
}
193194

194-
// Take a list of strings and compile them into a list of regular expressions.
195-
func compileRegexps(regexpStrings []string) ([]*regexp.Regexp, error) {
195+
// Take a list of allowed domains as strings and compile them into a list of regular expressions.
196+
func compileRegexps(allowedDomains []string) ([]*regexp.Regexp, error) {
196197
regexps := []*regexp.Regexp{}
197-
for _, regexpStr := range regexpStrings {
198-
r, err := regexp.Compile(regexpStr)
198+
for _, each := range allowedDomains {
199+
// make sure the expression represents an exact match
200+
if !strings.HasPrefix(each, "^") {
201+
each = fmt.Sprintf("^%s$", each)
202+
}
203+
r, err := regexp.Compile(each)
199204
if err != nil {
200205
return regexps, err
201206
}

0 commit comments

Comments
 (0)