Sanitize SVG

This commit is contained in:
DarthSim
2022-06-10 18:07:09 +06:00
parent 8f91fa5bd4
commit e1e2277a32
7 changed files with 89 additions and 1 deletions

View File

@@ -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
}