diff --git a/docs/operations/browser-file-storage-recovery.md b/docs/operations/browser-file-storage-recovery.md index dd758100..5815615d 100644 --- a/docs/operations/browser-file-storage-recovery.md +++ b/docs/operations/browser-file-storage-recovery.md @@ -611,10 +611,11 @@ Service Worker를 별도 선택한 조합에서만 추가. 워커의 fetch 가 `skipWaiting()`하고, 활성화 때 `registration.unregister()`한다. fetch handler가 없어서 그동안의 요청은 모두 네트워크로 간다. 다음 load부터는 제어받지 않는다. 브라우저 확인: `tests/e2e/service-worker-recovery.spec.ts`. -- 이 경로가 동작하려면 `service-worker.js`를 `Cache-Control: no-cache`로 서빙해야 - 한다. 워커를 싣는 빌드(`ACTIVE`·`REMOVE_REGISTRATION`)에서는 - `verify:hosting-headers` live 모드가 `/service-worker.js`를 요청해 이 헤더를 - 확인하고, 다르면 FAIL이다(`config/hosting/cache-policy.json` `serviceWorker`, +- 이 경로가 동작하려면 `service-worker.js`를 `Cache-Control: no-cache`로, redirect + 없이 서빙해야 한다. 브라우저는 워커 스크립트의 redirect를 같은 origin 안이라도 + 거절한다. 워커를 싣는 빌드(`ACTIVE`·`REMOVE_REGISTRATION`)에서는 + `verify:hosting-headers` live 모드가 `/service-worker.js`를 요청해 이 헤더와 + redirect를 확인하고, 다르면 FAIL이다(`config/hosting/cache-policy.json` `serviceWorker`, `scripts/verify-hosting-headers.ts`). fixture 모드는 선언끼리만 대조하므로 `UNVERIFIED`다. 하위 경로 base URL은 live probe가 아직 받지 않는다 (`scripts/lib/hosting-probe.ts` `classifyLiveHostingBaseUrl`, 리뷰 0929/13-06). diff --git a/docs/operations/release-cache-rollback.md b/docs/operations/release-cache-rollback.md index b6211a37..5d782079 100644 --- a/docs/operations/release-cache-rollback.md +++ b/docs/operations/release-cache-rollback.md @@ -71,9 +71,12 @@ It also requests `appRoute` (`/__probe/deep-link`, a path no build has a file for): the host must answer 200 with the same `index.html` (the same entry script) and the HTML headers, so a host without the SPA fallback fails (review 1101/13-04). When the build ships a worker it requests -`/service-worker.js` and expects `no-cache`. The surfaces and their headers are -declared in `config/hosting/cache-policy.json`. For each cacheable extension the -release has under `assets/` (`.css`, `.js`, `.woff2` and the rest of +`/service-worker.js` and expects `no-cache` and no redirect at all, not even +one inside the origin: browsers fetch the worker script with redirect mode +`error`, so registration, every update check and the `REMOVE_REGISTRATION` +kill switch fail behind one (review 1106/06-01). The surfaces and their +headers are declared in `config/hosting/cache-policy.json`. For each cacheable +extension the release has under `assets/` (`.css`, `.js`, `.woff2` and the rest of `CACHEABLE_ASSET_CONTENT_TYPES`) it requests the first such file and expects exactly that type (`hashedAsset.css` and so on). The worker's install refuses the whole release when one precached asset has another type, while a page diff --git a/scripts/lib/hosting-probe.ts b/scripts/lib/hosting-probe.ts index 82e90fd5..02a997b5 100644 --- a/scripts/lib/hosting-probe.ts +++ b/scripts/lib/hosting-probe.ts @@ -125,6 +125,12 @@ export function releaseIdentity(manifest: string | null): ReleaseIdentity | null * * 1103/13-02. The host must negotiate a declared protocol (HTTP/2): the * template splits its initial chunks on that premise. + * + * 1106/06-01. The worker script alone must also answer without any redirect. + * Browsers fetch it with redirect mode "error" (the Service Worker Update + * algorithm), so a same-origin redirect breaks registration, every update + * check and the REMOVE_REGISTRATION kill switch, although the followed answer + * is a 200 with the right headers. Pages may still follow a redirect. */ export async function probeLiveRelease( base: URL, @@ -156,6 +162,17 @@ export async function probeLiveRelease( passed: finalOrigin === base.origin, }, ); + if (surface === "serviceWorker") { + const redirected = response.redirected || response.type === "opaqueredirect"; + results.push({ + surface, + header: "redirect", + expected: false, + observed: redirected, + ...(redirected ? { reason: "browsers refuse a redirected worker script" } : {}), + passed: !redirected, + }); + } responses[surface] = Object.fromEntries( [...response.headers.entries()].map(([name, value]) => [name.toLowerCase(), value]), ); diff --git a/tests/unit/hosting-probe.test.ts b/tests/unit/hosting-probe.test.ts index de9f2d3c..0d980b33 100644 --- a/tests/unit/hosting-probe.test.ts +++ b/tests/unit/hosting-probe.test.ts @@ -448,6 +448,55 @@ describe("live hosting probe (1105/06-02)", () => { expect.objectContaining({ surface: "releaseManifest", header: "build-id", passed: true }), ); }); + + // 1106/06-01. Browsers fetch the worker script with redirect mode "error", + // so a same-origin redirect breaks registration, every update check and the + // REMOVE_REGISTRATION kill switch, while the followed answer is a 200 with + // the right headers. A page may still follow such a redirect. + it("fails a worker script the host answers only after a same-origin redirect", async () => { + const served: Record = { + "/": [INDEX, "text/html"], + "/release-manifest.json": [JSON.stringify(IDENTITY), "application/json"], + "/service-worker.js": ["", "text/javascript"], + "/assets/index-A1.js": ["", "text/javascript"], + "/assets/index-C3.css": ["", "text/css"], + }; + // Each path in `redirected` is answered after a redirect to `/v2/...` on the same origin. + const failing = async (redirected: readonly string[]) => { + const { results } = await probeLiveHosting( + base, + { ...PATHS, serviceWorker: "/service-worker.js" }, + CANDIDATE, + DIST_FILES, + { + fetcher: async (url) => { + const entry = served[url.pathname]; + const response = new Response(entry?.[0] ?? "Not Found", { + status: entry ? 200 : 404, + headers: entry ? { "content-type": entry[1] } : {}, + }); + const moved = redirected.includes(url.pathname); + Object.defineProperty(response, "url", { + value: moved ? new URL(`/v2${url.pathname}`, url).href : url.href, + }); + Object.defineProperty(response, "redirected", { value: moved }); + return response; + }, + }, + ); + return results.filter((result) => !result.passed); + }; + + expect(await failing([])).toEqual([]); + expect(await failing(["/", "/service-worker.js"])).toEqual([ + expect.objectContaining({ + surface: "serviceWorker", + header: "redirect", + observed: true, + reason: expect.stringContaining("redirect"), + }), + ]); + }); }); // 1101/13-01. FE-GATE-019 checks the promoted candidate it downloaded, not a