Slides: the bound bucket is served through the app, so uploads and pictures work
The object store was bound for the first time on 2026-11-11 and the
presigned design (spec §2.7) had never run: the browser PUTs to the
bucket and loads pictures from it, and the page's CSP (default-src
'self', img-src 'self' data:) refuses both, and the platform's bucket
answers no CORS for this origin. So every upload and every picture would
have failed the moment the store was live.
slides.ThroughApp hides a store's presigning, and cmd/slides binds the
platform's bucket through it: an upload goes to PUT /d/{sqid}/uploads/
{key} (putUpload, the path development's blobs.Dir always took), a
picture is streamed by serveAsset, an export by serveExport, and the
bytes land in the bucket. The staging receipt, the sniff, the SVG
sanitising and registration are unchanged. Going direct again needs the
bucket in connect-src and img-src and a CORS rule; ThroughApp's comment
says so. TestBucketThroughTheAppTakesTheInAppPath holds it: a
presigning store bound this way signs nothing, and the picture comes
back from the app and is in the bucket.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+77
−15
cmd/slides/main.go+5 −1internal/slides/assets.go+38 −14internal/slidestest/assets_test.go+34 −0
CI passed — run details
diff --git a/cmd/slides/main.go b/cmd/slides/main.go| index 90b39ec..eca408d 100644 |
| --- a/cmd/slides/main.go |
| +++ b/cmd/slides/main.go |
| @@ -158,7 +158,11 @@ func newBlobs(env, dbPath string, logger *slog.Logger) (blobs.Store, error) { |
| return nil, err |
| } |
| if s3 != nil { |
| - return s3, nil |
| + // Through the app, not presigned: the browser can reach neither |
| + // the bucket's PUT nor its GET under this app's CSP, and the |
| + // bucket has no CORS for it (slides.ThroughApp says why). |
| + logger.Info("slides: object store bound, served through the app", "bucket", os.Getenv("CARLOS_STORE_BUCKET")) |
| + return slides.ThroughApp(s3), nil |
| } |
| if env != slides.EnvDevelopment { |
| // No bucket outside development is not a refusal here: nothing |
diff --git a/internal/slides/assets.go b/internal/slides/assets.go| index b6f840f..598c946 100644 |
| --- a/internal/slides/assets.go |
| +++ b/internal/slides/assets.go |
| @@ -142,6 +142,34 @@ type presigner interface { |
| PresignGet(hash string, ttl time.Duration) (string, error) |
| } |
| +// ThroughApp is a bound object store with its presigning hidden, so |
| +// every byte goes through this app: an upload is PUT to |
| +// /d/{sqid}/uploads/{key} (putUpload), a picture is streamed from |
| +// serveAsset, and an export from serveExport — the paths development's |
| +// blobs.Dir always took. |
| +// |
| +// Production binds the platform's bucket through it (cmd/slides). The |
| +// presigned design (spec §2.7) has the browser PUT to the bucket and |
| +// load pictures from it, and neither can work as deployed: the page's |
| +// CSP is default-src 'self' and img-src 'self' data: (serving.go), so |
| +// the browser refuses both, and the platform's bucket answers no CORS |
| +// for this origin. Found when the store was first bound, 2026-11-11 — |
| +// the path had never run. Going direct again needs the bucket's origin |
| +// in connect-src and img-src and a CORS rule on the bucket; until then |
| +// this is the path that works. The cost is the bytes passing through |
| +// one instance: a 20 MiB picture once on the way in, and on every |
| +// uncached view on the way out (Cache-Control below keeps that rare). |
| +func ThroughApp(s blobs.Store) blobs.Store { |
| + if s == nil { |
| + return nil |
| + } |
| + return throughApp{s} |
| +} |
| + |
| +// throughApp embeds only the blobs.Store interface, so a type assertion |
| +// to presigner fails on it whatever the store underneath can do. |
| +type throughApp struct{ blobs.Store } |
| + |
| // presignTTL is how long a minted URL lives. An hour for a GET, because |
| // that is the life of one person reading a deck; the same for a PUT, |
| // because a 20 MiB file on a bad connection is not a five-minute job. |
| @@ -310,12 +338,10 @@ func (a *app) signUpload(w http.ResponseWriter, r *http.Request) { |
| } |
| out["url"] = url |
| } else { |
| - // blobs.Dir has nothing to sign, so development uploads the |
| - // same way through this app. Production with a real bucket |
| - // never reaches this branch and never proxies a byte — see |
| - // putUpload's own refusal. ObjectKey stays empty: a |
| - // content-addressed store picks the key itself, and putUpload |
| - // records which one. |
| + // A store that does not presign — blobs.Dir in development, and |
| + // production's bucket behind ThroughApp — takes the bytes |
| + // through this app. ObjectKey stays empty: a content-addressed |
| + // store picks the key itself, and putUpload records which one. |
| out["url"] = "/d/" + d.Sqid + "/uploads/" + key |
| } |
| if err := a.guarded(r.Context(), a.deckGuard(r.Context(), u, d), func(db *gorm.DB) error { return db.Create(&up).Error }); err != nil { |
| @@ -330,15 +356,13 @@ func (a *app) signUpload(w http.ResponseWriter, r *http.Request) { |
| // --- PUT /d/{sqid}/uploads/{ref} --- |
| -// putUpload is the development-only receiving end of the URL signUpload |
| -// hands back when the bound store cannot presign — blobs.Dir, a |
| -// directory beside the database. |
| +// putUpload is the receiving end of the URL signUpload hands back when |
| +// the bound store does not presign — blobs.Dir in development, and the |
| +// platform's bucket behind ThroughApp in production. |
| // |
| -// It refuses outright on a store that CAN presign, rather than quietly |
| -// working: the whole point of the presigned path is that 20 MiB does |
| -// not travel through an app process that has one small instance's |
| -// memory, and an endpoint that silently accepted it anyway would be a |
| -// performance cliff nobody could see in the code. |
| +// It refuses outright on a store that DOES presign: that store's uploads |
| +// go to the bucket, and an endpoint that also accepted them here would |
| +// be a second path nobody chose. |
| // |
| // It takes a staging key, not a ref, and resolves the receipt for it |
| // before it reads a byte (codex 1). Without that this endpoint was its |
diff --git a/internal/slidestest/assets_test.go b/internal/slidestest/assets_test.go| index 3fcab8b..678e019 100644 |
| --- a/internal/slidestest/assets_test.go |
| +++ b/internal/slidestest/assets_test.go |
| @@ -311,6 +311,40 @@ func TestUploadAndRegisterWithDirStore(t *testing.T) { |
| } |
| } |
| +// TestBucketThroughTheAppTakesTheInAppPath: production binds its bucket |
| +// through slides.ThroughApp (cmd/slides), because the page's CSP lets |
| +// the browser reach neither the bucket's PUT nor its GET. A store that |
| +// CAN presign, bound that way, must sign nothing: the upload goes to |
| +// this app, the picture is streamed back by it, and the bytes land in |
| +// the bucket underneath. |
| +func TestBucketThroughTheAppTakesTheInAppPath(t *testing.T) { |
| + bucket := &presigningStore{Store: dirStore(t)} |
| + a := newAppWithStore(t, slides.ThroughApp(bucket)) |
| + cookies := signedIn(t, a, allowedAddress) |
| + token := mintAgent(t, a, cookies, "claude") |
| + sqid := apiDeck(t, a, token, "Pictures") |
| + deck := "/d/" + sqid |
| + |
| + record := upload(t, a, deck, cookies, "chart.png", "image/png", onePixelPNG, "A bar chart") |
| + registerInDeck(t, a, token, sqid, record) |
| + ref := record["ref"].(string) |
| + rec := mustGet(t, a, deck+"/assets/"+ref, http.StatusOK, cookies) |
| + if !bytes.Equal(rec.Body.Bytes(), onePixelPNG) { |
| + t.Errorf("GET %s/assets/%s returned %d bytes, want the picture streamed back by the app", deck, ref, rec.Body.Len()) |
| + } |
| + if loc := rec.Header().Get("Location"); loc != "" { |
| + t.Errorf("the picture redirected to %q; through the app it is served, not sent to the bucket", loc) |
| + } |
| + if len(bucket.minted) != 0 { |
| + t.Errorf("the bucket signed %v; through the app it signs nothing", bucket.minted) |
| + } |
| + if rc, err := bucket.Store.Get(context.Background(), ref); err != nil { |
| + t.Errorf("the picture is not in the bucket underneath: %v", err) |
| + } else { |
| + rc.Close() |
| + } |
| +} |
| + |
| // TestUploadLimits: the four types and the 20 MiB ceiling, refused |
| // before a URL is ever minted. |
| func TestUploadLimits(t *testing.T) { |