MM-54219 - Fix: Improve limits on redirectLocationDataCache (#24429)

* ignore redirect locations over certain length

* maybe the link isn't necessary

* remove unrelated debugging line

* PR comments
Этот коммит содержится в:
Christopher Poile
2023-09-05 14:04:14 -04:00
коммит произвёл GitHub
родитель 1fb8772ef9
Коммит b6f2c8205e
2 изменённых файлов: 44 добавлений и 5 удалений

Просмотреть файл

@@ -26,9 +26,11 @@ import (
)
const (
RedirectLocationCacheSize = 10000
DefaultServerBusySeconds = 3600
MaxServerBusySeconds = 86400
RedirectLocationCacheSize = 10000
RedirectLocationMaximumLength = 2100
RedirectLocationCacheExpiry = 1 * time.Hour
DefaultServerBusySeconds = 3600
MaxServerBusySeconds = 86400
)
var redirectLocationDataCache = cache.NewLRU(cache.LRUOptions{
@@ -585,7 +587,7 @@ func getRedirectLocation(c *Context, w http.ResponseWriter, r *http.Request) {
res, err := client.Head(url)
if err != nil {
// Cache failures to prevent retries.
redirectLocationDataCache.SetWithExpiry(url, "", 1*time.Hour)
redirectLocationDataCache.SetWithExpiry(url, "", RedirectLocationCacheExpiry)
// Always return a success status and a JSON string to limit information returned to client.
w.Write([]byte(model.MapToJSON(m)))
return
@@ -596,7 +598,17 @@ func getRedirectLocation(c *Context, w http.ResponseWriter, r *http.Request) {
}()
location = res.Header.Get("Location")
redirectLocationDataCache.SetWithExpiry(url, location, 1*time.Hour)
// If the location length is > 2100, we can probably ignore. Fixes https://mattermost.atlassian.net/browse/MM-54219
if len(location) > RedirectLocationMaximumLength {
// Treating as a "failure". Cache failures to prevent retries.
redirectLocationDataCache.SetWithExpiry(url, "", RedirectLocationCacheExpiry)
// Always return a success status and a JSON string to limit information returned to client.
w.Write([]byte(model.MapToJSON(m)))
return
}
redirectLocationDataCache.SetWithExpiry(url, location, RedirectLocationCacheExpiry)
m["location"] = location
w.Write([]byte(model.MapToJSON(m)))