mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
fix: prevent XSS for specific content types
This commit is contained in:
@@ -188,6 +188,12 @@ func (s *APIV1Service) GetResourceBinary(ctx context.Context, request *v1pb.GetR
|
|||||||
if strings.HasPrefix(contentType, "text/") {
|
if strings.HasPrefix(contentType, "text/") {
|
||||||
contentType += "; charset=utf-8"
|
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{
|
return &httpbody.HttpBody{
|
||||||
ContentType: contentType,
|
ContentType: contentType,
|
||||||
|
Reference in New Issue
Block a user