mirror of
https://github.com/status-im/consul.git
synced 2025-01-22 11:40:06 +00:00
agent: Limit KV entries to 512KB. Fixes #123.
This commit is contained in:
parent
4a80e73df4
commit
8f37f967e0
@ -2,6 +2,7 @@ package agent
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"github.com/hashicorp/consul/consul/structs"
|
"github.com/hashicorp/consul/consul/structs"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -9,6 +10,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// maxKVSize is used to limit the maximum payload length
|
||||||
|
// of a KV entry. If it exceeds this amount, the client is
|
||||||
|
// likely abusing the KV store.
|
||||||
|
maxKVSize = 512 * 1024
|
||||||
|
)
|
||||||
|
|
||||||
func (s *HTTPServer) KVSEndpoint(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
func (s *HTTPServer) KVSEndpoint(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||||
// Set default DC
|
// Set default DC
|
||||||
args := structs.KeyRequest{}
|
args := structs.KeyRequest{}
|
||||||
@ -144,6 +152,13 @@ func (s *HTTPServer) KVSPut(resp http.ResponseWriter, req *http.Request, args *s
|
|||||||
applyReq.Op = structs.KVSCAS
|
applyReq.Op = structs.KVSCAS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check the content-length
|
||||||
|
if req.ContentLength > maxKVSize {
|
||||||
|
resp.WriteHeader(413)
|
||||||
|
resp.Write([]byte(fmt.Sprintf("Value exceeds %d byte limit", maxKVSize)))
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Copy the value
|
// Copy the value
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
if _, err := io.Copy(buf, req.Body); err != nil {
|
if _, err := io.Copy(buf, req.Body); err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user