Plugins: Ensure proxy route bodies are valid JSON (#61771)

ensure proxy route bodies are valid JSON
This commit is contained in:
Will Browne
2023-02-01 16:37:08 +01:00
committed by GitHub
parent 0a780d978e
commit 317f044e70

View File

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