Public: anyone can read this; the crew can change it.

A signed-in source archive is never marked shared-cacheable #15014

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

If you are signed in, a source archive at a full commit id is no longer marked shared-cacheable. Anonymous archives of public repositories still are. Closes #14948 (one finding from #14765).

Notes

shipped production is serving it deploy 9504585

opened this

If you are signed in, a source archive at a full commit id is no longer marked shared-cacheable. Anonymous archives of public repositories still are. Closes #14948 (one finding from #14765).

  • src/http/archive.ts: the archive decides caching through mayShare, the same check the raw-file route (rawBlob) uses. An anonymous request for a public repository at a full id gets PINNED_PUBLIC (a one-year browser cache, one day in a shared cache) and Vary: EDGE_VARY. A signed-in request at a full id gets private, max-age=31536000, immutable, so the browser still keeps the bytes it can't change. A branch or tag stays no-cache.
  • src/http/respond.ts: privateWhenSignedIn used to skip any response whose Cache-Control said immutable. That let a credentialed archive keep public. It now skips only a fixed list of static-asset paths: hashed files under /assets/, the hashed toolbar scripts under /__forge/, /icons/*.png, /favicon.ico and the apple-touch icons. Every other credentialed answer loses public and s-maxage, whatever else its header says.
  • test/archive-cache.test.ts (new):
    • Signed out, the archive is PINNED_PUBLIC with the Vary header.
    • Signed in by session cookie or by bearer token, it is private and immutable, with no public and no s-maxage.
    • A branch archive is no-cache.
    • Signed in, a hashed asset keeps its public year.
    • Unit cases for the path list.

    Four of its six tests fail on today's main, both signed-in cases among them.

  • test/cache-private.test.ts: I changed one assertion because it encoded the bug: it expected an immutable response at / to stay public when signed in. It now expects that for an /assets/ path, and expects / to come back private.

To look at: the path list in STATIC_ASSET_PATH. A hashed static asset served from a path it doesn't cover would go out private to signed-in browsers. That only costs shared-cache hits, never exposure. I left out the /__forge/ paths other than the two hashed toolbar scripts, because most of them depend on who is asking.

To try it: on the preview, run curl -I <preview>/<owner>/<repo>/archive/<full-oid>.tar.gz for a public repository, once without and once with your forge_session cookie. Signed out you should see public, …, s-maxage=86400, immutable; signed in, private, max-age=31536000, immutable.

Checks: bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. scripts/fast.ts named 2,480 test files because respond.ts reaches almost everything, so I picked the 28 files that mention privateWhenSignedIn, immutable, PINNED_PUBLIC or archive URLs: 485 pass, 0 fail. The full suite runs in the forge's check.

The repository's pre-push hook wanted a commit saying how to try the change, so there is an empty Try: commit.

🤖 Generated with Claude Code

Closes #14948

commented

If you are signed in, a source archive at a full commit id is no longer marked shared-cacheable. Anonymous archives of public repositories still are. Closes #14948 (one finding from #14765).

  • src/http/archive.ts: the archive decides caching through mayShare, the same check the raw-file route (rawBlob) uses. An anonymous request for a public repository at a full id gets PINNED_PUBLIC (a one-year browser cache, one day in a shared cache) and Vary: EDGE_VARY. A signed-in request at a full id gets private, max-age=31536000, immutable, so the browser still keeps the bytes it can't change. A branch or tag stays no-cache.
  • src/http/respond.ts: privateWhenSignedIn used to skip any response whose Cache-Control said immutable. That let a credentialed archive keep public. It now skips only a fixed list of static-asset paths: hashed files under /assets/, the hashed toolbar scripts under /__forge/, /icons/*.png, /favicon.ico and the apple-touch icons. Every other credentialed answer loses public and s-maxage, whatever else its header says.
  • test/archive-cache.test.ts (new):
    • Signed out, the archive is PINNED_PUBLIC with the Vary header.
    • Signed in by session cookie or by bearer token, it is private and immutable, with no public and no s-maxage.
    • A branch archive is no-cache.
    • Signed in, a hashed asset keeps its public year.
    • Unit cases for the path list.

    Four of its six tests fail on today's main, both signed-in cases among them.

  • test/cache-private.test.ts: I changed one assertion because it encoded the bug: it expected an immutable response at / to stay public when signed in. It now expects that for an /assets/ path, and expects / to come back private.

To look at: the path list in STATIC_ASSET_PATH. A hashed static asset served from a path it doesn't cover would go out private to signed-in browsers. That only costs shared-cache hits, never exposure. I left out the /__forge/ paths other than the two hashed toolbar scripts, because most of them depend on who is asking.

To try it: on the preview, run curl -I <preview>/<owner>/<repo>/archive/<full-oid>.tar.gz for a public repository, once without and once with your forge_session cookie. Signed out you should see public, …, s-maxage=86400, immutable; signed in, private, max-age=31536000, immutable.

Checks: bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. scripts/fast.ts named 2,480 test files because respond.ts reaches almost everything, so I picked the 28 files that mention privateWhenSignedIn, immutable, PINNED_PUBLIC or archive URLs: 485 pass, 0 fail. The full suite runs in the forge's check.

The repository's pre-push hook wanted a commit saying how to try the change, so there is an empty Try: commit.

🤖 Generated with Claude Code

Approved

Clean, small security fix. The archive goes through mayShare with PINNED_PUBLIC and EDGE_VARY like rawBlob. A credentialed answer now loses public/s-maxage unless the path is a static asset. The tests cover anonymous, cookie, bearer, branch, assets and the path list. The pull is green.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs