fix: 1.4.8 egress false positives (non-SYN replies, IMDS on host, Akamai/Telegram)
Release / Publish tags (push) Successful in 13s
Release / Plan (reuse the published image?) (push) Successful in 5s
Release / ci (push) Successful in 1m20s
Release / Build image (amd64) (push) Successful in 24s
Release / Build image (arm64) (push) Successful in 1m11s
Release / Gitea release (push) Skipped
CI / Format and vet (push) Successful in 51s
CI / Tests (Linux, race detector) (push) Successful in 50s
CI / Dependency audit (push) Successful in 29s
CI / Docker image (build and smoke test) (push) Skipped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-15 08:51:42 -03:00
1 parent 873219416f
commit 3ae72e27d6
8 files changed
+175 -13

No files matched your search

+54 -6
View File
@@ -2,6 +2,7 @@ package egress
import (
"container/list"
"errors"
"fmt"
"hash/fnv"
"math"
@@ -223,9 +224,9 @@ type Engine struct {
closed []BurstOut
maxT int64
lines, malformed atomic.Uint64
last atomic.Int64
stateFn atomic.Pointer[func() string]
lines, malformed, nonSYN atomic.Uint64
last atomic.Int64
stateFn atomic.Pointer[func() string]
}
// New builds an engine.
@@ -356,6 +357,10 @@ func (e *Engine) reloadMap() {
func (e *Engine) Ingest(line []byte) {
ev, err := ParseLine(line, e.now())
if err != nil {
if errors.Is(err, ErrNonSYN) {
e.nonSYN.Add(1)
return
}
if len(line) > 0 {
e.malformed.Add(1)
}
@@ -761,6 +766,9 @@ func (e *Engine) beacon(ws *wstate, ev Event, dport uint16, dns bool, p *pairSta
}
}
}
if ev.Host && isCloudMetadata(ev.Dst) {
kind = "infra"
}
if f := e.addFinding(kind, "", ws.name, ev.Dst.String(), dport, ev.Proto, p.last, p.interval, p.cv, "", 1); f != nil {
if n := len(f.Samples); n == 0 || f.Samples[n-1] != p.last {
if n >= MaxSamples {
@@ -827,16 +835,23 @@ func (e *Engine) beacon(ws *wstate, ev Event, dport uint16, dns bool, p *pairSta
bad, sev, why = true, "high", why+"; destination: "+r
}
}
if !bad && e.cfg.Geo != nil {
if !bad && ev.Host && isCloudMetadata(ev.Dst) {
// only the host itself: a container reaching IMDS stays a finding (SSRF/credential theft)
sev, kind = "info", "infra"
why += "; provider service (cloud metadata)"
} else if !bad && e.cfg.Geo != nil {
_, asn, org := e.cfg.Geo(ev.Dst.String())
switch {
case ev.Host && e.providerASN(asn):
sev, kind = "info", "infra"
why = fmt.Sprintf("%s; provider service (%s)", why, org)
case commonCloudASNs[asn]:
case commonCloudASNs[asn] || inCommonCDN(ev.Dst):
sev = "low"
why += "; large CDN/cloud network: regular connections are common for API calls"
}
} else if !bad && inCommonCDN(ev.Dst) {
sev = "low"
why += "; large CDN/cloud network: regular connections are common for API calls"
}
p.flagged, p.interval, p.cv = true, med, jit
f := e.addFinding(kind, sev, ws.name, ev.Dst.String(), dport, ev.Proto, p.last, med, jit, why, 0)
@@ -851,7 +866,40 @@ func (e *Engine) beacon(ws *wstate, ev Event, dport uint16, dns bool, p *pairSta
// commonCloudASNs are large CDNs/clouds whose regular connections usually are
// API calls.
var commonCloudASNs = map[string]bool{"AS13335": true, "AS15169": true, "AS14618": true, "AS16509": true, "AS8075": true, "AS20940": true, "AS54113": true}
var commonCloudASNs = map[string]bool{"AS13335": true, "AS15169": true, "AS14618": true, "AS16509": true, "AS8075": true, "AS20940": true, "AS54113": true,
"AS16625": true, // Akamai
"AS62041": true, // Telegram
}
// commonCDNPrefixes back the ASN list when the geo database has no entry:
// Akamai and the Telegram API.
var commonCDNPrefixes = mustPrefixes("23.0.0.0/12", "104.64.0.0/10", "184.24.0.0/13", "2.16.0.0/13",
"149.154.160.0/20", "91.108.0.0/16")
// cloudMetadata are the metadata services of the clouds (IMDS), IPv4 and
// IPv6; link-local addresses are included.
var cloudMetadata = mustPrefixes("169.254.0.0/16", "fe80::/10", "fd00:c1::a9fe:a9fe/128", "fd00:ec2::254/128")
func mustPrefixes(s ...string) []netip.Prefix {
out := make([]netip.Prefix, len(s))
for i, v := range s {
out[i] = netip.MustParsePrefix(v)
}
return out
}
func inPrefixes(a netip.Addr, ps []netip.Prefix) bool {
a = a.Unmap()
for _, p := range ps {
if p.Contains(a) {
return true
}
}
return false
}
func inCommonCDN(a netip.Addr) bool { return inPrefixes(a, commonCDNPrefixes) }
func isCloudMetadata(a netip.Addr) bool { return inPrefixes(a, cloudMetadata) }
func (e *Engine) providerASN(asn string) bool {
if asn == "" {