Skip to content

Commit

Permalink
agent: Limit KV entries to 512KB. Fixes #123.
Browse files Browse the repository at this point in the history
  • Loading branch information
armon committed May 6, 2014
1 parent 4a80e73 commit 8f37f96
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions command/agent/kvs_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ package agent

import (
"bytes"
"fmt"
"github.com/hashicorp/consul/consul/structs"
"io"
"net/http"
"strconv"
"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) {
// Set default DC
args := structs.KeyRequest{}
Expand Down Expand Up @@ -144,6 +152,13 @@ func (s *HTTPServer) KVSPut(resp http.ResponseWriter, req *http.Request, args *s
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
buf := bytes.NewBuffer(nil)
if _, err := io.Copy(buf, req.Body); err != nil {
Expand Down

0 comments on commit 8f37f96

Please sign in to comment.