carlos / platform Public

Edge protection: the hard tier blocks by default (catalogue v2)

Seven days of watch records on the flagship and Tito Go (2026-10-26 to
11-02, about 7.2M requests) show 39k hard-tier matches and no
legitimate one: every 2xx answer came from an app that answers every
path with its home page, except one tenant site that really serves its
.git directory, which is the leak this tier exists for. The 33 hard rules
(.env, .git, keys, dumps, traversal) move from watch to block, so the
default mode answers them with the 404 block page and a reference code.
The probe tier and the burst rule still watch: probe matches got real
2xx answers (a code forge's .sql files, /admin pages) and need learned
exemptions before they block.

An app's record-only switch (v0.33.5) still turns every block off for
that app. Catalogue version 2.

Tests that assumed the hard tier only watches now say which mode they
mean, and the burst and static tests restore the rule modes they change
instead of resetting them to watch. New witness:
TestGuardCatalogueBlocksHardWatchesProbe.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 975561b7d6d4065b15abf3bfc4587f9492862896 parent ab5b57b
8 files changed, +114 −65
  • internal/edge/burst_edge_test.go +22 −7
  • internal/edge/edge.go +2 −2
  • internal/edge/edgeerrors_test.go +1 −1
  • internal/edge/guard_test.go +38 −10
  • internal/edge/path_test.go +3 −0
  • internal/edge/static_guard_test.go +13 −10
  • internal/edgeguard/catalogue.go +1 −1
  • internal/edgeguard/catalogue.txt +34 −34

CI cancelled — superseded by a newer push — run details

diff --git a/internal/edge/burst_edge_test.go b/internal/edge/burst_edge_test.go
index a934ce340..eed075b06 100644
--- a/internal/edge/burst_edge_test.go
+++ b/internal/edge/burst_edge_test.go
@@ -406,11 +406,11 @@ func TestBurstOneVerdictPerRequest(t *testing.T) {
until := g.trip(t, burstHost)
g.meter.Drain()
matches := len(g.rec.match)
- g.get(burstHost, "/.env")
+ g.get(burstHost, "/wp-login.php")
if len(g.rec.match) != matches+1 {
t.Fatalf("%d matches for one request", len(g.rec.match)-matches)
}
- wantBurstMatch(t, g.lastMatch(t, "/.env"), reqrec.KindWatch, reqrec.CooldownFromThisApp, until)
+ wantBurstMatch(t, g.lastMatch(t, "/wp-login.php"), reqrec.KindWatch, reqrec.CooldownFromThisApp, until)
f := g.meter.Drain()
d, ok := f.Guard[usage.GuardKey(burstHost, "bdk", "shop")]
if len(f.Guard) != 1 || !ok || d.Checked != 1 || d.Watch != 1 || d.Block != 0 || !maps.Equal(d.Groups, map[string]int64{"burst/probe-burst": 1}) {
@@ -436,16 +436,22 @@ func TestBurstWatchNeverWeakensABlock(t *testing.T) {
}
})
t.Run("static rewrite", func(t *testing.T) {
- // The default mode, where the burst rule watches; the .env rule as
- // it will be once promoted to block.
+ // The default mode, where the burst rule watches and the .env rule
+ // blocks. The .git rule watches here, so a hard-tier request path
+ // whose own verdict does not block still reaches the static handler.
g := newBurstStaticRig(t, "", map[string]string{".env": "SECRET=1", "_redirects": "/* /.env 200\n"})
until := g.trip(t, burstHost)
env, ok := edgeguard.RuleByID("hard.secrets.env")
if !ok {
t.Fatal("no hard.secrets.env")
}
- env.Mode = edgeguard.ModeBlock
- t.Cleanup(func() { env.Mode = edgeguard.ModeWatch })
+ git, ok := edgeguard.RuleByID("hard.secrets.git")
+ if !ok {
+ t.Fatal("no hard.secrets.git")
+ }
+ envMode, gitMode := env.Mode, git.Mode
+ env.Mode, git.Mode = edgeguard.ModeBlock, edgeguard.ModeWatch
+ t.Cleanup(func() { env.Mode, git.Mode = envMode, gitMode })
matches := len(g.rec.match)
w := g.get(burstHost, "/wp-login.php")
if w.Code != 404 || w.Header().Get("X-Carlos-Ref") == "" || strings.Contains(w.Body.String(), "SECRET") {
@@ -791,7 +797,7 @@ func TestBurstStaleFillCountedOnceAtTheHome(t *testing.T) {
// promoteBurstRule sets the burst rule's catalogue mode to block for the
// test, as the later one-line promotion will: in the default mode the burst
-// rule then refuses while the hard and probe rules still only watch.
+// rule then refuses while the probe rules still only watch.
func promoteBurstRule(t *testing.T) {
t.Helper()
edgeguard.BurstRule.Mode = edgeguard.ModeBlock
@@ -822,6 +828,15 @@ func TestBurstNeverRefusesAnExistingStaticHardFile(t *testing.T) {
})
t.Run("burst rule promoted", func(t *testing.T) {
promoteBurstRule(t)
+ // With the .env rule watching (as an app's own allow rule will make
+ // it), a burst refusal still never takes a file the site has.
+ env, ok := edgeguard.RuleByID("hard.secrets.env")
+ if !ok {
+ t.Fatal("no hard.secrets.env")
+ }
+ envMode := env.Mode
+ env.Mode = edgeguard.ModeWatch
+ t.Cleanup(func() { env.Mode = envMode })
g := newBurstStaticRig(t, "", withEnv)
g.trip(t, burstHost)
if w := g.get(burstHost, "/.env"); w.Code != 200 || w.Body.String() != "SECRET=1" {
diff --git a/internal/edge/edge.go b/internal/edge/edge.go
index 5dbc88e01..e19487d51 100644
--- a/internal/edge/edge.go
+++ b/internal/edge/edge.go
@@ -294,8 +294,8 @@ type Edge struct {
gzipOn bool
// guard is CARLOS_EDGE_PROTECT, read once in New: what the edge does
// with a request matching a hard or probe rule (guard.go). By default
- // each rule's own mode, and in catalogue version 1 that is only ever to
- // watch.
+ // each rule's own mode: from catalogue version 2 the hard tier blocks
+ // and the probe tier watches.
guard guardMode
// guardMint is mintRef, bound once in New: a method value taken per
// request would allocate for every guarded request, and most never
diff --git a/internal/edge/edgeerrors_test.go b/internal/edge/edgeerrors_test.go
index c8ea9a4e4..995cd51a3 100644
--- a/internal/edge/edgeerrors_test.go
+++ b/internal/edge/edgeerrors_test.go
@@ -229,7 +229,7 @@ func TestEdgeFilesUnavailableByCause(t *testing.T) {
if got := do("busy.example.com", "/sandbox"); got != 503 {
t.Fatalf("busy status = %d", got)
}
- if do("dead.example.com", "/.env") != 502 || do("dead.example.com", "/phpinfo.php") != 502 {
+ if do("dead.example.com", "/login") != 502 || do("dead.example.com", "/phpinfo.php") != 502 {
t.Fatal("a refused dial must answer 502")
}
recs := sink.snap()
diff --git a/internal/edge/guard_test.go b/internal/edge/guard_test.go
index 85e41441c..54f7f5ae8 100644
--- a/internal/edge/guard_test.go
+++ b/internal/edge/guard_test.go
@@ -90,11 +90,12 @@ func (g *guardRig) get(path string) *httptest.ResponseRecorder {
return w
}
-// In the default mode every rule of catalogue version 1 only watches: the
-// probe goes through, the visitor gets the app's own answer, and the one
-// record for it is a watch carrying that answer's status.
+// In watch mode every rule only watches: the probe goes through, the visitor
+// gets the app's own answer, and the one record for it is a watch carrying
+// that answer's status.
func TestGuardWatchForwards(t *testing.T) {
g := guardEdge(t, false, false, http.StatusNotFound, "the app's own 404")
+ g.e.guard = guardWatch
w := g.get("/.env")
if w.Code != 404 || w.Body.String() != "the app's own 404" || g.upstream.Load() != 1 {
t.Fatalf("got %d %q, upstream %d", w.Code, w.Body.String(), g.upstream.Load())
@@ -138,6 +139,30 @@ func TestGuardWatchRecordsUpstreamStatus(t *testing.T) {
}
}
+// In the default mode, from catalogue version 2, the hard tier blocks and the
+// probe tier still only watches: /.env never reaches the app, /wp-login.php
+// does and gets the app's own answer.
+func TestGuardCatalogueBlocksHardWatchesProbe(t *testing.T) {
+ g := guardEdge(t, false, false, http.StatusNotFound, "the app's own 404")
+ if g.e.guard != guardCatalogue {
+ t.Fatalf("guard mode %v, want the catalogue's", g.e.guard)
+ }
+ w := g.get("/.env")
+ if w.Code != 404 || w.Header().Get("X-Carlos-Ref") == "" || strings.Contains(w.Body.String(), "the app's own 404") || g.upstream.Load() != 0 {
+ t.Fatalf("/.env: %d %q, upstream %d; want the block page", w.Code, w.Body.String(), g.upstream.Load())
+ }
+ if m := g.rec.match[len(g.rec.match)-1]; m.Kind != reqrec.KindBlock || m.RuleID != "hard.secrets.env" {
+ t.Fatalf("/.env: match %+v, want the hard block", m)
+ }
+ w = g.get("/wp-login.php")
+ if w.Code != 404 || w.Body.String() != "the app's own 404" || w.Header().Get("X-Carlos-Ref") != "" || g.upstream.Load() != 1 {
+ t.Fatalf("/wp-login.php: %d %q, upstream %d; want the app's answer", w.Code, w.Body.String(), g.upstream.Load())
+ }
+ if m := g.rec.match[len(g.rec.match)-1]; m.Kind != reqrec.KindWatch || m.RuleID != "probe.wordpress.wp-login" {
+ t.Fatalf("/wp-login.php: match %+v, want the probe watch", m)
+ }
+}
+
// In block mode a hard-tier probe is answered here with the block page: a
// 404 whose body and header carry one sealed code naming the rule. Nothing
// behind the edge sees the request.
@@ -312,11 +337,14 @@ func (s *fieldSink) EdgeSummary(acct, app, host, level, msg string, f map[string
// request's spelling. Through the real recorder, so this is what is stored.
func TestGuardFragmentKeepsNoToken(t *testing.T) {
const token = "AbCd12_EfGh34_IjKl56_MnOp78"
- for _, tc := range []struct{ name, path, frag string }{
- {"underscores", "/wp-admin/" + token, "/wp-admin"},
- {"hyphens", "/WP-Admin/AbCd12-EfGh34-IjKl56-MnOp78", "/WP-Admin"},
- {"slashes", "/wp-admin/AbCd12/EfGh34/IjKl56/MnOp78", "/wp-admin"},
- {"under a segseq", "/Proc/Self/AbCd12_EfGh34_IjKl56_MnOp78", "Proc/Self"},
+ for _, tc := range []struct {
+ name, path, frag string
+ kind reqrec.Kind
+ }{
+ {"underscores", "/wp-admin/" + token, "/wp-admin", reqrec.KindWatch},
+ {"hyphens", "/WP-Admin/AbCd12-EfGh34-IjKl56-MnOp78", "/WP-Admin", reqrec.KindWatch},
+ {"slashes", "/wp-admin/AbCd12/EfGh34/IjKl56/MnOp78", "/wp-admin", reqrec.KindWatch},
+ {"under a segseq", "/Proc/Self/AbCd12_EfGh34_IjKl56_MnOp78", "Proc/Self", reqrec.KindBlock},
} {
g := guardEdge(t, false, false, http.StatusNotFound, "no")
sink := &fieldSink{}
@@ -326,8 +354,8 @@ func TestGuardFragmentKeepsNoToken(t *testing.T) {
t.Fatalf("%s: %d records, want 1", tc.name, len(sink.recs))
}
f := sink.recs[0]
- if f["kind"] != string(reqrec.KindWatch) || f["frag"] != tc.frag {
- t.Fatalf("%s: kind %q frag %q, want watch and %q", tc.name, f["kind"], f["frag"], tc.frag)
+ if f["kind"] != string(tc.kind) || f["frag"] != tc.frag {
+ t.Fatalf("%s: kind %q frag %q, want %s and %q", tc.name, f["kind"], f["frag"], tc.kind, tc.frag)
}
for _, piece := range []string{"AbCd12", "EfGh34", "IjKl56", "MnOp78"} {
for _, spelt := range []string{piece, strings.ToLower(piece)} {
diff --git a/internal/edge/path_test.go b/internal/edge/path_test.go
index 5a8cb7ff8..c86b40a3c 100644
--- a/internal/edge/path_test.go
+++ b/internal/edge/path_test.go
@@ -205,6 +205,9 @@ func TestPathMatchTriesBothFormsOfTheFirstSegment(t *testing.T) {
upsertPath(t, reg, "ti.to", "flipped", "go.tito.io")
upsertPath(t, reg, "ti.to", "onbeta", "beta.tito.io")
+ // The hard tier blocks a raw ".." by default; this test is about the
+ // path matcher behind it, so protection is off.
+ t.Setenv("CARLOS_EDGE_PROTECT", "off")
e, err := New(reg, nil)
if err != nil {
t.Fatal(err)
diff --git a/internal/edge/static_guard_test.go b/internal/edge/static_guard_test.go
index faae416a1..c4a99b2b0 100644
--- a/internal/edge/static_guard_test.go
+++ b/internal/edge/static_guard_test.go
@@ -163,11 +163,12 @@ func TestStaticExplicitRedirectIsExistence(t *testing.T) {
// A rewrite onto a file the hard tier names is not served as a rewrite: the
// request path looked harmless, the file it would send is a leak. Watching
-// records it and serves the file; blocking answers with the guard's 404.
+// records it and serves the file; blocking (the default, and block mode)
+// answers with the guard's 404.
func TestStaticRewriteToHardFile(t *testing.T) {
files := map[string]string{".env": "SECRET=1", "_redirects": "/download /.env 200\n"}
- g := staticGuardEdge(t, guardCatalogue, files)
+ g := staticGuardEdge(t, guardWatch, files)
if w := g.get("/download"); w.Code != 200 || w.Body.String() != "SECRET=1" {
t.Fatalf("watch: %d %q, want the file served", w.Code, w.Body.String())
}
@@ -176,14 +177,16 @@ func TestStaticRewriteToHardFile(t *testing.T) {
t.Fatalf("watch: match %+v", m)
}
- g = staticGuardEdge(t, guardBlock, files)
- w := g.get("/download")
- if w.Code != 404 || w.Header().Get("X-Carlos-Ref") == "" || w.Body.String() == "SECRET=1" {
- t.Fatalf("block: %d ref %q body %q", w.Code, w.Header().Get("X-Carlos-Ref"), w.Body.String())
- }
- m = g.onlyMatch(t)
- if m.Kind != reqrec.KindBlock || m.Tier != reqrec.TierHard || m.RuleID != "hard.secrets.env" || m.Ref != w.Header().Get("X-Carlos-Ref") {
- t.Fatalf("block: match %+v", m)
+ for _, mode := range []guardMode{guardCatalogue, guardBlock} {
+ g = staticGuardEdge(t, mode, files)
+ w := g.get("/download")
+ if w.Code != 404 || w.Header().Get("X-Carlos-Ref") == "" || w.Body.String() == "SECRET=1" {
+ t.Fatalf("mode %d: %d ref %q body %q", mode, w.Code, w.Header().Get("X-Carlos-Ref"), w.Body.String())
+ }
+ m = g.onlyMatch(t)
+ if m.Kind != reqrec.KindBlock || m.Tier != reqrec.TierHard || m.RuleID != "hard.secrets.env" || m.Ref != w.Header().Get("X-Carlos-Ref") {
+ t.Fatalf("mode %d: match %+v", mode, m)
+ }
}
}
diff --git a/internal/edgeguard/catalogue.go b/internal/edgeguard/catalogue.go
index e6070930f..111686ca5 100644
--- a/internal/edgeguard/catalogue.go
+++ b/internal/edgeguard/catalogue.go
@@ -104,7 +104,7 @@ var catalogueData []byte
// removed or changed, so a log line can say which catalogue produced it. It
// must equal the "# version N" line in catalogue.txt, and init panics if the
// two disagree, so a rule edit that forgets one of them fails the tests.
-const Version = 1
+const Version = 2
var (
rules []Rule
diff --git a/internal/edgeguard/catalogue.txt b/internal/edgeguard/catalogue.txt
index 0b7cc81f0..2684f91d1 100644
--- a/internal/edgeguard/catalogue.txt
+++ b/internal/edgeguard/catalogue.txt
@@ -1,38 +1,38 @@
-# version 1
+# version 2
# tier group name kind pattern mode
-hard traversal dotdot dotdot - watch
-hard traversal proc-self segseq proc/self watch
-hard traversal vite-fs segment @fs watch
-hard secrets env segment .env watch
-hard secrets env-variant segglob .env.* watch
-hard secrets git segment .git watch
-hard secrets git-credentials segment .git-credentials watch
-hard secrets svn segment .svn watch
-hard secrets hg segment .hg watch
-hard secrets aws segment .aws watch
-hard secrets ssh segment .ssh watch
-hard secrets docker segment .docker watch
-hard secrets kube segment .kube watch
-hard secrets npmrc segment .npmrc watch
-hard secrets pypirc segment .pypirc watch
-hard secrets netrc segment .netrc watch
-hard secrets htpasswd segment .htpasswd watch
-hard keys id-rsa segment id_rsa watch
-hard keys id-dsa segment id_dsa watch
-hard keys id-ecdsa segment id_ecdsa watch
-hard keys id-ed25519 segment id_ed25519 watch
-hard keys credentials-json segment credentials.json watch
-hard keys gcp-credentials segment gcp-credentials.json watch
-hard keys firebase-admin segglob firebase-adminsdk*.json watch
-hard dumps db-sql exact /db.sql watch
-hard dumps dump-sql exact /dump.sql watch
-hard dumps backup-sql exact /backup.sql watch
-hard dumps database-sql exact /database.sql watch
-hard source php-save ext .php.save watch
-hard source php-bak ext .php.bak watch
-hard source php-old ext .php.old watch
-hard source php-swp ext .php.swp watch
-hard source php-tilde ext .php~ watch
+hard traversal dotdot dotdot - block
+hard traversal proc-self segseq proc/self block
+hard traversal vite-fs segment @fs block
+hard secrets env segment .env block
+hard secrets env-variant segglob .env.* block
+hard secrets git segment .git block
+hard secrets git-credentials segment .git-credentials block
+hard secrets svn segment .svn block
+hard secrets hg segment .hg block
+hard secrets aws segment .aws block
+hard secrets ssh segment .ssh block
+hard secrets docker segment .docker block
+hard secrets kube segment .kube block
+hard secrets npmrc segment .npmrc block
+hard secrets pypirc segment .pypirc block
+hard secrets netrc segment .netrc block
+hard secrets htpasswd segment .htpasswd block
+hard keys id-rsa segment id_rsa block
+hard keys id-dsa segment id_dsa block
+hard keys id-ecdsa segment id_ecdsa block
+hard keys id-ed25519 segment id_ed25519 block
+hard keys credentials-json segment credentials.json block
+hard keys gcp-credentials segment gcp-credentials.json block
+hard keys firebase-admin segglob firebase-adminsdk*.json block
+hard dumps db-sql exact /db.sql block
+hard dumps dump-sql exact /dump.sql block
+hard dumps backup-sql exact /backup.sql block
+hard dumps database-sql exact /database.sql block
+hard source php-save ext .php.save block
+hard source php-bak ext .php.bak block
+hard source php-old ext .php.old block
+hard source php-swp ext .php.swp block
+hard source php-tilde ext .php~ block
probe wordpress wp-login exact /wp-login.php watch
probe wordpress xmlrpc exact /xmlrpc.php watch
probe wordpress wp-links-opml exact /wp-links-opml.php watch