Sanitize post for audit with preview links (#23745)

* sanitize post for audit with preview links

* add unit test

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Doug Lauder
2023-06-15 08:23:56 -04:00
коммит произвёл GitHub
родитель 5d66883b04
Коммит d655ab94a3
4 изменённых файлов: 86 добавлений и 1 удалений

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

@@ -120,6 +120,11 @@ type Post struct {
}
func (o *Post) Auditable() map[string]interface{} {
var metaData map[string]any
if o.Metadata != nil {
metaData = o.Metadata.Auditable()
}
return map[string]interface{}{
"id": o.Id,
"create_at": o.CreateAt,
@@ -139,7 +144,7 @@ func (o *Post) Auditable() map[string]interface{} {
"reply_count": o.ReplyCount,
"last_reply_at": o.LastReplyAt,
"is_following": o.IsFollowing,
"metadata": o.Metadata,
"metadata": metaData,
}
}

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

@@ -23,3 +23,11 @@ type PostEmbed struct {
// Any additional data for the embedded content. Only used for OpenGraph embeds.
Data any `json:"data,omitempty"`
}
func (pe *PostEmbed) Auditable() map[string]any {
// filter out embedded content.
return map[string]any{
"type": pe.Type,
"url": pe.URL,
}
}

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

@@ -30,6 +30,26 @@ type PostMetadata struct {
Acknowledgements []*PostAcknowledgement `json:"acknowledgements,omitempty"`
}
func (pm *PostMetadata) Auditable() map[string]any {
embeds := make([]map[string]any, 0, len(pm.Embeds))
for _, pe := range pm.Embeds {
embeds = append(embeds, pe.Auditable())
}
if len(embeds) == 0 {
embeds = nil
}
return map[string]any{
"embeds": embeds,
"emojis": pm.Emojis,
"files": pm.Files,
"images": pm.Images,
"reactions": pm.Reactions,
"priority": pm.Priority,
"acknowledgements": pm.Acknowledgements,
}
}
type PostImage struct {
Width int `json:"width"`
Height int `json:"height"`