edge: a digestless static head is bound to its promotion record
Fix round 1 (Astra P1-3, Fable P2-1): static sites were a fourth staging path the H3-M1 binding missed. resolveLocked passed the pointer's digest to ensureExtracted, and a digestless pointer (marker off, the default) checked nothing, so a bucket writer could replace a static release's manifest and site tarball behind the untouched signed head and a fresh edge extracted and served the swap, scripts and redirect rules included. A digestless head now takes its digest from the signed promotion record (release.RecordedManifestDigest, recordBinding exported) before anything is fetched; no record, an unreadable one or a manifest that does not hash to it is refused, and the cached tree, if any, keeps being served. Test: TestStaticRefusesASwapBehindADigestlessHeadOnAFreshEdge. It failed before (200 "<script>evil()</script>") and passes now; the edge's 76 static tests pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+70
−0
internal/edge/static.go+15 −0internal/edge/static_test.go+46 −0internal/release/adopt.go+9 −0
diff --git a/internal/edge/static.go b/internal/edge/static.go| index 997e835ca..d526ff076 100644 |
| --- a/internal/edge/static.go |
| +++ b/internal/edge/static.go |
| @@ -296,6 +296,21 @@ func (s *staticSite) resolveLocked(ctx context.Context) (servedTree, error) { |
| return s.stale(err) |
| } |
| if want := cp.Digest; cp.Version != s.version || (want != "" && want != s.digest) { |
| + // A pointer that signs no digest (the account's marker off, the |
| + // default) binds nothing by itself: the bytes under the version are |
| + // whatever the bucket holds. So the build is bound to its signed |
| + // promotion record instead, as adoption binds a digestless head |
| + // (stagePointerHead), before anything is fetched: without a record, |
| + // or with a manifest that does not hash to it, nothing is extracted |
| + // and the cached tree, if any, keeps being served (hunt H3-M1 class, |
| + // fix round 1). |
| + if want == "" { |
| + bound, err := release.RecordedManifestDigest(ctx, s.store, s.pub, s.acct, s.app, cp.Version) |
| + if err != nil { |
| + return s.stale(fmt.Errorf("stage %s: %w", cp.Version, err)) |
| + } |
| + want = bound |
| + } |
| // From the check of what is on disk to the record of what is served, |
| // no sweep touches this app's directory. |
| done := s.trees.begin(s.appDir()) |
diff --git a/internal/edge/static_test.go b/internal/edge/static_test.go| index 4af384ff3..ce35e12c5 100644 |
| --- a/internal/edge/static_test.go |
| +++ b/internal/edge/static_test.go |
| @@ -4,6 +4,9 @@ import ( |
| "bytes" |
| "context" |
| "crypto/ed25519" |
| + "crypto/sha256" |
| + "encoding/hex" |
| + "encoding/json" |
| "errors" |
| "io" |
| "net/http" |
| @@ -547,3 +550,46 @@ func TestStaticExtractNeverReadsALegacyArtifact(t *testing.T) { |
| t.Errorf("GET / = %d %q — the edge served an artifact that only exists at the legacy key", code, body) |
| } |
| } |
| + |
| +// A bucket writer replaces a static release's manifest and site tarball |
| +// behind an untouched digestless pointer (marker off, the default). A fresh |
| +// edge must not extract or serve the swap: a digestless head is bound to its |
| +// signed promotion record, whose digest the swapped manifest does not |
| +// match (hunt H3-M1 class, Astra P1-3, Fable P2-1). |
| +func TestStaticRefusesASwapBehindADigestlessHeadOnAFreshEdge(t *testing.T) { |
| + store, storeRoot, priv, srv := staticFixture(t) |
| + ctx := context.Background() |
| + if cp, err := release.Channel(ctx, store, priv.Public().(ed25519.PublicKey), release.OpsAccount, "site", "canary/x"); err != nil || cp.Digest != "" { |
| + t.Fatalf("setup: the pointer = %+v, %v; want a digestless head", cp, err) |
| + } |
| + evil, err := PackDir(writeTree(t, map[string]string{"index.html": "<script>evil()</script>"})) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + mkey := release.ManifestKey(release.OpsAccount, "site", "v1") |
| + raw, _, err := store.Get(ctx, mkey) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var m release.Manifest |
| + if err := json.Unmarshal(raw, &m); err != nil { |
| + t.Fatal(err) |
| + } |
| + sum := sha256.Sum256(evil) |
| + a := m.Artifacts[siteArtifactFile] |
| + a.SHA256, a.Size = hex.EncodeToString(sum[:]), int64(len(evil)) |
| + m.Artifacts[siteArtifactFile] = a |
| + swapped, err := json.Marshal(m) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for key, body := range map[string][]byte{mkey: swapped, release.ArtifactKey(release.OpsAccount, "site", "v1", siteArtifactFile): evil} { |
| + if err := os.WriteFile(filepath.Join(storeRoot, filepath.FromSlash(key)), body, 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + code, body := getPath(t, srv.URL, "site.example.com", "/") |
| + if strings.Contains(body, "evil") || code == http.StatusOK { |
| + t.Fatalf("a fresh edge served the swapped site: %d %q", code, body) |
| + } |
| +} |
diff --git a/internal/release/adopt.go b/internal/release/adopt.go| index c28c0d7ad..93922c0ef 100644 |
| --- a/internal/release/adopt.go |
| +++ b/internal/release/adopt.go |
| @@ -2843,6 +2843,15 @@ func stageAuthorized(ctx context.Context, s Store, pub ed25519.PublicKey, optDir |
| return retainedOrRefused(optDir, acct, app, ver, host, want, refused) |
| } |
| +// RecordedManifestDigest is recordBinding for a caller outside this package |
| +// that stages from a digestless signed pointer: the edge's static sites |
| +// (hunt H3-M1 class, fix round 1). It returns the manifest digest ver's |
| +// signed promotion record binds, or the refusal recordBinding gives: no |
| +// record, one that cannot be read, or one with no digest. |
| +func RecordedManifestDigest(ctx context.Context, s Store, pub ed25519.PublicKey, acct, app, ver string) (string, error) { |
| + return recordBinding(ctx, s, pub, acct, app, ver) |
| +} |
| + |
| // recordBinding reads ver's promotion record and returns the manifest |
| // digest that binds its bytes, or the refusal stageAuthorized and |
| // stagePointerHead share: no record, a record that cannot be read (never |