Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(security): force attachment disposition for SVG uploads (#3023)
Tom Qiao295df8d928fb
diff --git a/server/internal/storage/local_test.go b/server/internal/storage/local_test.goindex 84f3e687c6..0a5ae23a16 100644--- a/server/internal/storage/local_test.go+++ b/server/internal/storage/local_test.go@@ -259,6 +259,14 @@ func TestLocalStorage_ServeFile_ContentDispositionFromSidecar(t *testing.T) {filename: "weird\";name.txt",wantHeader: `attachment; filename="weird__name.txt"`,},+ {+ // SVG can carry <script>/onload — never serve inline.+ name: "attachment for svg (stored-XSS prevention)",+ key: "workspaces/ws-1/jkl.svg",+ contentType: "image/svg+xml",+ filename: "logo.svg",+ wantHeader: `attachment; filename="logo.svg"`,+ },}for _, tc := range cases {diff --git a/server/internal/storage/util.go b/server/internal/storage/util.goindex 56add6886d..42c9bbb3f3 100644--- a/server/internal/storage/util.go+++ b/server/internal/storage/util.go@@ -22,7 +22,15 @@ func sanitizeFilename(name string) string {// isInlineContentType returns true for media types that browsers should// display inline (images, video, audio, PDF). Everything else triggers a// download via Content-Disposition: attachment.+//+// SVG is excluded even though its MIME type is image/svg+xml: SVG is XML+// and can carry <script>, <foreignObject>, or onload= attributes that+// execute in the document's origin when rendered inline. Forcing+// attachment disposition prevents stored-XSS via uploaded .svg files.func isInlineContentType(ct string) bool {+ if ct == "image/svg+xml" {+ return false+ }return strings.HasPrefix(ct, "image/") ||strings.HasPrefix(ct, "video/") ||strings.HasPrefix(ct, "audio/") ||diff --git a/server/internal/storage/util_test.go b/server/internal/storage/util_test.gonew file mode 100644index 0000000000..34479e1493--- /dev/null+++ b/server/internal/storage/util_test.go@@ -0,0 +1,31 @@+package storage++import "testing"++func TestIsInlineContentType(t *testing.T) {+ cases := []struct {+ ct string+ want bool+ }{+ {"image/png", true},+ {"image/jpeg", true},+ {"image/gif", true},+ {"image/webp", true},+ {"video/mp4", true},+ {"audio/mpeg", true},+ {"application/pdf", true},++ // SVG must NOT render inline — it can carry executable script.+ {"image/svg+xml", false},++ {"text/html", false},+ {"application/octet-stream", false},+ {"text/plain", false},+ {"", false},+ }+ for _, tc := range cases {+ if got := isInlineContentType(tc.ct); got != tc.want {+ t.Errorf("isInlineContentType(%q) = %v, want %v", tc.ct, got, tc.want)+ }+ }+}