Skip to content

Commit

Permalink
Stop using terms "whitelist" and "blacklist"
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Jul 5, 2023
1 parent 562ab86 commit 6031828
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion api/r0/preview_url.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func PreviewUrl(r *http.Request, rctx rcontext.RequestContext, user _apimeta.Use
if err != nil {
if err == common.ErrMediaNotFound || err == common.ErrHostNotFound {
return _responses.NotFoundError()
} else if err == common.ErrInvalidHost || err == common.ErrHostBlacklisted {
} else if err == common.ErrInvalidHost || err == common.ErrHostNotAllowed {
return _responses.BadRequest(err.Error())
} else {
sentry.CaptureException(err)
Expand Down
2 changes: 1 addition & 1 deletion common/errorcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package common

const ErrCodeInvalidHost = "M_INVALID_HOST"
const ErrCodeHostNotFound = "M_HOST_NOT_FOUND"
const ErrCodeHostBlacklisted = "M_HOST_BLACKLISTED"
const ErrCodeHostNotAllowed = "M_HOST_NOT_ALLOWED"
const ErrCodeNotFound = "M_NOT_FOUND"
const ErrCodeUnknownToken = "M_UNKNOWN_TOKEN"
const ErrCodeNoGuests = "M_GUEST_ACCESS_FORBIDDEN"
Expand Down
2 changes: 1 addition & 1 deletion common/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var ErrMediaNotFound = errors.New("media not found")
var ErrMediaTooLarge = errors.New("media too large")
var ErrInvalidHost = errors.New("invalid host")
var ErrHostNotFound = errors.New("host not found")
var ErrHostBlacklisted = errors.New("host not allowed")
var ErrHostNotAllowed = errors.New("host not allowed")
var ErrMediaQuarantined = errors.New("media quarantined")
var ErrQuotaExceeded = errors.New("quota exceeded")
var ErrWrongUser = errors.New("wrong user")
Expand Down
4 changes: 2 additions & 2 deletions config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ urlPreviews:
- 'fe80::/64'
- 'fc00::/7'
allowedNetworks:
- "0.0.0.0/0" # "Everything". The blacklist will help limit this.
- "0.0.0.0/0" # "Everything". The deny list will help limit this.
# This is the default value for this field.

# How many days after a preview is generated before it expires and is deleted. The preview
Expand All @@ -348,7 +348,7 @@ urlPreviews:
# Set the User-Agent header to supply when generating URL previews
userAgent: "matrix-media-repo"

# When true, oEmbed previews will be enabled. Typically these kinds of previews are used for
# When true, oEmbed previews will be enabled. Typically, these kinds of previews are used for
# sites that do not support OpenGraph or page scraping, such as Twitter. For information on
# specifying providers for oEmbed, including your own, see the following documentation:
# https://docs.t2bot.io/matrix-media-repo/url-previews/oembed.html
Expand Down
4 changes: 2 additions & 2 deletions controllers/preview_controller/preview_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func cachedPreviewToReal(cached *types.CachedUrlPreview) (*types.UrlPreview, err
return nil, common.ErrInvalidHost
} else if cached.ErrorCode == common.ErrCodeHostNotFound {
return nil, common.ErrHostNotFound
} else if cached.ErrorCode == common.ErrCodeHostBlacklisted {
return nil, common.ErrHostBlacklisted
} else if cached.ErrorCode == common.ErrCodeHostNotAllowed {
return nil, common.ErrHostNotAllowed
} else if cached.ErrorCode == common.ErrCodeNotFound {
return nil, common.ErrMediaNotFound
} else if cached.ErrorCode == common.ErrCodeUnknown {
Expand Down
12 changes: 6 additions & 6 deletions url_previewers/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,29 @@ func getSafeAddress(addr string, ctx rcontext.RequestContext) (net.IP, string, e
deniedCidrs = append(deniedCidrs, "::/128")

if !isAllowed(ipAddr, allowedCidrs, deniedCidrs, ctx) {
return nil, "", common.ErrHostBlacklisted
return nil, "", common.ErrHostNotAllowed
}
return ipAddr, p, nil
}

func isAllowed(ip net.IP, allowed []string, disallowed []string, ctx rcontext.RequestContext) bool {
ctx.Log.Debug("Validating host")

// First check if the IP fits the blacklist. This should be a much shorter list, and therefore
// First check if the IP fits the deny list. This should be a much shorter list, and therefore
// much faster to check.
ctx.Log.Debug("Checking blacklist for host...")
ctx.Log.Debug("Checking deny list for host...")
if inRange(ip, disallowed, ctx) {
ctx.Log.Debug("Host found on blacklist - rejecting")
ctx.Log.Debug("Host found on deny list - rejecting")
return false
}

// Now check the allowed list just to make sure the IP is actually allowed
if inRange(ip, allowed, ctx) {
ctx.Log.Debug("Host allowed due to whitelist")
ctx.Log.Debug("Host allowed due to allow list")
return true
}

ctx.Log.Debug("Host is not on either whitelist or blacklist, considering blacklisted")
ctx.Log.Debug("Host is not on either allow list or deny list, considering deny listed")
return false
}

Expand Down

0 comments on commit 6031828

Please sign in to comment.