mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
fix: content sanitization in getimage endpoint (#2241)
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
)
|
||||
|
||||
type Image struct {
|
||||
@@ -37,9 +39,21 @@ func GetImage(urlStr string) (*Image, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bodyBytes, err = SanitizeContent(bodyBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
image := &Image{
|
||||
Blob: bodyBytes,
|
||||
Mediatype: mediatype,
|
||||
}
|
||||
return image, nil
|
||||
}
|
||||
|
||||
func SanitizeContent(content []byte) ([]byte, error) {
|
||||
bodyString := string(content)
|
||||
|
||||
bm := bluemonday.UGCPolicy()
|
||||
return []byte(bm.Sanitize(bodyString)), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user