mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 21:42:11 +08:00
Plugins: Ensure proxy route bodies are valid JSON (#61771)
ensure proxy route bodies are valid JSON
This commit is contained in:
@ -2,6 +2,8 @@ package pluginproxy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@ -77,6 +79,10 @@ func setBodyContent(req *http.Request, route *plugins.Route, data templateData)
|
||||
return err
|
||||
}
|
||||
|
||||
if !json.Valid([]byte(interpolatedBody)) {
|
||||
return errors.New("body is not valid JSON")
|
||||
}
|
||||
|
||||
req.Body = io.NopCloser(strings.NewReader(interpolatedBody))
|
||||
req.ContentLength = int64(len(interpolatedBody))
|
||||
}
|
||||
|
Reference in New Issue
Block a user