edge: key the plan-disabled log throttle on the route, not the Host
planDisabledAdmit called logThrottled("plan-disabled "+host, ...) with
the request's own host. Under a one-label catch-all (*.parent) every
invented label resolves to the same route, so once that route or its
parent was turned off after a lapse, each new subdomain a stranger
sent added a permanent logN entry and a journal line. logThrottled's
contract forbids keys built from remote input.
The key is now the matched route's host (registry data the box
controls), so a catch-all costs one entry however many names hit it.
The line names the route and, when the request's host differs, that
host quoted (strconv.Quote), so the first and every 300th line still
say which name was answered without letting the Host shape the line.
Test: TestDisabledCatchAllLogsOncePerRoute turns off *.lapsed.example,
sends 50 invented subdomains, and expects the disabled page for each
and exactly one throttle entry counting 50. It failed on the old key
(50 entries).
Audit 2026-11-16, activator-edge "bugs found along the way" 1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+47
−1
internal/edge/plandisabled.go+10 −1internal/edge/plandisabled_test.go+37 −0
CI cancelled — superseded by a newer push — run details
diff --git a/internal/edge/plandisabled.go b/internal/edge/plandisabled.go| index 6b55307b7..eb2198b84 100644 |
| --- a/internal/edge/plandisabled.go |
| +++ b/internal/edge/plandisabled.go |
| @@ -4,6 +4,7 @@ import ( |
| "bytes" |
| "html/template" |
| "net/http" |
| + "strconv" |
| "github.com/carlosframework/platform/internal/registry" |
| ) |
| @@ -77,7 +78,15 @@ func (e *Edge) planDisabledAdmit(w http.ResponseWriter, r *http.Request, host st |
| if f == nil || rt.Kind == "status" || !(*f)(rt, host) { |
| return true |
| } |
| - e.logThrottled("plan-disabled "+host, "plan: answered "+host+" with the disabled page (turned off after a lapse)") |
| + // Keyed on the route, never the request's host: under a catch-all every |
| + // invented label would add a map entry and a journal line |
| + // (logThrottled's contract). The line names the route and, when it |
| + // differs, the host of the request that was logged, quoted. |
| + msg := "plan: answered " + rt.Host + " with the disabled page (turned off after a lapse)" |
| + if host != rt.Host { |
| + msg += " for host " + strconv.Quote(host) |
| + } |
| + e.logThrottled("plan-disabled "+rt.Host, msg) |
| h := w.Header() |
| h.Set("Content-Type", "text/html; charset=utf-8") |
| h.Set("Cache-Control", "no-store") |
diff --git a/internal/edge/plandisabled_test.go b/internal/edge/plandisabled_test.go| index 19ace8d89..3dd12fdb0 100644 |
| --- a/internal/edge/plandisabled_test.go |
| +++ b/internal/edge/plandisabled_test.go |
| @@ -1,6 +1,7 @@ |
| package edge |
| import ( |
| + "fmt" |
| "net/http" |
| "net/http/httptest" |
| "strings" |
| @@ -110,3 +111,39 @@ func TestNoDisabledHookUnchanged(t *testing.T) { |
| t.Fatalf("a hook answering false: %d", rec.Code) |
| } |
| } |
| + |
| +// TestDisabledCatchAllLogsOncePerRoute: the throttled log line is keyed on |
| +// the route a request resolved to, never on the request's host. Under a |
| +// turned-off catch-all every invented label is answered with the page, and |
| +// all of them share one throttle entry, so a stranger cannot grow the map |
| +// (or the journal) one subdomain at a time. |
| +func TestDisabledCatchAllLogsOncePerRoute(t *testing.T) { |
| + t.Parallel() |
| + const catchAll = "*.lapsed.example" |
| + srv, backend := newGateBackend(t, "app", "") |
| + reg := openReg(t) |
| + if err := reg.Upsert(registry.Route{Host: catchAll, Kind: "instance", Addr: srv.Listener.Addr().String(), |
| + Status: "ready", App: "shop", Account: "bab"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + e, err := New(reg, &fakeActivator{}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(e.probers.Stop) |
| + e.SetPlanDisabledFor(func(rt registry.Route, _ string) bool { return rt.Host == catchAll }) |
| + |
| + const n = 50 |
| + for i := range n { |
| + host := fmt.Sprintf("invented-%d.lapsed.example", i) |
| + wantDisabledPage(t, gateDo(e, http.MethodGet, host, "/", ""), host) |
| + } |
| + if seen, _ := backend.seen(); seen != 0 { |
| + t.Fatalf("upstream saw %d requests, want none", seen) |
| + } |
| + e.logMu.Lock() |
| + defer e.logMu.Unlock() |
| + if len(e.logN) != 1 || e.logN["plan-disabled "+catchAll] != n { |
| + t.Fatalf("throttle map %v, want one entry for %s counting %d", e.logN, catchAll, n) |
| + } |
| +} |