Skip to content

Commit 8abf4db

Browse files
authored
Merge pull request #964 from ipfs/input-validation-allowlists
bitswap/httpnet: Sanitize allow/denylist inputs
2 parents 44137d7 + 8deebe5 commit 8abf4db

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

bitswap/network/httpnet/httpnet.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,44 @@ func WithInsecureSkipVerify(b bool) Option {
120120
}
121121

122122
// WithAllowlist sets the hostnames that we are allowed to connect to via
123-
// HTTP. Additionally, http response status metrics are tagged for each of
124-
// these hosts.
123+
// HTTP.
125124
func WithAllowlist(hosts []string) Option {
126125
return func(net *Network) {
127126
log.Infof("HTTP retrieval allowlist: %s", strings.Join(hosts, ", "))
128127
net.allowlist = make(map[string]struct{})
129128
for _, h := range hosts {
129+
h = strings.TrimSpace(h)
130+
if h == "" {
131+
log.Error("empty string in allowlist. Ignoring...")
132+
continue
133+
}
134+
if strings.Contains(h, " ") {
135+
log.Errorf("allowlist item '%s' contains a whitespace. Ignoring...")
136+
continue
137+
}
138+
130139
net.allowlist[h] = struct{}{}
131140
}
132141
}
133142
}
134143

144+
// WithDenylist sets the hostnames that we are prohibited to connect to via
145+
// HTTP.
135146
func WithDenylist(hosts []string) Option {
136147
return func(net *Network) {
137148
log.Infof("HTTP retrieval denylist: %s", strings.Join(hosts, ", "))
138149
net.denylist = make(map[string]struct{})
139150
for _, h := range hosts {
151+
h = strings.TrimSpace(h)
152+
if h == "" {
153+
log.Error("empty string in denylist. Ignoring...")
154+
continue
155+
}
156+
if strings.Contains(h, " ") {
157+
log.Errorf("denylist item '%s' contains a whitespace. Ignoring...")
158+
continue
159+
}
160+
140161
net.denylist[h] = struct{}{}
141162
}
142163
}

0 commit comments

Comments
 (0)