Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

fix: prevent XSS for specific content types

Steven46d5307d7f21
diff --git a/server/router/api/v1/resource_service.go b/server/router/api/v1/resource_service.go
index ec1f609a9..43db4d18d 100644
--- a/server/router/api/v1/resource_service.go
+++ b/server/router/api/v1/resource_service.go
@@ -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,