[MM-13889] Limit OpenGraph data response size (#10213)
* Limit OpenGraph data response size * Add LimitReader to Metadata Image
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
4e0840969b
Коммит
a2f46c0466
@@ -20,6 +20,7 @@ import (
|
||||
|
||||
const LINK_CACHE_SIZE = 10000
|
||||
const LINK_CACHE_DURATION = 3600
|
||||
const MaxMetadataImageSize = MaxOpenGraphResponseSize
|
||||
|
||||
var linkCache = utils.NewLru(LINK_CACHE_SIZE)
|
||||
|
||||
@@ -451,7 +452,7 @@ func cacheLinkMetadata(requestURL string, timestamp int64, og *opengraph.OpenGra
|
||||
|
||||
func (a *App) parseLinkMetadata(requestURL string, body io.Reader, contentType string) (*opengraph.OpenGraph, *model.PostImage, error) {
|
||||
if strings.HasPrefix(contentType, "image") {
|
||||
image, err := parseImages(body)
|
||||
image, err := parseImages(io.LimitReader(body, MaxMetadataImageSize))
|
||||
return nil, image, err
|
||||
} else if strings.HasPrefix(contentType, "text/html") {
|
||||
og := a.ParseOpenGraphMetadata(requestURL, body, contentType)
|
||||
|
||||
Ссылка в новой задаче
Block a user