mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-06-09 11:25:14 +02:00
rename 'Whitelist' to 'RemoteHosts"
This better describes what exactly is being allowed.
This commit is contained in:
parent
0370572130
commit
70276f36bc
7 changed files with 61 additions and 49 deletions
|
|
@ -42,8 +42,11 @@ type Proxy struct {
|
|||
Client *http.Client // client used to fetch remote URLs
|
||||
Cache Cache // cache used to cache responses
|
||||
|
||||
// Whitelist specifies a list of remote hosts that images can be
|
||||
// RemoteHosts specifies a list of remote hosts that images can be
|
||||
// proxied from. An empty list means all hosts are allowed.
|
||||
RemoteHosts []string
|
||||
|
||||
// Whitelist should no longer be used. Use "RemoteHosts" instead.
|
||||
Whitelist []string
|
||||
|
||||
// Referrers, when given, requires that requests to the image
|
||||
|
|
@ -207,15 +210,19 @@ func copyHeader(dst, src http.Header, keys ...string) {
|
|||
// referrer, host, and signature. It returns an error if the request is not
|
||||
// allowed.
|
||||
func (p *Proxy) allowed(r *Request) error {
|
||||
if p.RemoteHosts == nil {
|
||||
// backwards compatible with old naming of the field
|
||||
p.RemoteHosts = p.Whitelist
|
||||
}
|
||||
if len(p.Referrers) > 0 && !validReferrer(p.Referrers, r.Original) {
|
||||
return fmt.Errorf("request does not contain an allowed referrer: %v", r)
|
||||
}
|
||||
|
||||
if len(p.Whitelist) == 0 && len(p.SignatureKey) == 0 {
|
||||
return nil // no whitelist or signature key, all requests accepted
|
||||
if len(p.RemoteHosts) == 0 && len(p.SignatureKey) == 0 {
|
||||
return nil // no allowed hosts or signature key, all requests accepted
|
||||
}
|
||||
|
||||
if len(p.Whitelist) > 0 && validHost(p.Whitelist, r.URL) {
|
||||
if len(p.RemoteHosts) > 0 && validHost(p.RemoteHosts, r.URL) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue