edge: asset fills carry Sec-Fetch-Mode (burst fix round 2)
assetFillRequest copies the visitor's Sec-Fetch-Mode beside User-Agent and Accept, so a home that serves a fill as an ordinary hop (its assertion no longer verifies, e.g. a stale far mirror after a generation change) sees the same browser signal the far edge saw, and a browser's missing assets are counted nowhere. A forged header only exempts the forger, which the spec accepts. Test: browser-style requests for missing assets through a far edge with a stale mirror never count or trip on either edge; without the header they count once, at the home.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+41
−7
internal/edge/assetcatch.go+12 −7internal/edge/burst_edge_test.go+29 −0
diff --git a/internal/edge/assetcatch.go b/internal/edge/assetcatch.go| index 3b5ebe841..82bf114a9 100644 |
| --- a/internal/edge/assetcatch.go |
| +++ b/internal/edge/assetcatch.go |
| @@ -573,12 +573,13 @@ func (e *Edge) leadAssetFill(w http.ResponseWriter, r *http.Request, release fun |
| } |
| // fillFromApp fills k from the app (§5.2, §5.3). It sends the allow-listed |
| -// request (Host, User-Agent, Accept, Accept-Encoding: identity; GET even for |
| -// a HEAD; no cookie, no credentials, no visitor geo) through the activator |
| -// for a hibernating route or up.proxy otherwise, and judges the response with |
| -// assetAdmit when its headers arrive (declared by the build that answered: |
| -// the generation's X-Carlos-Version on a generation-managed route, the |
| -// route's Version otherwise, asked of the policy with the request hostname). |
| +// request (Host, User-Agent, Accept, Sec-Fetch-Mode, Accept-Encoding: |
| +// identity; GET even for a HEAD; no cookie, no credentials, no visitor geo) |
| +// through the activator for a hibernating route or up.proxy otherwise, and |
| +// judges the response with assetAdmit when its headers arrive (declared by |
| +// the build that answered: the generation's X-Carlos-Version on a |
| +// generation-managed route, the route's Version otherwise, asked of the |
| +// policy with the request hostname). |
| // The rest is runAssetFill. |
| func (e *Edge) fillFromApp(ctx context.Context, w http.ResponseWriter, r *http.Request, up upstream, k assetcache.Key, onHeader func(v assetVerdict, h http.Header)) (*assetcache.Entry, error) { |
| st := e.assets.Load() |
| @@ -665,7 +666,11 @@ func assetFillRequest(ctx context.Context, r *http.Request) *http.Request { |
| RequestURI: u.RequestURI(), |
| TLS: r.TLS, |
| } |
| - for _, name := range []string{"User-Agent", "Accept"} { |
| + // Sec-Fetch-Mode is the browser signal the probe-burst limit reads |
| + // (noteBurst): carried so a home that serves this fill as an ordinary |
| + // hop, because the assertion no longer verifies there, judges it as the |
| + // far edge would. It names how the browser fetches, not who asks. |
| + for _, name := range []string{"User-Agent", "Accept", "Sec-Fetch-Mode"} { |
| if vs := r.Header.Values(name); len(vs) > 0 { |
| req.Header[name] = append([]string(nil), vs...) |
| } |
diff --git a/internal/edge/burst_edge_test.go b/internal/edge/burst_edge_test.go| index b3ae56012..0095e7e27 100644 |
| --- a/internal/edge/burst_edge_test.go |
| +++ b/internal/edge/burst_edge_test.go |
| @@ -831,3 +831,32 @@ func TestBurstNeverRefusesAnExistingStaticHardFile(t *testing.T) { |
| wantBurstMatch(t, g.lastMatch(t, "/.env"), reqrec.KindBlock, reqrec.CooldownFromThisApp, until) |
| }) |
| } |
| + |
| +// Fix round 2: the fill carries the visitor's Sec-Fetch-Mode, so a browser's |
| +// missing assets count nowhere even when the far edge's mirror is stale and |
| +// the home, unable to verify the fill, serves it as an ordinary hop. |
| +func TestBurstStaleBrowserFillCountedNowhere(t *testing.T) { |
| + x := newBurstFar(t, missingAsset) |
| + x.publishGen(t, "stale-gen") |
| + for i := 0; i < burstThreshold+5; i++ { |
| + w := x.s.get(t, fmt.Sprintf("/assets/missing-%d.js", i), "Sec-Fetch-Mode", "no-cors") |
| + if w.Code != 404 || w.Header().Get(assetAckHeader) != "" { |
| + t.Fatalf("browser asset %d: %d", i, w.Code) |
| + } |
| + } |
| + x.waitHome(t, burstThreshold+5) |
| + if far, home := burstNotes(x.s.e.burst), burstNotes(x.home.e.burst); far != 0 || home != 0 { |
| + t.Fatalf("browser misses through a stale far edge counted: far %d, home %d", far, home) |
| + } |
| + if fc, hc := x.s.e.burst.cooldownCount(), x.home.e.burst.cooldownCount(); fc != 0 || hc != 0 { |
| + t.Fatalf("cool-downs: far %d, home %d; want none", fc, hc) |
| + } |
| + // The control: the same requests without the header count at the home. |
| + for i := 0; i < 3; i++ { |
| + x.s.get(t, fmt.Sprintf("/assets/gone-%d.js", i)) |
| + } |
| + x.waitHome(t, burstThreshold+5+3) |
| + if far, home := burstNotes(x.s.e.burst), burstNotes(x.home.e.burst); far != 0 || home != 3 { |
| + t.Fatalf("scanner misses through a stale far edge: far %d, home %d; want 0 and 3", far, home) |
| + } |
| +} |