mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-14 13:22:26 +03:00
url_preview tests
Signed-off-by: Aleksandr Dubovikov <d.lexand@gmail.com>
This commit is contained in:
parent
4232fa3e67
commit
0224d94d9a
3 changed files with 245 additions and 7 deletions
|
@ -88,11 +88,9 @@ func makeUrlPreviewHandler(
|
|||
}
|
||||
|
||||
// Check if the url is in the blacklist
|
||||
for _, pattern := range urlBlackList {
|
||||
if pattern.MatchString(pUrl) {
|
||||
logger.WithField("pattern", pattern.String()).Warn("the url is blacklisted")
|
||||
return util.ErrorResponse(ErrorBlackListed)
|
||||
}
|
||||
if checkURLBlacklisted(urlBlackList, pUrl) {
|
||||
logger.Debug("The url is in the blacklist")
|
||||
return util.ErrorResponse(ErrorBlackListed)
|
||||
}
|
||||
|
||||
urlParsed, perr := url.Parse(pUrl)
|
||||
|
@ -668,5 +666,14 @@ func createUrlBlackList(cfg *config.MediaAPI) []*regexp.Regexp {
|
|||
blackList[i] = regexp.MustCompile(pattern)
|
||||
}
|
||||
return blackList
|
||||
|
||||
}
|
||||
|
||||
func checkURLBlacklisted(blacklist []*regexp.Regexp, url string) bool {
|
||||
// Check if the url is in the blacklist
|
||||
for _, pattern := range blacklist {
|
||||
if pattern.MatchString(url) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue