mirror of
https://github.com/usememos/memos.git
synced 2025-11-08 08:21:49 +08:00
fix: prevent XSS for specific content types
This commit is contained in:
parent
c2528c57f0
commit
46d5307d7f
1 changed files with 6 additions and 0 deletions
|
|
@ -188,6 +188,12 @@ func (s *APIV1Service) GetResourceBinary(ctx context.Context, request *v1pb.GetR
|
|||
if strings.HasPrefix(contentType, "text/") {
|
||||
contentType += "; charset=utf-8"
|
||||
}
|
||||
// Prevent XSS attacks by serving potentially unsafe files with a content type that prevents script execution.
|
||||
if strings.EqualFold(contentType, "image/svg+xml") ||
|
||||
strings.EqualFold(contentType, "text/html") ||
|
||||
strings.EqualFold(contentType, "application/xhtml+xml") {
|
||||
contentType = "application/octet-stream"
|
||||
}
|
||||
|
||||
return &httpbody.HttpBody{
|
||||
ContentType: contentType,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue