Release / Plan (reuse the published image?) (push) Successful in 3s
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 28s
CI / Dependency audit (push) Successful in 20s
CI / Tests (Linux, race detector) (push) Successful in 1m10s
Release / ci (push) Successful in 1m10s
Release / Build image (arm64) (push) Successful in 55s
Release / Build image (amd64) (push) Successful in 1m16s
Release / Publish tags (push) Successful in 14s
Release / Gitea release (push) Skipped
New pages grouped in the rail (Monitor, Investigate, Analyze, Operate, Reports): Services (SLO, Apdex, latency app vs proxy), Sessions (stage funnel), Campaigns, Event search, MITRE ATT&CK matrix, Evolution, Concentration (Pareto, Gini), Survival (Kaplan-Meier per attack episode, recidivists), Where errors come from (application vs failed attack vs proxy vs client), Protocols and TLS, Defense (fail2ban, SSH, blocklist), Integrity, and a printable executive report. Chart library (donut, radar, stacked area, bars, heatmap, gauge), glossary with accessible "?" tooltips, self-explanatory category names (nonexistent page 404), page loader through pages.json. Unique visitors fixed: real browsers opening a page, one per IP per day, deduplicated across domains, with non-human clients counted apart. Anonymous legitimate visits on the Live page (?visits=1, no IP). Traefik origin, service, protocol and TLS fields parsed. Paths and Referer paths drop e-mail and token segments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
5.0 KiB
Go
62 lines
5.0 KiB
Go
package core
|
|
|
|
import "testing"
|
|
|
|
func TestErrorClass(t *testing.T) {
|
|
rich := func(e Event) Event {
|
|
e.Proto, e.Scheme = "HTTP/2.0", "https"
|
|
if e.Router == "" {
|
|
e.Router, e.Service = "https-0-abc-gitea@docker", "https-0-abc-gitea@docker"
|
|
}
|
|
return e
|
|
}
|
|
moz := "Mozilla/5.0 (Windows NT 10.0) Chrome/120"
|
|
cases := []struct {
|
|
name string
|
|
ev Event
|
|
susp bool
|
|
class string
|
|
sub string
|
|
attack bool
|
|
}{
|
|
{"catchall env probe", Event{Status: 503, OriginStatus: 503, Method: "GET", Path: "/.env", UA: moz, Domain: "blog.example.com", Router: "catchall@file", Service: "error-pages@file", Proto: "HTTP/2.0"}, false, "attack", "", false},
|
|
{"no router 404", Event{Status: 404, Method: "GET", Path: "/x", UA: moz, Domain: "a.example.com", Proto: "HTTP/1.1"}, false, "attack", "", false},
|
|
{"ip host", Event{Status: 404, OriginStatus: 404, Method: "GET", Path: "/", UA: moz, Domain: "136.0.0.1", Router: "x@docker", Proto: "HTTP/1.1"}, false, "attack", "", false},
|
|
{"scanner cat", rich(Event{Status: 404, OriginStatus: 404, Method: "GET", Path: "/wp-login.php", UA: moz, Cat: Scanner}), false, "attack", "", false},
|
|
{"weird method", rich(Event{Status: 405, OriginStatus: 405, Method: "PROPFIND", UA: moz}), false, "attack", "", false},
|
|
{"empty ua", rich(Event{Status: 404, OriginStatus: 404, Method: "GET", Path: "/a"}), false, "attack", "", false},
|
|
{"curl", rich(Event{Status: 404, OriginStatus: 404, Method: "GET", Path: "/a", UA: "curl/8.1"}), false, "attack", "", false},
|
|
{"suspicious ip", rich(Event{Status: 404, OriginStatus: 404, Method: "GET", Path: "/a", UA: moz}), true, "attack", "", false},
|
|
{"429", rich(Event{Status: 429, Method: "GET", UA: moz}), false, "blocked", "", false},
|
|
{"401 origin 0", rich(Event{Status: 401, OriginStatus: 0, Method: "GET", UA: moz, Path: "/x"}), false, "blocked", "", false},
|
|
{"504 origin 0", rich(Event{Status: 504, OriginStatus: 0, Method: "GET", UA: moz, Path: "/x"}), false, "proxy", "", false},
|
|
{"499 is the client", rich(Event{Status: 499, OriginStatus: 0, Method: "GET", UA: moz, Path: "/x"}), false, "client", "cancelled", false},
|
|
{"runner poll", rich(Event{Status: 404, OriginStatus: 404, Method: "POST", UA: "connect-go/1.16 (go1.22)", Path: "/api/actions/runner.v1.RunnerService/FetchTask", Cat: Scanner}), true, "client", "auth_challenge", false},
|
|
{"gitea-runner", rich(Event{Status: 401, OriginStatus: 0, Method: "POST", UA: "gitea-runner/0.2", Path: "/api/actions/x"}), true, "client", "auth_challenge", false},
|
|
{"502 retry", rich(Event{Status: 502, OriginStatus: 502, Retries: 2, Method: "GET", UA: moz}), false, "proxy", "", false},
|
|
{"app 500", rich(Event{Status: 500, OriginStatus: 500, Method: "POST", UA: moz, Path: "/api/x"}), false, "app", "", false},
|
|
{"app 500 under attack", rich(Event{Status: 500, OriginStatus: 500, Method: "GET", UA: moz, Path: "/a?x=../", Cat: Exploit}), false, "app", "", true},
|
|
{"crawler 404", rich(Event{Status: 404, OriginStatus: 404, Method: "GET", UA: "Mozilla/5.0 (compatible; ElevenlabsCrawler/1.0)", Path: "/z"}), false, "bot", "", false},
|
|
{"robots 404", rich(Event{Status: 404, OriginStatus: 404, Method: "GET", UA: moz, Path: "/robots.txt"}), false, "bot", "", false},
|
|
{"broken link", rich(Event{Status: 404, OriginStatus: 404, Method: "GET", UA: moz, Path: "/old", Domain: "a.example.com", Referer: "https://a.example.com/index"}), false, "client", "broken_link", false},
|
|
{"fetch same-origin", rich(Event{Status: 404, OriginStatus: 404, Method: "GET", UA: moz, Path: "/old", FetchSite: "same-origin"}), false, "client", "broken_link", false},
|
|
{"external link", rich(Event{Status: 404, OriginStatus: 404, Method: "GET", UA: moz, Path: "/old", Domain: "a.example.com", Referer: "https://news.ycombinator.com/"}), false, "client", "external_link", false},
|
|
{"auth browser", rich(Event{Status: 401, OriginStatus: 401, Method: "GET", UA: moz, Path: "/admin", E: Enrich{Device: "desktop"}}), false, "client", "auth", false},
|
|
{"registry challenge", rich(Event{Status: 401, OriginStatus: 401, Method: "GET", UA: "docker/27.0 go/go1.22", Path: "/v2/"}), true, "client", "auth_challenge", false},
|
|
{"actions challenge", rich(Event{Status: 401, OriginStatus: 401, Method: "GET", UA: "act_runner/0.2", Path: "/api/actions/x"}), false, "client", "auth_challenge", false},
|
|
{"validation", rich(Event{Status: 422, OriginStatus: 422, Method: "POST", UA: moz, Path: "/api/x"}), false, "client", "validation", false},
|
|
{"404 plain", rich(Event{Status: 404, OriginStatus: 404, Method: "GET", UA: moz, Path: "/nope"}), false, "client", "other", false},
|
|
{"legacy log 500", Event{Status: 500, Method: "GET", UA: moz, Path: "/x", Domain: "a.example.com"}, false, "app", "", false},
|
|
{"200", Event{Status: 200}, false, "", "", false},
|
|
}
|
|
for _, c := range cases {
|
|
cl, sub, ua := ErrorClassify(c.ev, c.susp)
|
|
if cl != c.class || sub != c.sub || ua != c.attack {
|
|
t.Errorf("%s: got %q/%q/%v want %q/%q/%v", c.name, cl, sub, ua, c.class, c.sub, c.attack)
|
|
}
|
|
if ErrorClass(c.ev, c.susp) != c.class {
|
|
t.Errorf("%s: ErrorClass mismatch", c.name)
|
|
}
|
|
}
|
|
}
|