Skip to content

Commit ce6e210

Browse files
committed
internal/witness: reject requests with more than 63 proof lines
The spec says the client MUST NOT send more than 63 consistency proof lines. Return a 400 Bad Request for requests that exceed this limit. Suggested by Gabriel Kihlman. Fixes #58
1 parent 5133cde commit ce6e210

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

internal/witness/witness.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ func (w *Witness) processAddCheckpointRequest(body []byte, bastion string) (cosi
196196
return nil, errBadRequest
197197
}
198198
l = l.With("oldSize", oldSize)
199+
if len(lines[1:]) > 63 {
200+
// > The client MUST NOT send more than 63 consistency proof lines.
201+
return nil, errBadRequest
202+
}
199203
proof := make(tlog.TreeProof, len(lines[1:]))
200204
for i, h := range lines[1:] {
201205
proof[i], err = tlog.ParseHash(h)

internal/witness/witness_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package witness
22

33
import (
4+
"bytes"
45
"crypto/ed25519"
56
"encoding/base64"
67
"encoding/hex"
@@ -156,3 +157,39 @@ func fatalIfErr(t *testing.T, err error) {
156157
t.Fatal(err)
157158
}
158159
}
160+
161+
func TestTooManyProofs(t *testing.T) {
162+
// gentest seed b4e385f4358f7373cfa9184b176f3cccf808e795baf04092ddfde9461014f0c4
163+
ss := ed25519.PrivateKey(mustDecodeHex(t,
164+
"31ffc2116ecbe003acaa800ab70757bd7d53206e3febef6a6d0796d95530b34f"+
165+
"64848ad8abed6e85981b3b3875b252b8767ebb4b02f703aca3b1e71bbd6a8e50"))
166+
w, err := NewWitness(":memory:", "example.com", ss, slog.New(testLogHandler(t)))
167+
fatalIfErr(t, err)
168+
t.Cleanup(func() { w.Close() })
169+
origin := "sigsum.org/v1/tree/4d6d8825a6bb689d459628312889dfbb0bcd41b5211d9e1ce768b0ff0309e562"
170+
171+
treeHash := merkle.HashEmptyTree()
172+
fatalIfErr(t, sqlitexExec(w.db, "INSERT INTO log (origin, tree_size, tree_hash) VALUES (?, 0, ?)",
173+
nil, origin, base64.StdEncoding.EncodeToString(treeHash[:])))
174+
pk := mustDecodeHex(t, "ffdc2d4d98e4124d3feaf788c0c2f9abfd796083d1f0495437f302ec79cf100f")
175+
k, err := note.NewEd25519VerifierKey(origin, pk[:])
176+
fatalIfErr(t, err)
177+
fatalIfErr(t, sqlitexExec(w.db, "INSERT INTO key (origin, key) VALUES (?, ?)", nil, origin, k))
178+
179+
// make checkpoint with > 63 proofs
180+
buf := []byte("old 0\n")
181+
proofs := bytes.Repeat([]byte("KgEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n"), 64)
182+
buf = append(buf, proofs...)
183+
rest := []byte(`
184+
sigsum.org/v1/tree/4d6d8825a6bb689d459628312889dfbb0bcd41b5211d9e1ce768b0ff0309e562
185+
1
186+
KgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
187+
188+
— sigsum.org/v1/tree/4d6d8825a6bb689d459628312889dfbb0bcd41b5211d9e1ce768b0ff0309e562 UgIom7fPZTqpxWWhyjWduBvTvGVqsokMbqTArsQilegKoFBJQjUFAmQ0+YeSPM3wfUQMFSzVnnNuWRTYrajXpNUbIQY=
189+
`)
190+
buf = append(buf, rest...)
191+
_, err = w.processAddCheckpointRequest(buf, "")
192+
if err == nil || err != errBadRequest {
193+
t.Fatal("checkpoint with too many proofs (>63) should have failed with bad request")
194+
}
195+
}

0 commit comments

Comments
 (0)