feat: 1.3.0 thirteen new pages, charts, tooltips and error analysis
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>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-14 22:39:33 -03:00
1 parent b7462c14fa
commit 2ebda1e4d7
79 files changed
+9091 -171

No files matched your search

+198
View File
@@ -0,0 +1,198 @@
package core
import (
"net"
"net/url"
"regexp"
"strings"
)
// Error classes: where a 4xx/5xx comes from. The answer to "is this a bug in my
// application or a failed attack?".
const (
ClassAttack = "attack" // a probe, exploit or scanner: a frustrated attack
ClassBlocked = "blocked" // refused by a middleware or rate limit before the app
ClassProxy = "proxy" // the proxy could not reach the backend, or the client gave up
ClassApp = "app" // the backend itself answered 5xx
ClassBot = "bot" // a known crawler asking for something that is not there
ClassClient = "client" // an ordinary client mistake (broken link, auth, bad input)
ClassUnknown = "unknown"
)
// Subtypes of the client class.
const (
SubBrokenLink = "broken_link"
SubExternalLink = "external_link"
SubAuth = "auth"
SubAuthChallenge = "auth_challenge"
SubValidation = "validation"
SubCancelled = "cancelled"
SubOther = "other"
)
var okMethods = map[string]bool{"GET": true, "HEAD": true, "POST": true, "PUT": true, "PATCH": true, "DELETE": true, "OPTIONS": true}
var toolUARe = regexp.MustCompile(`(?i)(^|[^a-z])(curl|wget|python-requests|python-urllib|aiohttp|go-http-client|libwww-perl|okhttp|httpie|scrapy|sqlmap|nikto|nmap|masscan|zgrab|nuclei|dirbuster|gobuster|feroxbuster|wfuzz|hydra|httpx|fasthttp|java/|axios|node-fetch)([^a-z]|$)`)
var crawlerUARe = regexp.MustCompile(`(?i)(bot|crawler|spider|slurp|bingpreview|facebookexternalhit|embedly|ia_archiver|archive\.org|mediapartners|headlesschrome|lighthouse|pingdom|uptime|monitor)`)
var registryUARe = regexp.MustCompile(`(?i)(docker|containerd|buildkit|act_runner|gitea-runner|connect-go|skopeo|podman|go-containerregistry|oras|crane)`)
// rich reports whether the log line carried the origin fields. Without them
// (older Traefik, demo data) OriginStatus is unknown and is taken as equal to
// the downstream status.
func rich(ev Event) bool {
return ev.Proto != "" || ev.Scheme != "" || ev.Router != "" || ev.Service != ""
}
func originOf(ev Event) int {
if !rich(ev) {
return ev.Status
}
return ev.OriginStatus
}
func isIPHost(h string) bool {
if i := strings.LastIndexByte(h, ':'); i > 0 && !strings.Contains(h[i:], "]") {
h = h[:i]
}
h = strings.Trim(h, "[]")
return net.ParseIP(h) != nil
}
// NoRouter: the request matched no application router (the catch-all answered,
// or Traefik had nothing for the host): internet noise by definition.
func NoRouter(ev Event) bool {
if isIPHost(ev.Domain) {
return true
}
if !rich(ev) {
return false
}
return ev.Router == "" || strings.HasPrefix(ev.Router, "catchall") || strings.HasPrefix(ev.Service, "error-pages")
}
// AuthChallenge: the normal 401 a container registry or CI runner gets before
// presenting a token. Never an attack.
func AuthChallenge(ev Event) bool {
if ev.Status != 401 && ev.Status != 403 {
return false
}
p := ev.Path
if !(p == "/v2" || strings.HasPrefix(p, "/v2/") || strings.HasPrefix(p, "/api/actions")) {
return false
}
return registryUARe.MatchString(ev.UA)
}
// RunnerCall: a CI runner polling the forge API (never an attack, whatever the
// status): act_runner, gitea-runner or connect-go under /api/actions/.
func RunnerCall(ev Event) bool {
return strings.HasPrefix(ev.Path, "/api/actions") && registryUARe.MatchString(ev.UA)
}
func sameSite(ev Event) bool {
if ev.FetchSite == "same-origin" {
return true
}
if ev.Referer == "" || ev.Referer == "-" {
return false
}
u, err := url.Parse(ev.Referer)
if err != nil || u.Host == "" {
return false
}
h := strings.TrimPrefix(strings.ToLower(u.Hostname()), "www.")
d := strings.TrimPrefix(strings.ToLower(ev.Domain), "www.")
if i := strings.LastIndexByte(d, ':'); i > 0 {
d = d[:i]
}
return h == d || strings.HasSuffix(h, "."+d) || strings.HasSuffix(d, "."+h)
}
var botPaths = []string{"/robots.txt", "/sitemap", "/favicon", "/apple-touch-icon", "/.well-known/"}
func isBotPath(p string) bool {
p = strings.ToLower(p)
for _, b := range botPaths {
if strings.HasPrefix(p, b) {
return true
}
}
return false
}
func browserLike(ev Event) bool {
switch ev.E.Device {
case "desktop", "mobile", "tablet":
return !ev.E.Bot
}
return ev.E.Device == "" && strings.HasPrefix(ev.UA, "Mozilla/") && !crawlerUARe.MatchString(ev.UA) && !toolUARe.MatchString(ev.UA)
}
// ErrorClass classifies a 4xx/5xx answer; "" for anything else. susp says the
// source address is suspicious, hostile or banned.
func ErrorClass(ev Event, susp bool) string {
c, _, _ := ErrorClassify(ev, susp)
return c
}
// ErrorClassify is ErrorClass with the client subtype and the under_attack mark
// (a real application failure on a request that looks like an attack).
func ErrorClassify(ev Event, susp bool) (class, sub string, underAttack bool) {
st := ev.Status
if st < 400 || st > 599 {
return "", "", false
}
origin := originOf(ev)
challenge := AuthChallenge(ev) || (RunnerCall(ev) && st < 500)
if challenge {
return ClassClient, SubAuthChallenge, false
}
attackish := ev.Cat == Scanner || ev.Cat == Exploit || ev.Cat == BruteForce ||
(ev.Method != "" && !okMethods[strings.ToUpper(ev.Method)]) ||
ev.UA == "" || ev.E.Tool || (toolUARe.MatchString(ev.UA) && !registryUARe.MatchString(ev.UA)) ||
susp || NoRouter(ev)
if RunnerCall(ev) {
attackish = false
}
// the backend really failed: an application error, even if an attacker caused it
if ev.Retries > 0 && st >= 500 && !NoRouter(ev) {
return ClassProxy, "", false
}
if origin >= 500 && st >= 500 && !NoRouter(ev) {
return ClassApp, "", attackish
}
if attackish {
return ClassAttack, "", false
}
if st == 429 || ((st == 403 || st == 401) && origin == 0) {
return ClassBlocked, "", false
}
if ((st == 502 || st == 503 || st == 504) && origin == 0) || (ev.Retries > 0 && st >= 500) {
return ClassProxy, "", false
}
if st >= 500 {
return ClassProxy, "", false // a 5xx the backend did not produce
}
if st == 499 {
return ClassClient, SubCancelled, false // the client gave up: not a server error
}
if ev.E.Bot || crawlerUARe.MatchString(ev.UA) || (st == 404 && isBotPath(ev.Path)) {
return ClassBot, "", false
}
switch st {
case 404:
if sameSite(ev) {
return ClassClient, SubBrokenLink, false
}
if ev.Referer != "" && ev.Referer != "-" {
return ClassClient, SubExternalLink, false
}
case 401, 403:
if origin == st && browserLike(ev) {
return ClassClient, SubAuth, false
}
case 400, 405, 413, 422:
return ClassClient, SubValidation, false
}
return ClassClient, SubOther, false
}
+61
View File
@@ -0,0 +1,61 @@
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)
}
}
}
+14 -1
View File
@@ -149,7 +149,20 @@ type Event struct {
DurationNS int64
Bytes int64
Referer string
E Enrich
// FetchDest is Sec-Fetch-Dest ("document", "empty", "image"...), "" when the
// browser did not send it. Prefetch: Sec-Purpose / Purpose said prefetch.
FetchDest string
Prefetch bool
// Origin details (Traefik only, empty on older logs): what the backend
// answered and where the time went.
OriginStatus int
OriginNS, OverheadNS int64
OriginBytes int64
Retries int
Router, Service string
Proto, Scheme, TLSVer, TLSCiph string
EntryPoint, FetchSite string
E Enrich
}
// Enrich holds what the geo and user-agent databases say about an event. It is
+24
View File
@@ -51,8 +51,23 @@ type traefikLine struct {
Referer string `json:"request_Referer"`
FetchSite string `json:"request_Sec-Fetch-Site"`
FetchDest string `json:"request_Sec-Fetch-Dest"`
SecPurpose string `json:"request_Sec-Purpose"`
Purpose string `json:"request_Purpose"`
Duration int64 `json:"Duration"`
Size int64 `json:"DownstreamContentSize"`
OriginStatus int `json:"OriginStatus"`
OriginDur int64 `json:"OriginDuration"`
Overhead int64 `json:"Overhead"`
OriginSize int64 `json:"OriginContentSize"`
Retries int `json:"RetryAttempts"`
Router string `json:"RouterName"`
Service string `json:"ServiceName"`
Proto string `json:"RequestProtocol"`
Scheme string `json:"RequestScheme"`
TLSVer string `json:"TLSVersion"`
TLSCipher string `json:"TLSCipher"`
EntryPoint string `json:"entryPointName"`
}
// ParseTraefik parses one Traefik JSON access log line.
@@ -82,6 +97,15 @@ func ParseTraefik(line []byte) (Event, error) {
DurationNS: l.Duration, Bytes: l.Size, Referer: clip(l.Referer, 300),
}
ev.Framed = Framed(l.FetchSite, l.FetchDest)
ev.OriginStatus, ev.OriginNS, ev.OverheadNS, ev.OriginBytes, ev.Retries = l.OriginStatus, l.OriginDur, l.Overhead, l.OriginSize, l.Retries
ev.Router, ev.Service = clip(l.Router, 64), clip(l.Service, 64)
ev.Proto, ev.Scheme, ev.TLSVer, ev.TLSCiph = clip(l.Proto, 12), clip(l.Scheme, 8), clip(l.TLSVer, 8), clip(l.TLSCipher, 64)
ev.EntryPoint, ev.FetchSite = clip(l.EntryPoint, 64), clip(strings.ToLower(l.FetchSite), 16)
ev.FetchDest = strings.ToLower(strings.TrimSpace(l.FetchDest))
if len(ev.FetchDest) > 20 {
ev.FetchDest = ev.FetchDest[:20]
}
ev.Prefetch = strings.Contains(strings.ToLower(l.SecPurpose+" "+l.Purpose), "prefetch")
c := Classify(l.Method, l.Path, l.Status)
ev.Cat, ev.Soft, ev.Strong, ev.Weak = c.Cat, c.Soft, c.Strong, c.Weak
return ev, nil
+20
View File
@@ -31,3 +31,23 @@ func TestTraefikSecFetchFraming(t *testing.T) {
}
}
}
func TestTraefikFetchDestAndPrefetch(t *testing.T) {
base := `{"ClientHost":"8.8.8.8","RequestHost":"a.example","RequestMethod":"GET","RequestPath":"/","DownstreamStatus":200,"StartUTC":"2026-11-14T10:00:00Z"`
for _, tc := range []struct {
extra string
dest string
prefetch bool
}{
{``, "", false},
{`,"request_Sec-Fetch-Dest":"Document"`, "document", false},
{`,"request_Sec-Fetch-Dest":"empty"`, "empty", false},
{`,"request_Sec-Purpose":"prefetch;prerender"`, "", true},
{`,"request_Purpose":"prefetch"`, "", true},
} {
ev, err := ParseTraefik([]byte(base + tc.extra + `}`))
if err != nil || ev.FetchDest != tc.dest || ev.Prefetch != tc.prefetch {
t.Errorf("%s: dest=%q prefetch=%v err=%v", tc.extra, ev.FetchDest, ev.Prefetch, err)
}
}
}