carlos / platform Public

edge: a far match is recorded once across the edges; its hops carry a checked mark (asset cache plan 3 final F1, fix wave 2)

The far catch now records a request its checks matched once, however it
was answered: a hit, a waiter's hit, the block page, a throttle refusal,
a fill or a re-forward. A cold watched fill with the home's protection
off was recorded by no one before.

So that the home does not record it a second time, every hop the far
edge sends for a matched request (the fill and any re-forward) carries
X-Carlos-Hop-Checked, signed at send time with the mesh key in its own
MAC domain (signHopChecked), like the door mark. acceptHop deletes it
from every request and honours it only beside a verified hop; the home
then skips its checks and its request record for that hop, as for a
tunnel delivery. Unmatched requests carry no mark and are recorded by
the home as before.

Witnesses: TestAssetE2EFarGuardRecordsOnce (two real edges: far watch +
home off, far watch + home watch, far block),
TestFarReforwardIsRecordedOnceAcrossTheEdges (real far and home edges),
TestCheckedMarkCountsOnlyBesideAVerifiedHop.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev c0b2a6fbbca5c4c25d766f0a7f38ddf48ca690d8 parent 986ebe7
7 files changed, +310 −25
  • internal/edge/asset_e2e_test.go +116 −0
  • internal/edge/asset_far_test.go +101 −4
  • internal/edge/assetcatch.go +35 −13
  • internal/edge/edge.go +5 −2
  • internal/edge/homemap.go +27 −4
  • internal/edge/mesh.go +22 −0
  • internal/edge/reqrecords.go +4 −2
diff --git a/internal/edge/asset_e2e_test.go b/internal/edge/asset_e2e_test.go
index 62e45ce27..25d5cbf14 100644
--- a/internal/edge/asset_e2e_test.go
+++ b/internal/edge/asset_e2e_test.go
@@ -51,6 +51,7 @@ import (
"github.com/carlosframework/platform/internal/assetcache"
"github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/reqrec"
)
// e2eGen2 is the generation a purge draws.
@@ -1415,3 +1416,118 @@ func TestAssetE2EGenerationOrOwnerMismatchGetsNoAck(t *testing.T) {
})
}
}
+
+// ---- protection recorded once across the two edges (fix wave 2) ----------
+
+// lockedRecorder keeps request records filed from server goroutines.
+type lockedRecorder struct {
+ mu sync.Mutex
+ resp []reqrec.Response
+ match []reqrec.Match
+}
+
+func (l *lockedRecorder) Response(x reqrec.Response) {
+ l.mu.Lock()
+ defer l.mu.Unlock()
+ l.resp = append(l.resp, x)
+}
+
+func (l *lockedRecorder) Match(x reqrec.Match) {
+ l.mu.Lock()
+ defer l.mu.Unlock()
+ l.match = append(l.match, x)
+}
+
+func (l *lockedRecorder) counts() (resp, match int, last reqrec.Match) {
+ l.mu.Lock()
+ defer l.mu.Unlock()
+ if n := len(l.match); n > 0 {
+ last = l.match[n-1]
+ }
+ return len(l.resp), len(l.match), last
+}
+
+// A far request for a cached asset path a protection rule matches
+// (/assets/.env, hard tier) is recorded exactly once across the two edges,
+// by the far edge, whatever the home's own mode: on the cold fill and on the
+// warm hit. With far protection watching and the home's off, the fill is
+// not lost; with both watching, the home does not record it a second time
+// (the fill hop carries the far edge's checked mark). With far protection
+// blocking, the far edge answers the block page and the home never sees the
+// request. An unmatched path is unchanged: no mark, recorded by the home.
+func TestAssetE2EFarGuardRecordsOnce(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ far, home guardMode
+ }{
+ {"far watch, home off", guardWatch, guardOff},
+ {"far watch, home watch", guardWatch, guardWatch},
+ {"far block, home watch", guardBlock, guardWatch},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ x := newAssetE2E(t, assetE2EOpts{handler: assetOK(laBody)})
+ x.a.edge.guard, x.b.edge.guard = tc.home, tc.far
+ homeRec, farRec := &lockedRecorder{}, &lockedRecorder{}
+ x.a.edge.EnableRequestRecords(homeRec)
+ x.b.edge.EnableRequestRecords(farRec)
+ block := tc.far == guardBlock
+ for i, cache := range []string{"miss", "hit"} {
+ resp, body := x.fetch(t, x.b, "/assets/.env")
+ x.rows(t) // every handler on both edges has returned
+ if block {
+ if resp.StatusCode != http.StatusNotFound || resp.Header.Get("X-Carlos-Ref") == "" {
+ t.Fatalf("request %d = %d ref %q, want the block page", i, resp.StatusCode, resp.Header.Get("X-Carlos-Ref"))
+ }
+ } else {
+ wantE2ECache(t, resp, cache)
+ if resp.StatusCode != http.StatusOK || body != laBody {
+ t.Fatalf("request %d = %d %q", i, resp.StatusCode, body)
+ }
+ }
+ hr, hm, _ := homeRec.counts()
+ fr, fm, m := farRec.counts()
+ if hr != 0 || hm != 0 || fr != 0 || fm != i+1 {
+ t.Fatalf("after request %d: home %d responses %d matches, far %d responses %d matches; want the far edge's one match each",
+ i, hr, hm, fr, fm)
+ }
+ wantKind := reqrec.KindWatch
+ if block {
+ wantKind = reqrec.KindBlock
+ }
+ if m.Kind != wantKind || m.RuleID != "hard.secrets.env" || m.Acct != "abc" || m.App != "shop" || m.Path != "/assets/.env" {
+ t.Fatalf("request %d recorded %+v", i, m)
+ }
+ }
+ if block {
+ if n := x.a.calls.Load(); n != 0 {
+ t.Fatalf("the home saw %d request(s) the far edge blocked", n)
+ }
+ } else {
+ req, _ := x.aTap.last()
+ if mark := req.Get(hopCheckedHeader); !verifyHopCheckedEitherKey(x.key, nil, laHost, mark, time.Now()) {
+ t.Fatalf("the fill hop carried checked mark %q, want a valid one", mark)
+ }
+ if got := x.app.lastReq().Header.Get(hopCheckedHeader); got != "" {
+ t.Fatalf("the home's app received the checked mark %q", got)
+ }
+ }
+ if tc.home != guardWatch || block {
+ return
+ }
+ // An unmatched asset: no mark, and the home records the fill
+ // hop as before.
+ resp, _ := x.fetch(t, x.b, "/assets/app.js")
+ x.rows(t)
+ wantE2ECache(t, resp, "miss")
+ if req, _ := x.aTap.last(); req.Get(hopCheckedHeader) != "" {
+ t.Fatal("an unmatched fill carried the checked mark")
+ }
+ if hr, hm, _ := homeRec.counts(); hr != 1 || hm != 0 {
+ t.Fatalf("an unmatched fill: home %d responses %d matches, want one response", hr, hm)
+ }
+ if fr, fm, _ := farRec.counts(); fr != 0 || fm != 2 {
+ t.Fatalf("an unmatched fill: far %d responses %d matches, want nothing new", fr, fm)
+ }
+ })
+ }
+}
diff --git a/internal/edge/asset_far_test.go b/internal/edge/asset_far_test.go
index 9cff2b9b3..4b5f58869 100644
--- a/internal/edge/asset_far_test.go
+++ b/internal/edge/asset_far_test.go
@@ -1146,12 +1146,23 @@ func TestFarHitsMeetTheGuard(t *testing.T) {
rec := &memRecorder{}
s.e.EnableRequestRecords(rec)
s.e.guard = guardWatch
- for p := range rules {
+ for p, want := range rules {
wantCache(t, s.get(t, p), "miss")
+ // The fill is recorded here, once, and its hop tells the
+ // home so with the checked mark (fix wave 2).
+ if len(rec.match) == 0 {
+ t.Fatalf("watched far fill of %s recorded nothing", p)
+ }
+ if m := rec.match[len(rec.match)-1]; m.Kind != reqrec.KindWatch || m.RuleID != want.id || m.Path != p || m.WokeKnown {
+ t.Fatalf("watched far fill of %s recorded %+v", p, m)
+ }
+ mark := s.rec.get().header.Get(hopCheckedHeader)
+ if !verifyHopCheckedEitherKey(s.meshKey, nil, laHost, mark, time.Now()) {
+ t.Fatalf("the fill hop for %s carried checked mark %q, want a valid one", p, mark)
+ }
}
- // A fill reached the home as a hop, and the home records it.
- if len(rec.match) != 0 || len(rec.resp) != 0 {
- t.Fatalf("the far edge recorded fills: matches %+v responses %+v", rec.match, rec.resp)
+ if len(rec.match) != len(rules) || len(rec.resp) != 0 {
+ t.Fatalf("watched fills recorded matches %+v responses %+v, want one match each", rec.match, rec.resp)
}
s.meter.Drain()
@@ -1286,3 +1297,89 @@ func TestUncaughtLocalInformationalVocabularyIsScrubbed(t *testing.T) {
})
}
}
+
+// ---- the checked mark (fix wave 2) ----------------------------------------
+
+// A buffered far request the far edge's checks matched, whose fill the home
+// app vetoes with a late Set-Cookie trailer, is re-forwarded: two hops reach
+// the real home edge, the fill and the re-forward. Both carry the checked
+// mark, so the watching home records neither, and the far edge records the
+// request once.
+func TestFarReforwardIsRecordedOnceAcrossTheEdges(t *testing.T) {
+ var home *laScene
+ homeRec := &lockedRecorder{}
+ s := newFarEdge(t, func(key []byte, m *homeMap) http.Handler {
+ home = newLAScene(t, func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/javascript")
+ w.Header().Set("Cache-Control", "public, max-age=3600")
+ w.Header().Set("Trailer", "Set-Cookie")
+ io.WriteString(w, laBody)
+ w.(http.Flusher).Flush()
+ w.Header().Set("Set-Cookie", "late=1")
+ })
+ hm := newHomeMap(m.s, "betty")
+ refreshHomeMap(t, hm)
+ home.e.homes.Store(hm)
+ home.e.guard = guardWatch
+ home.e.EnableRequestRecords(homeRec)
+ return home.e
+ })
+ farRec := &lockedRecorder{}
+ s.e.EnableRequestRecords(farRec)
+ s.e.guard = guardWatch
+ rec := s.get(t, "/assets/.env", "Range", "bytes=0-6")
+ wantCache(t, rec, "bypass")
+ if rec.Code != 200 || rec.Body.String() != laBody {
+ t.Fatalf("re-forwarded = %d %q, want the app's whole answer", rec.Code, rec.Body.String())
+ }
+ if n := home.b.n.Load(); n != 3 {
+ t.Fatalf("the app saw %d requests, want 3 (the far fill, the home's own fill, the re-forward)", n)
+ }
+ if hr, hm, _ := homeRec.counts(); hr != 0 || hm != 0 {
+ t.Fatalf("the home recorded %d responses and %d matches, want none", hr, hm)
+ }
+ fr, fm, m := farRec.counts()
+ if fr != 0 || fm != 1 || m.Kind != reqrec.KindWatch || m.RuleID != "hard.secrets.env" || m.Status != 200 || m.WokeKnown {
+ t.Fatalf("the far edge recorded %d responses, %d matches, last %+v; want one watch match", fr, fm, m)
+ }
+}
+
+// The checked mark counts only beside a verified hop, and only in its own MAC
+// domain: a client's mark, even one signed with the mesh key, and a hop
+// signature passed off as a mark both leave the home's checks and record in
+// place. The mark never reaches the app.
+func TestCheckedMarkCountsOnlyBesideAVerifiedHop(t *testing.T) {
+ s := newLAScene(t, assetOK(laBody))
+ key := s.armMesh(t)
+ rec := &memRecorder{}
+ s.e.EnableRequestRecords(rec)
+ s.e.guard = guardWatch
+ for _, tc := range []struct {
+ name string
+ hop bool
+ mark func() string
+ recorded bool
+ }{
+ {"a client's mark", false, func() string { return signHopChecked(key, laHost, time.Now()) }, true},
+ {"a hop signature as the mark", true, func() string { return signHop(key, laHost, time.Now()) }, true},
+ {"a verified hop's mark", true, func() string { return signHopChecked(key, laHost, time.Now()) }, false},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ before := len(rec.match)
+ req := httptest.NewRequest(http.MethodGet, "http://"+laHost+"/.env", nil)
+ req.Header.Set(hopCheckedHeader, tc.mark())
+ if tc.hop {
+ req.Header.Set(hopHeader, "1")
+ req.Header.Set(hopAuthHeader, signHop(key, laHost, time.Now()))
+ }
+ w := httptest.NewRecorder()
+ s.e.ServeHTTP(w, req)
+ if got := len(rec.match) - before; (got == 1) != tc.recorded || got > 1 {
+ t.Fatalf("%d match(es) recorded at the home, want recorded=%v", got, tc.recorded)
+ }
+ if v := s.b.lastReq().Header.Get(hopCheckedHeader); v != "" {
+ t.Fatalf("the app received the checked mark %q", v)
+ }
+ })
+ }
+}
diff --git a/internal/edge/assetcatch.go b/internal/edge/assetcatch.go
index ec998dcd7..17ffae4bb 100644
--- a/internal/edge/assetcatch.go
+++ b/internal/edge/assetcatch.go
@@ -1039,8 +1039,10 @@ func (e *Edge) farAssetCatch(r *http.Request, host string) (a HostAssets, eip, b
// Protection (edge request protection, internal/edgeguard): every request
// this catch keeps first meets the hard and probe checks under this box's
// mode, before the store is read, exactly as a request the home serves meets
-// them in ServeHTTP. A block is answered with the block page; a match it
-// answers itself is recorded as a Match under the synthetic route.
+// them in ServeHTTP. A block is answered with the block page. A match is
+// recorded here as one Match under the synthetic route, however the request
+// was answered, and every hop sent for it carries the checked mark, so the
+// home neither checks nor records it again.
func (e *Edge) serveAssetFar(w http.ResponseWriter, r *http.Request, host string) bool {
a, eip, box, key, ok := e.farAssetCatch(r, host)
if !ok {
@@ -1055,7 +1057,7 @@ func (e *Edge) serveAssetFar(w http.ResponseWriter, r *http.Request, host string
rt := registry.Route{Host: host, Account: a.Account, App: a.App, Kind: "instance"}
var n int64
cw := &countingWriter{ResponseWriter: w, n: &n}
- var billed, acked, reforwarded bool
+ var billed, acked, reforwarded, viaHome bool
var out *outcome
defer func() {
if billed || (acked && !reforwarded) {
@@ -1063,12 +1065,13 @@ func (e *Edge) serveAssetFar(w http.ResponseWriter, r *http.Request, host string
m.Record(rt, 1, n, false)
}
}
- // What this edge answered itself (a hit, the block page, a throttle
- // refusal) is recorded here when a rule matched it, as ServeHTTP's
- // observer defer records a matched request it serves. A fill or a
- // forward reached the home as a hop, and the home records it there.
- if billed && out != nil && out.guard != nil && out.guard.verdict != nil {
- e.observeRecords(rt, false, r, cw, out)
+ // A request a rule matched is recorded here, once, however it was
+ // answered: a hit, the block page, a throttle refusal, a fill or a
+ // forward. Every hop sent for it carried this edge's checked mark,
+ // so the home neither checks nor records it, whatever its own mode.
+ // viaHome: a wake, if any, happened on the home, out of sight.
+ if out != nil && out.guard != nil && out.guard.verdict != nil {
+ e.observeRecords(rt, viaHome, r, cw, out)
}
}()
// The hard and probe checks, as ServeHTTP runs them for a request this
@@ -1084,6 +1087,20 @@ func (e *Edge) serveAssetFar(w http.ResponseWriter, r *http.Request, host string
return true
}
}
+ // From here on, when a rule matched (a watch: a block has returned),
+ // every hop this edge sends for the request (a fill, a forward) carries
+ // its checked mark (signHopChecked), signed when the hop is sent: the
+ // home then neither checks nor records the request, as for a tunnel
+ // delivery, and this edge's defer records it once. A request no rule
+ // matched carries no mark, and the home records it as an ordinary hop.
+ checked := out != nil && out.guard != nil && out.guard.verdict != nil
+ forward = func() {
+ viaHome = true
+ if checked {
+ r.Header.Set(hopCheckedHeader, signHopChecked(key, host, time.Now()))
+ }
+ e.farForward(cw, r, host, eip, box)
+ }
var judged, admitted bool
throttle := func() bool {
if !judged {
@@ -1127,16 +1144,17 @@ func (e *Edge) serveAssetFar(w http.ResponseWriter, r *http.Request, host string
forward()
return true
}
- releaseSlot, ok := e.backhaulAdmit(w, r, eip, box)
+ releaseSlot, ok := e.backhaulAdmit(cw, r, eip, box)
if !ok {
done(nil)
return true
}
+ viaHome = true
e.leadAssetFill(cw, r, nil, done, func(ctx context.Context, onHeader func(assetVerdict, http.Header)) (*assetcache.Entry, error) {
// The slot is held for the fill's whole exchange with the home, and
// given back before any re-forward takes its own.
defer releaseSlot()
- return e.fillFromHome(ctx, cw, r, k, host, eip, box, key, assertion, &acked, onHeader)
+ return e.fillFromHome(ctx, cw, r, k, host, eip, box, key, assertion, checked, &acked, onHeader)
}, func(_ assetVerdict, h http.Header) { stripAssetFillVocabulary(h) }, func() {
reforwarded = true
forward()
@@ -1155,9 +1173,10 @@ func (e *Edge) serveAssetFar(w http.ResponseWriter, r *http.Request, host string
// set when the acknowledgement verifies, storable or not: the caller meters
// exactly those responses. The rest (body size, reservation, trailer veto,
// fallback ETag, the initiating-request rule) is runAssetFill's, as for a
-// fill from the app.
+// fill from the app. checked adds this edge's checked mark (signHopChecked)
+// to the hop, when its own checks matched r and it records r itself.
func (e *Edge) fillFromHome(ctx context.Context, w http.ResponseWriter, r *http.Request, k assetcache.Key, host, eip, box string,
- key []byte, assertion string, acked *bool, onHeader func(assetVerdict, http.Header)) (*assetcache.Entry, error) {
+ key []byte, assertion string, checked bool, acked *bool, onHeader func(assetVerdict, http.Header)) (*assetcache.Entry, error) {
judge := func(code int, snap http.Header, reqTime, respTime time.Time) assetVerdict {
exp, ok := assetAcknowledged(snap, key, assertion)
if !ok {
@@ -1182,6 +1201,9 @@ func (e *Edge) fillFromHome(ctx context.Context, w http.ResponseWriter, r *http.
}
send := func(w http.ResponseWriter, req *http.Request) {
req.Header.Set(assetFillHeader, assertion)
+ if checked {
+ req.Header.Set(hopCheckedHeader, signHopChecked(key, host, time.Now()))
+ }
backhaulProxy(host, eip, box, signHop(key, host, time.Now()), "", true, e.backhaulTransport(eip), e.logThrottled).ServeHTTP(w, req)
}
return e.runAssetFill(ctx, w, r, k, host, judge, send, onHeader)
diff --git a/internal/edge/edge.go b/internal/edge/edge.go
index e986d4258..4e17b69c6 100644
--- a/internal/edge/edge.go
+++ b/internal/edge/edge.go
@@ -1805,8 +1805,11 @@ func (e *Edge) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// backhauled it here (hopDoorFrom, set only beside a verified hop,
// as the rate limit reads it). A request a tunnel delivered was
// checked, and is recorded, by the hub that forwarded it, so
- // checking it again here would answer or count it twice.
- if e.guard != guardOff && !isDoor && !hopDoorFrom(r.Context()) && !fromTunnel(r.Context()) {
+ // checking it again here would answer or count it twice. So was a
+ // hop a far edge's asset catch sent with its checked mark: its
+ // checks matched, and it records the request (hopCheckedFrom, set
+ // only beside a verified hop).
+ if e.guard != guardOff && !isDoor && !hopDoorFrom(r.Context()) && !fromTunnel(r.Context()) && !hopCheckedFrom(r.Context()) {
out.guard = e.newGuardState()
}
defer func() {
diff --git a/internal/edge/homemap.go b/internal/edge/homemap.go
index 9820ad0fb..e58efcb3c 100644
--- a/internal/edge/homemap.go
+++ b/internal/edge/homemap.go
@@ -101,6 +101,10 @@ const (
hopHeader = "X-Carlos-Hop"
hopAuthHeader = "X-Carlos-Hop-Auth"
hopDoorHeader = "X-Carlos-Hop-Door"
+ // hopCheckedHeader is the checked mark (signHopChecked): the sending
+ // edge's hard and probe checks matched this request, and it records the
+ // request itself.
+ hopCheckedHeader = "X-Carlos-Hop-Checked"
)
// edgeRoleHome is the only role v1 writes, and the only one that routes.
@@ -1230,17 +1234,31 @@ func hopDoorFrom(ctx context.Context) bool {
return v
}
+// hopCheckedKey marks a verified hop whose sender vouched, with
+// X-Carlos-Hop-Checked, that its hard and probe checks matched the request
+// and that it records it (a far edge's asset catch, serveAssetFar). Set only
+// beside hopVerifiedKey. It exempts the request from this box's checks and
+// from its request record (observeRecords), as a tunnel delivery is exempt,
+// so the request is decided and recorded once; it exempts nothing else.
+type hopCheckedKey struct{}
+
+func hopCheckedFrom(ctx context.Context) bool {
+ v, _ := ctx.Value(hopCheckedKey{}).(bool)
+ return v
+}
+
// acceptHop is the whole of hop handling on the request path, and it runs
// before the route lookup so that BOTH of its outcomes are decided ahead of
// anything that serves:
//
-// no hop header → nothing happens beyond deleting the door mark (the
-// overwhelming case: a few header lookups on a request
-// that is not a hop).
+// no hop header → nothing happens beyond deleting the door and
+// checked marks (the overwhelming case: a few header
+// lookups on a request that is not a hop).
// verified hop → the mark goes on the context, the inbound
// X-Forwarded-For is believed, and the caller serves
// the route locally or refuses (staleHopRefusal). A
-// door mark that verifies adds hopDoorKey.
+// door mark that verifies adds hopDoorKey; a checked
+// mark that verifies adds hopCheckedKey.
// unverified hop → every forwarded header is stripped and the sender is
// an ordinary client from here on.
//
@@ -1260,6 +1278,8 @@ func (e *Edge) acceptHop(r *http.Request, host string) (*http.Request, bool) {
// and only when it is a single value.
door := r.Header.Values(hopDoorHeader)
r.Header.Del(hopDoorHeader)
+ checked := r.Header.Values(hopCheckedHeader)
+ r.Header.Del(hopCheckedHeader)
if r.Header.Get(hopHeader) == "" {
// A signature with no marker beside it is not a hop — but it is still
// this edge's vocabulary, and the invariant above is "deleted in ALL
@@ -1296,6 +1316,9 @@ func (e *Edge) acceptHop(r *http.Request, host string) (*http.Request, bool) {
if len(door) == 1 && verifyHopDoorEitherKey(current, next, host, door[0], now) {
ctx = context.WithValue(ctx, hopDoorKey{}, true)
}
+ if len(checked) == 1 && verifyHopCheckedEitherKey(current, next, host, checked[0], now) {
+ ctx = context.WithValue(ctx, hopCheckedKey{}, true)
+ }
return r.WithContext(ctx), true
}
diff --git a/internal/edge/mesh.go b/internal/edge/mesh.go
index 54d21b992..086a003dd 100644
--- a/internal/edge/mesh.go
+++ b/internal/edge/mesh.go
@@ -266,6 +266,28 @@ func verifyHopDoorEitherKey(current, next []byte, host, header string, now time.
return len(current) > 0 && verifyHopMAC(current, hopDoorDomain, host, header, now)
}
+// hopCheckedDomain separates the checked mark's MAC from the hop's and the
+// door mark's, by the same NUL argument as hopDoorDomain.
+const hopCheckedDomain = "checked\x00"
+
+// signHopChecked produces the value of the X-Carlos-Hop-Checked header, which
+// a far edge's asset catch adds to every hop it sends for a request its own
+// hard and probe checks matched and that it records itself (serveAssetFar).
+// Same key, host and timestamp format as signHop, in its own MAC domain.
+func signHopChecked(key []byte, host string, now time.Time) string {
+ ts := strconv.FormatInt(now.Unix(), 10)
+ return ts + ":" + hex.EncodeToString(hopMAC(key, hopCheckedDomain, host, ts))
+}
+
+// verifyHopCheckedEitherKey is verifyHopEitherKey for the checked mark.
+// acceptHop consults it only once the hop itself has verified.
+func verifyHopCheckedEitherKey(current, next []byte, host, header string, now time.Time) bool {
+ if len(next) > 0 && verifyHopMAC(next, hopCheckedDomain, host, header, now) {
+ return true
+ }
+ return len(current) > 0 && verifyHopMAC(current, hopCheckedDomain, host, header, now)
+}
+
// hopMAC is the MAC signHop and verifyHop both compute — one place so the
// two can never drift out of sync on what bytes are actually signed, and
// the one choke point that canonicalizes host before it enters the MAC.
diff --git a/internal/edge/reqrecords.go b/internal/edge/reqrecords.go
index 4a9d5a812..38cdb66b6 100644
--- a/internal/edge/reqrecords.go
+++ b/internal/edge/reqrecords.go
@@ -60,8 +60,10 @@ func (e *Edge) observeRecords(rt registry.Route, viaTunnel bool, r *http.Request
return
}
// One record per served response, observeAnalytics's rule: the hub that
- // forwarded this over the tunnel records it from its own defer.
- if fromTunnel(r.Context()) {
+ // forwarded this over the tunnel records it from its own defer, and a
+ // far edge whose checks matched a hop it sent, and that marked it
+ // checked, records it itself (serveAssetFar).
+ if fromTunnel(r.Context()) || hopCheckedFrom(r.Context()) {
return
}
status := ob.status