Skip to content

Self-improving AI Employees for everyone

fix(security): backport cache reuse protections and remove audit exclusion

trohitgfb97254cbd31
diff --git a/.github/workflows/predeploy.yml b/.github/workflows/predeploy.yml
index 477f9a17..da2a8b47 100644
--- a/.github/workflows/predeploy.yml
+++ b/.github/workflows/predeploy.yml
@@ -30,12 +30,16 @@ jobs:
- name: Frontend tests (vitest)
run: bun run --filter react-flow-client test
# GitHub's dependency graph cannot read bun.lock, so no Dependabot alert
- # covers the JS trees and these audits are the only check. The desktop
- # exception is documented in docs-internal/ci_cd.md ("Dependency update
- # policy"). desktop/ has its own lockfile,
- # which bun audits without installing it.
+ # covers the JS trees. Both audits run without exclusions; desktop/
+ # has its own lockfile and a Bun security patch. Test that patch after
+ # a frozen install because the audit cannot inspect its behavior.
- name: Audit JS dependencies
run: bun run audit:deps
+ - name: Verify desktop cache security patch
+ working-directory: desktop
+ run: |
+ bun install --frozen-lockfile --ignore-scripts
+ bun run test:security
- name: Audit desktop JS dependencies
working-directory: desktop
run: bun run audit:deps
diff --git a/desktop/bun.lock b/desktop/bun.lock
index 1d6b72be..b321b6ee 100644
--- a/desktop/bun.lock
+++ b/desktop/bun.lock
@@ -22,6 +22,9 @@
},
},
},
+ "patchedDependencies": {
+ },
"overrides": {
"brace-expansion@<1.1.21": {
".": "^1.1.21",
@@ -38,6 +41,7 @@
"global-agent@<4.1.3": {
".": "^4.1.3",
},
+ "http-cache-semantics": "4.3.0",
"source-map-js@<1.2.2": {
".": "^1.2.2",
},
@@ -589,7 +593,7 @@
"hosted-git-info": ["[email protected]", "", { "dependencies": { "lru-cache": "^6.0.0" } }, "sha512-kyCuEOWjJqZuDbRHzL8V93NzQhwIB71oFWSyzVo+KPZI+pnQPPxucdkrOZvkLRnrf5URsQM+IJ09Dw29cRALIA=="],
- "http-cache-semantics": ["[email protected]", "", {}, "sha512-dTxcvPXqPvXBQpq5dUr6mEMJX4oIEFv6bwom3FDwKRDsuIjjJGANqhBuoAn9c1RQJIdAKav33ED65E2ys+87QQ=="],
+ "http-cache-semantics": ["[email protected]", "", {}, "sha512-M5t5LlJpS1UHMjvwRQVdFHvPISGeLAxNcrWuJkeGh0KxsqCHZ1O3NXZU/8x7cD0BDcGW8kapxMKTvwlqrNkHkA=="],
"http-proxy-agent": ["[email protected]", "", { "dependencies": { "agent-base": "^7.1.0", "debug": "^4.3.4" } }, "sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig=="],
diff --git a/desktop/package.json b/desktop/package.json
index b05ad337..48b0c5b2 100644
--- a/desktop/package.json
+++ b/desktop/package.json
@@ -13,12 +13,13 @@
"build": "electron-vite build",
"preview": "electron-vite preview",
"typecheck": "tsc --noEmit -p tsconfig.json",
- "audit:deps": "bun audit --ignore=GHSA-ch52-4w7c-c8xp",
+ "audit:deps": "bun audit",
"fetch-runtimes": "bun run scripts/fetch-runtimes.ts",
"stage": "bun run scripts/stage.ts",
"gen-icons": "bun run scripts/gen-icons.ts",
"sync-version": "bun run scripts/sync-version.ts",
"test": "vitest run tests/unit",
+ "test:security": "vitest run tests/unit/http-cache-semantics.test.ts",
"test:invariants": "vitest run tests/invariants",
"test:e2e": "playwright test",
"pack": "electron-vite build && electron-builder --dir",
@@ -46,6 +47,10 @@
"brace-expansion@>=5.0.0 <5.0.12": "^5.0.12",
"fast-uri@>=3.0.0 <3.1.8": "^3.1.8",
"global-agent@<4.1.3": "^4.1.3",
+ "http-cache-semantics": "4.3.0",
"source-map-js@<1.2.2": "^1.2.2"
+ },
+ "patchedDependencies": {
}
}
diff --git a/desktop/patches/[email protected] b/desktop/patches/[email protected]
new file mode 100644
index 00000000..9bc65e34
--- /dev/null
+++ b/desktop/patches/[email protected]
@@ -0,0 +1,64 @@
+diff --git a/index.js b/index.js
+index 56c26025074cbcf218e3ec4d810662da93f8024e..fe659d74a73dbaf1f99029ad800ce554e155e0b1 100644
+--- a/index.js
++++ b/index.js
+@@ -369,6 +369,21 @@ module.exports = class CachePolicy {
+ };
+ }
+
++ _requiresRevalidation() {
++ // Stale allowances cannot override storage or reuse prohibitions.
++ return !!(
++ !this.storable() ||
++ this._rescc['no-cache'] ||
++ this._rescc['must-revalidate'] ||
++ this._resHeaders.vary === '*' ||
++ (this._isShared &&
++ (this._rescc['proxy-revalidate'] ||
++ (this._resHeaders['set-cookie'] &&
++ !this._rescc.public &&
++ !this._rescc.immutable)))
++ );
++ }
++
+ /**
+ * Checks if the given request matches this cache entry, and how the cache can be used to satisfy it. Returns an object with:
+ *
+@@ -396,7 +411,7 @@ module.exports = class CachePolicy {
+ this._assertRequestHasHeaders(req);
+
+ // In all circumstances, a cache MUST NOT ignore the must-revalidate directive
+- if (this._rescc['must-revalidate']) {
++ if (this._requiresRevalidation()) {
+ return this._evaluateRequestMissResult(req);
+ }
+
+@@ -706,7 +721,8 @@ module.exports = class CachePolicy {
+ * @returns {boolean} `true` if `stale-if-error` condition allows use of a stale response.
+ */
+ _useStaleIfError() {
+- return this.maxAge() + toNumberOrZero(this._rescc['stale-if-error']) > this.age();
++ return !this._requiresRevalidation() &&
++ this.maxAge() + toNumberOrZero(this._rescc['stale-if-error']) > this.age();
+ }
+
+ /** See `evaluateRequest()` for a more complete solution
+@@ -714,7 +730,8 @@ module.exports = class CachePolicy {
+ */
+ useStaleWhileRevalidate() {
+ const swr = toNumberOrZero(this._rescc['stale-while-revalidate']);
+- return swr > 0 && this.maxAge() + swr > this.age();
++ return !this._requiresRevalidation() &&
++ swr > 0 && this.maxAge() + swr > this.age();
+ }
+
+ /**
+@@ -855,7 +872,7 @@ module.exports = class CachePolicy {
+ revalidatedPolicy(request, response) {
+ this._assertRequestHasHeaders(request);
+
+- if (this._useStaleIfError() && isErrorResponse(response)) {
++ if (this._requestMatches(request, true) && this._useStaleIfError() && isErrorResponse(response)) {
+ return {
+ policy: this,
+ modified: false,
diff --git a/desktop/tests/unit/http-cache-semantics.test.ts b/desktop/tests/unit/http-cache-semantics.test.ts
new file mode 100644
index 00000000..ad8788d6
--- /dev/null
+++ b/desktop/tests/unit/http-cache-semantics.test.ts
@@ -0,0 +1,130 @@
+import { createRequire } from "node:module";
+
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+
+// Exercise the dependency actually used by electron-builder, including its Bun patch.
+let dependencyRequire = createRequire(import.meta.url);
+for (const packageName of ["electron-builder", "app-builder-lib", "@electron/get", "got", "cacheable-request"]) {
+ dependencyRequire = createRequire(dependencyRequire.resolve(packageName));
+}
+const CachePolicy = dependencyRequire("http-cache-semantics");
+const now = Date.parse("2026-10-09T00:00:00Z");
+type Headers = Record<string, string>;
+
+const request = (headers: Headers = {}) => ({
+ url: "https://cache-fixture.example/account",
+ method: "GET",
+ headers: { host: "cache-fixture.example", ...headers },
+});
+
+function policyFor(headers: Headers, requestHeaders: Headers = {}, shared = true) {
+ const policy = new CachePolicy(request(requestHeaders), {
+ status: 200,
+ headers: { date: new Date(now).toUTCString(), ...headers },
+ }, { shared });
+ policy.now = () => now + 60_000;
+ return policy;
+}
+
+const restricted: [string, Headers, Headers?][] = [
+ ["shared Set-Cookie", { "cache-control": "max-age=600", "set-cookie": "fixture-user=alice" }],
+ ["shared proxy-revalidate", { "cache-control": "max-age=600, proxy-revalidate" }],
+ ["must-revalidate", { "cache-control": "max-age=30, must-revalidate" }],
+ ["shared private", { "cache-control": "max-age=600, private" }],
+ ["response no-store", { "cache-control": "max-age=600, no-store" }],
+ ["response no-cache", { "cache-control": "max-age=600, no-cache" }],
+ ["Vary wildcard", { "cache-control": "max-age=600", vary: "*" }],
+ ["request no-store", { "cache-control": "max-age=600" }, { "cache-control": "no-store" }],
+ ["shared authenticated", { "cache-control": "max-age=600" }, { authorization: "fixture-user alice" }],
+];
+
+beforeEach(() => vi.spyOn(Date, "now").mockReturnValue(now));
+afterEach(() => vi.restoreAllMocks());
+
+describe("http-cache-semantics shared-cache disclosure regression", () => {
+ for (const [label, headers, requestHeaders] of restricted) {
+ for (const maxStale of ["max-stale", "max-stale=3600"]) {
+ it(`${label} cannot be reused with ${maxStale}, including after serialization`, () => {
+ const original = policyFor(headers, requestHeaders);
+ const restored = CachePolicy.fromObject(JSON.parse(JSON.stringify(original.toObject())));
+ restored.now = original.now;
+ for (const policy of [original, restored]) {
+ const incoming = request({ ...requestHeaders, "cache-control": maxStale });
+ const result = policy.evaluateRequest(incoming);
+ expect(result.response).toBeUndefined();
+ expect(result.revalidation?.synchronous).toBe(true);
+ expect(policy.satisfiesWithoutRevalidation(incoming)).toBe(false);
+ }
+ });
+ }
+
+ it(`${label} cannot bypass restrictions with stale error or background revalidation`, () => {
+ const policy = policyFor({
+ ...headers,
+ "cache-control": `${headers["cache-control"]}, stale-if-error=3600, stale-while-revalidate=3600`,
+ }, requestHeaders);
+ expect(policy._useStaleIfError()).toBe(false);
+ expect(policy.useStaleWhileRevalidate()).toBe(false);
+ const result = policy.revalidatedPolicy(request(requestHeaders), { status: 503, headers: {} });
+ expect(result.policy).not.toBe(policy);
+ expect(result.matches).toBe(false);
+ expect(result.modified).toBe(true);
+ });
+ }
+
+ it.each([
+ ["fresh public", "public, max-age=600", {}, true, {}],
+ ["stale public", "public, max-age=30", {}, true, { "cache-control": "max-stale=3600" }],
+ ["public zero lifetime", "public, max-age=0", {}, true, { "cache-control": "max-stale=3600" }],
+ ["private cache cookies", "max-age=600", { "set-cookie": "fixture-user=alice" }, false, {}],
+ ["explicit public cookies", "public, max-age=600", { "set-cookie": "fixture-user=alice" }, true, {}],
+ ["explicit immutable cookies", "immutable, max-age=600", { "set-cookie": "fixture-user=alice" }, true, {}],
+ ] as [string, string, Headers, boolean, Headers][])(
+ "preserves %s responses",
+ (_label, cacheControl, headers, shared, requestHeaders) => {
+ const policy = policyFor({ "cache-control": cacheControl, ...headers }, {}, shared);
+ const result = policy.evaluateRequest(request(requestHeaders));
+ expect(result.response).toBeDefined();
+ expect(result.revalidation).toBeUndefined();
+ expect(policy.satisfiesWithoutRevalidation(request(requestHeaders))).toBe(true);
+ },
+ );
+
+ it("preserves stale public background revalidation and error fallback", () => {
+ const policy = policyFor({ "cache-control": "public, max-age=30, stale-if-error=3600, stale-while-revalidate=3600" });
+ expect(policy._useStaleIfError()).toBe(true);
+ expect(policy.useStaleWhileRevalidate()).toBe(true);
+ const result = policy.evaluateRequest(request());
+ expect(result.response).toBeDefined();
+ expect(result.revalidation?.synchronous).toBe(false);
+ expect(policy.revalidatedPolicy(request(), { status: 503, headers: {} }).policy).toBe(policy);
+ });
+
+ it.each(["URL", "Vary principal"])("does not use error fallback for a different %s", (mismatch) => {
+ const alice = { authorization: "fixture-user alice" };
+ const policy = policyFor({
+ "cache-control": "public, max-age=30, stale-if-error=3600",
+ vary: "authorization",
+ }, alice);
+ expect(policy._useStaleIfError()).toBe(true);
+ const incoming = mismatch === "URL"
+ ? { ...request(alice), url: "https://cache-fixture.example/other-account" }
+ : request({ authorization: "fixture-user bob" });
+ const result = policy.revalidatedPolicy(incoming, { status: 503, headers: {} });
+ expect(result.policy).not.toBe(policy);
+ expect(result.matches).toBe(false);
+ expect(result.modified).toBe(true);
+ });
+
+ it("keeps incoming request no-cache restricted", () => {
+ const policy = policyFor({ "cache-control": "public, max-age=600" });
+ expect(policy.evaluateRequest(request({ "cache-control": "no-cache, max-stale" })).response).toBeUndefined();
+ });
+
+ it("does not reuse an authenticated Vary entry for a different principal", () => {
+ const policy = policyFor({ "cache-control": "public, max-age=600", vary: "authorization" }, { authorization: "fixture-user alice" });
+ const result = policy.evaluateRequest(request({ authorization: "fixture-user bob", "cache-control": "max-stale" }));
+ expect(result.response).toBeUndefined();
+ expect(result.revalidation?.synchronous).toBe(true);
+ });
+});
diff --git a/docs-internal/ci_cd.md b/docs-internal/ci_cd.md
index 4e4dff77..ea7e94da 100644
--- a/docs-internal/ci_cd.md
+++ b/docs-internal/ci_cd.md
@@ -328,25 +328,30 @@ the latest checks instead.
GitHub's dependency graph does not read `bun.lock`; it sees only the ranges
in each `package.json`, so no Dependabot alert ever covers a resolved JS
version. `bun run audit:deps` is the check: `predeploy.yml` runs it at the
-root and in `desktop/` (`bun audit` reads the lockfile and needs no install).
-The root audit has no exclusions. The desktop audit fails on any advisory
-except the explicit exception below. An advisory
-is ignored only when it has no patched release and cannot be reached from
-untrusted input here:
-
-| Advisory | Package | Reached through | Why it is ignored |
-|---|---|---|---|
-| [GHSA-ch52-4w7c-c8xp](https://github.com/advisories/GHSA-ch52-4w7c-c8xp) | http-cache-semantics 4.2.0 | `desktop/`: Electron Builder → app-builder-lib → @electron/get 3.1.0 → got → cacheable-request | No verified upstream fix as of 2026-10-09; published 4.3.0 also reproduces the reported behavior. Build-time artifact downloading does not share authenticated user-response caches; this chain is absent from the shipped desktop runtime dependencies. |
-
-The 4.3.0 registry tarball was checked against its published SHA-512 integrity
-and tested with a fixed-clock shared-cache fixture on 2026-10-09. Responses
-containing `Set-Cookie` or `proxy-revalidate` were rejected for ordinary requests
-but reused when the request supplied `max-stale=3600`; the cookie was returned
-in the first case. The `must-revalidate` control prevented reuse. Both installed
-4.2.0 and published 4.3.0 behaved this way. The
-[published 4.3.0 source](https://github.com/kornelski/http-cache-semantics/blob/b1d4bd682fbab0252985de45219f4e7497c0067c/index.js)
-retains this logic. Moving beyond an advisory's current version range alone
-does not establish remediation.
+root and in `desktop/` (`bun audit` reads the lockfile). Both audits have no
+exclusions and fail on any advisory.
+
+The desktop chain Electron Builder → app-builder-lib → @electron/get 3.1.0
+→ got → cacheable-request uses `http-cache-semantics`. To address
+[GHSA-ch52-4w7c-c8xp](https://github.com/advisories/GHSA-ch52-4w7c-c8xp),
+`desktop/package.json` pins the compatible 4.3.0 release and applies the
+[security backport](../desktop/patches/[email protected]) through
+Bun's standard `patchedDependencies`. The published 4.3.0 source still reproduces
+the unsafe behavior, so the version floor alone is insufficient. The patch
+requires validation before responses barred from reuse can be served through
+`max-stale`, `stale-while-revalidate` or `stale-if-error`. Error fallback must also
+match the URL, host, method and Vary headers. It preserves ordinary stale reuse,
+private caches and the library's explicit public/immutable cookie opt-ins.
+
+`predeploy.yml` runs a frozen desktop install with lifecycle scripts disabled,
+then `bun run test:security`, before its desktop audit. The
+[security canaries](../desktop/tests/unit/http-cache-semantics.test.ts) use the
+actual builder dependency chain, a fixed clock and fake credentials. They cover
+unsafe reuse, serialized policies and compatible caching behavior; they failed
+against unpatched 4.3.0 and pass with the backport. Desktop CI also runs them in
+the full unit suite. All 128 official upstream tests at the published 4.3.0
+commit passed before and after patching. A clean audit is paired with behavioral
+checks because advisory version ranges cannot verify a local security patch.
The shadcn CLI was removed from `client/package.json` and the root lockfile on
2026-10-09, removing `braces` and its advisory entirely. The client used one
@@ -360,14 +365,14 @@ Electron itself uses `@electron/get` 5.1.0, which uses native fetch. Stable
Electron Builder 26.17.0 (the `v26` tag; `latest` remains 26.15.3) still requires
3.x. Do not force a 5.x transitive override: its removed GotDownloader API,
changed download options and proxy handling are incompatible with that caller.
-The migration is in Electron Builder 27 prereleases; wait for a supported
-stable release and validate packaging before removing the exception. See the
+The migration is in Electron Builder 27 prereleases. Keep the compatible
+security backport until a tested stable upgrade fixes or removes this chain. See the
[downloader migration notes](https://github.com/electron/get/releases/tag/v5.0.0).
-When the affected package gets a patch, drop `--ignore` and pin the fix in
-`overrides`; a compatible parent upgrade that removes the package also resolves
-the advisory. A passing audit with this exception does not mean the raw desktop
-audit is clean.
+When an upstream release fixes the behavior, update the version floor and remove
+the local patch only after the same security tests pass without it. A compatible
+parent upgrade that removes the package also resolves the advisory; validate
+desktop packaging before dropping its obsolete override and tests.
Re-enable updates deliberately, never by just deleting the ignore rules:
raise `open-pull-requests-limit`, add `groups` with `patterns: ["*"]` +