mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 08:12:10 +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 (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -77,6 +79,10 @@ func setBodyContent(req *http.Request, route *plugins.Route, data templateData)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !json.Valid([]byte(interpolatedBody)) {
|
||||||
|
return errors.New("body is not valid JSON")
|
||||||
|
}
|
||||||
|
|
||||||
req.Body = io.NopCloser(strings.NewReader(interpolatedBody))
|
req.Body = io.NopCloser(strings.NewReader(interpolatedBody))
|
||||||
req.ContentLength = int64(len(interpolatedBody))
|
req.ContentLength = int64(len(interpolatedBody))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user