Files
Lucas RayanandClaude Opus 5.5 b7462c14fa
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 27s
CI / Dependency audit (push) Successful in 18s
CI / Tests (Linux, race detector) (push) Successful in 58s
Release / Plan (reuse the published image?) (push) Successful in 4s
Release / ci (push) Skipped
Release / Build image (amd64) (push) Skipped
Release / Build image (arm64) (push) Skipped
Release / Publish tags (push) Successful in 13s
Release / Gitea release (push) Successful in 5s
feat: 1.2.0 attack intelligence, replay, 30-day history and new interface
Intelligence: attack families mapped to MITRE ATT&CK, network type from
ASN/rDNS without external APIs, request cadence, sessions with
recon/probe/exploit/access/banned stages, campaigns across IPs, verdict
with reasons, recommended actions, exposure detection (2xx with a body
on sensitive paths), STIX 2.1 export, FCrDNS for search engine bots,
optional Tor exit list.

Data: 30-day retention, twelve ranges plus custom from/to, an on-disk
event log (daily files, hourly gzip members, size cap, corruption and
disk-full tolerant), /events, /period, /metrics with stable per-hour
metrics, an extended /ip/{ip}, and peer /period merged on the hub.

Interface: layout system with fixed card sizes, range picker in the
URL, IP analysis page, Replay page, Geography down to state and city
(Natural Earth admin-1), Live page redesigned with stable metrics and a
reusable attack map. Demo data and documentation screenshots.

Security: bounded and deadline-limited period computations, linear
campaign clustering, singleflight caches, sanitized peer studies, event
query budgets, gzip bomb guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 21:45:59 -03:00

65 lines
2.0 KiB
Go

package evlog
import (
"bytes"
"strings"
"testing"
"time"
)
func TestQueryBudgetDeadlineAndSemaphore(t *testing.T) {
now := base
l := open(t, &now, 0)
for i := 0; i < 400; i++ {
l.Append(base.Unix()-int64(i), line(base.Unix()-int64(i), uint64(i+1), "1.2.3.4", "exploit"))
}
f := Filter{From: base.Unix() - 3600, To: base.Unix() + 10}
defer func(b int64, d time.Duration) { queryBudget, queryDeadline = b, d }(queryBudget, queryDeadline)
queryBudget = 2000 // a few lines: the budget is checked per line
r, err := l.Query(Query{Filter: f, Limit: 1000})
if err != nil || !r.Truncated || len(r.Items) >= 400 || len(r.Items) == 0 {
t.Fatalf("budget: %v truncated %v items %d", err, r.Truncated, len(r.Items))
}
queryBudget = 256 << 20
queryDeadline = time.Nanosecond
if r, _ = l.Query(Query{Filter: f, Limit: 1000}); !r.Truncated {
t.Fatal("a query past its deadline must come back truncated")
}
queryDeadline = 10 * time.Second
for i := 0; i < cap(querySem); i++ {
querySem <- struct{}{}
}
if _, err = l.Query(Query{Filter: f}); err != ErrBusy {
t.Fatalf("busy: %v", err)
}
for i := 0; i < cap(querySem); i++ {
<-querySem
}
if r, err = l.Query(Query{Filter: f, Limit: 1000}); err != nil || len(r.Items) != 400 || r.Truncated {
t.Fatalf("normal: %v %d", err, len(r.Items))
}
}
func TestOversizedLinesCountAgainstTheBudget(t *testing.T) {
big := strings.Repeat("x", 3*maxLine)
var in bytes.Buffer
for i := 0; i < 10; i++ {
in.WriteString(big + "\n")
}
in.WriteString(`{"t":1,"ip":"1.1.1.1"}` + "\n")
var nb int64
lines := 0
eachLine(&in, func([]byte) bool { lines++; return true }, &nb)
if lines != 1 || nb < 10*3*maxLine {
t.Fatalf("discarded lines must be counted: lines %d bytes %d", lines, nb)
}
// a stream of oversized lines is cut at the hard stop, not read forever
var nb2 int64 = hardStop - 10
var in2 bytes.Buffer
in2.WriteString(big + "\n")
if eachLine(&in2, func([]byte) bool { return true }, &nb2) {
t.Fatal("must stop past the hard limit")
}
}