Add URL validation to LinkMetadata cache and store (#31814) (#33453)

Automatic Merge
Этот коммит содержится в:
Mattermost Build
2025-07-17 20:58:42 +03:00
коммит произвёл GitHub
родитель 2fceeceba6
Коммит f21005e359
3 изменённых файлов: 154 добавлений и 0 удалений

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

@@ -34,6 +34,7 @@ type linkMetadataCache struct {
OpenGraph *opengraph.OpenGraph
PostImage *model.PostImage
Permalink *model.Permalink
URL string
}
const MaxMetadataImageSize = MaxOpenGraphResponseSize
@@ -812,6 +813,11 @@ func getLinkMetadataFromCache(requestURL string, timestamp int64) (*opengraph.Op
return nil, nil, nil, false
}
// Verify that the cached entry matches the requested URL
if cached.URL != requestURL {
return nil, nil, nil, false
}
return cached.OpenGraph, cached.PostImage, cached.Permalink, true
}
@@ -860,6 +866,7 @@ func cacheLinkMetadata(rctx request.CTX, requestURL string, timestamp int64, og
OpenGraph: og,
PostImage: image,
Permalink: permalink,
URL: requestURL,
}
if err := platform.LinkCache().SetWithExpiry(strconv.FormatInt(model.GenerateLinkMetadataHash(requestURL, timestamp), 16), metadata, platform.LinkCacheDuration); err != nil {