Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
40fd700f
Commit
40fd700f
authored
Apr 12, 2026
by
boojack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(fileserver): render SVG attachment previews
parent
efeb28c8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
1 deletion
+49
-1
fileserver.go
server/router/fileserver/fileserver.go
+0
-1
fileserver_test.go
server/router/fileserver/fileserver_test.go
+49
-0
No files found.
server/router/fileserver/fileserver.go
View file @
40fd700f
...
...
@@ -55,7 +55,6 @@ var xssUnsafeTypes = map[string]bool{
"text/xml"
:
true
,
"application/xml"
:
true
,
"application/xhtml+xml"
:
true
,
"image/svg+xml"
:
true
,
}
// thumbnailSupportedTypes contains image MIME types that support thumbnail generation.
...
...
server/router/fileserver/fileserver_test.go
View file @
40fd700f
...
...
@@ -185,6 +185,55 @@ func TestServeAttachmentFile_MotionClip(t *testing.T) {
require
.
Contains
(
t
,
rec
.
Body
.
String
(),
"ftyp"
)
}
func
TestServeAttachmentFile_SVGThumbnailServedAsImageWithSecurityHeaders
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
svc
,
fs
,
_
,
cleanup
:=
newShareAttachmentTestServices
(
ctx
,
t
)
defer
cleanup
()
creator
,
err
:=
svc
.
Store
.
CreateUser
(
ctx
,
&
store
.
User
{
Username
:
"svg-owner"
,
Role
:
store
.
RoleUser
,
Email
:
"svg-owner@example.com"
,
})
require
.
NoError
(
t
,
err
)
creatorCtx
:=
context
.
WithValue
(
ctx
,
auth
.
UserIDContextKey
,
creator
.
ID
)
svgContent
:=
[]
byte
(
`<svg xmlns="http://www.w3.org/2000/svg" width="120" height="40"><text x="0" y="20">memos</text></svg>`
)
attachment
,
err
:=
svc
.
CreateAttachment
(
creatorCtx
,
&
apiv1
.
CreateAttachmentRequest
{
Attachment
:
&
apiv1
.
Attachment
{
Filename
:
"preview.svg"
,
Type
:
"image/svg+xml"
,
Content
:
svgContent
,
},
})
require
.
NoError
(
t
,
err
)
_
,
err
=
svc
.
CreateMemo
(
creatorCtx
,
&
apiv1
.
CreateMemoRequest
{
Memo
:
&
apiv1
.
Memo
{
Content
:
"svg memo"
,
Visibility
:
apiv1
.
Visibility_PUBLIC
,
Attachments
:
[]
*
apiv1
.
Attachment
{
{
Name
:
attachment
.
Name
},
},
},
})
require
.
NoError
(
t
,
err
)
e
:=
echo
.
New
()
fs
.
RegisterRoutes
(
e
)
req
:=
httptest
.
NewRequest
(
http
.
MethodGet
,
fmt
.
Sprintf
(
"/file/%s/%s?thumbnail=true"
,
attachment
.
Name
,
attachment
.
Filename
),
nil
)
rec
:=
httptest
.
NewRecorder
()
e
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
require
.
Equal
(
t
,
"image/svg+xml"
,
rec
.
Header
()
.
Get
(
"Content-Type"
))
require
.
Empty
(
t
,
rec
.
Header
()
.
Get
(
"Content-Disposition"
))
require
.
Equal
(
t
,
"nosniff"
,
rec
.
Header
()
.
Get
(
"X-Content-Type-Options"
))
require
.
Equal
(
t
,
"default-src 'none'; style-src 'unsafe-inline';"
,
rec
.
Header
()
.
Get
(
"Content-Security-Policy"
))
require
.
Equal
(
t
,
svgContent
,
rec
.
Body
.
Bytes
())
}
func
newShareAttachmentTestServices
(
ctx
context
.
Context
,
t
*
testing
.
T
)
(
*
apiv1service
.
APIV1Service
,
*
FileServerService
,
*
store
.
Store
,
func
())
{
t
.
Helper
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment