mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-10 20:22:31 +02:00
Sanitize SVG
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/imgproxy/imgproxy/v3/processing"
|
||||
"github.com/imgproxy/imgproxy/v3/router"
|
||||
"github.com/imgproxy/imgproxy/v3/security"
|
||||
"github.com/imgproxy/imgproxy/v3/svg"
|
||||
"github.com/imgproxy/imgproxy/v3/vips"
|
||||
)
|
||||
|
||||
@@ -275,6 +276,22 @@ func handleProcessing(reqID string, rw http.ResponseWriter, r *http.Request) {
|
||||
if originData.Type == po.Format || po.Format == imagetype.Unknown {
|
||||
// Don't process SVG
|
||||
if originData.Type == imagetype.SVG {
|
||||
if config.SanitizeSvg {
|
||||
sanitized, svgErr := svg.Satitize(originData.Data)
|
||||
if svgErr != nil {
|
||||
panic(svgErr)
|
||||
}
|
||||
|
||||
// Since we'll replace origin data, it's better to close it to return
|
||||
// it's buffer to the pool
|
||||
originData.Close()
|
||||
|
||||
originData = &imagedata.ImageData{
|
||||
Data: sanitized,
|
||||
Type: imagetype.SVG,
|
||||
}
|
||||
}
|
||||
|
||||
respondWithImage(reqID, r, rw, statusCode, originData, po, imageURL, originData)
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user