Skip to content

Commit 7b7e589

Browse files
committed
fix(tanstack-start): ship CVE-2026-102989 patch with published package
The pnpm patchedDependencies entry only applies inside the declaring workspace. Published @octanejs/tanstack-start still depended on unpatched @tanstack/[email protected], so consumers installing the patch release still loaded the vulnerable handler. Ship the fix with the published package: - Add a postinstall script (scripts/postinstall-cve-patch.mjs) that applies the same four security-critical replacements to the co-installed @tanstack/[email protected]. The script is idempotent — it exits silently when the handler already carries the fix. - Bundle the pnpm-format patch file in patches/ for consumers whose environment disables lifecycle scripts; the changeset notes provide the pnpm-workspace.yaml snippet they need. - Update the changeset to accurately describe the consumer-side mechanism.
1 parent 8e03fcb commit 7b7e589

4 files changed

Lines changed: 137 additions & 0 deletions

File tree

‎.changeset/tanstack-start-cve-2026-102989.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,17 @@ method}` fields, and a non-`Response` result is no longer returned as the raw
2121
HTTP response on the non-server-function path. The patch is removed once Octane
2222
can adopt start-server-core >= 1.169.39.
2323

24+
Because pnpm `patchedDependencies` only apply inside the declaring workspace, the
25+
published package also ships a `postinstall` script that applies the same fix to
26+
the co-installed `@tanstack/[email protected]`. If your environment
27+
disables lifecycle scripts (`--ignore-scripts`), add the patch manually — a copy
28+
is bundled at `node_modules/@octanejs/tanstack-start/patches/@[email protected]`.
29+
For pnpm workspaces, add to `pnpm-workspace.yaml`:
30+
31+
```yaml
32+
patchedDependencies:
33+
'@tanstack/[email protected]': 'node_modules/@octanejs/tanstack-start/patches/@[email protected]'
34+
```
35+
2436
Apps must rebuild and redeploy to pick up the fix; upgrading the dependency alone
2537
does not patch an already-deployed app.

‎packages/tanstack-start/package.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"types": "src/index.d.ts",
3232
"files": [
3333
"src",
34+
"scripts/postinstall-cve-patch.mjs",
35+
"patches",
3436
"LICENSE",
3537
"README.md",
3638
"THIRD_PARTY_NOTICES.md"
@@ -113,6 +115,7 @@
113115
"./src/default-entry/client.js"
114116
],
115117
"scripts": {
118+
"postinstall": "node scripts/postinstall-cve-patch.mjs",
116119
"test": "cd ../.. && vitest run --project tanstack-start --project tanstack-start-rsbuild"
117120
},
118121
"dependencies": {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
diff --git a/dist/esm/server-functions-handler.js b/dist/esm/server-functions-handler.js
2+
index c493774211d1ea4b966e9fcd437e3e833d8f932e..69e7b1590fbdc9640b62152e1aaff7331bf7f01c 100644
3+
--- a/dist/esm/server-functions-handler.js
4+
+++ b/dist/esm/server-functions-handler.js
5+
@@ -49,21 +49,25 @@ var handleServerAction = async ({ request, context, serverFnId }) => {
6+
if (methodUpper === "GET") {
7+
const payloadParam = url.searchParams.get("payload");
8+
if (payloadParam && payloadParam.length > MAX_PAYLOAD_SIZE) throw new Error("Payload too large");
9+
- const payload = payloadParam ? parsePayload(JSON.parse(payloadParam)) : {};
10+
- payload.context = safeObjectMerge(payload.context, context);
11+
- payload.method = methodUpper;
12+
- return await action(payload);
13+
+ const payload = payloadParam ? parsePayload(JSON.parse(payloadParam)) : void 0;
14+
+ return await action({
15+
+ data: payload?.data,
16+
+ context: safeObjectMerge(payload?.context, context),
17+
+ method: methodUpper
18+
+ });
19+
}
20+
let jsonPayload;
21+
if (contentType?.includes("application/json")) jsonPayload = await request.json();
22+
- const payload = jsonPayload ? parsePayload(jsonPayload) : {};
23+
- payload.context = safeObjectMerge(payload.context, context);
24+
- payload.method = methodUpper;
25+
- return await action(payload);
26+
+ const payload = jsonPayload ? parsePayload(jsonPayload) : void 0;
27+
+ return await action({
28+
+ data: payload?.data,
29+
+ context: safeObjectMerge(payload?.context, context),
30+
+ method: methodUpper
31+
+ });
32+
})();
33+
- const unwrapped = res.result || res.error;
34+
+ const unwrapped = res.error !== void 0 ? res.error : res.result;
35+
if (isNotFound(res)) res = isNotFoundResponse(res);
36+
- if (!isServerFn) return unwrapped;
37+
+ if (!isServerFn && (unwrapped instanceof Response || unwrapped === null || typeof unwrapped !== "object")) return unwrapped;
38+
if (unwrapped instanceof Response) {
39+
if (isRedirect(unwrapped)) return unwrapped;
40+
unwrapped.headers.set(X_TSS_RAW_RESPONSE, "true");
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Backport the fix for CVE-2026-102989 onto an unpatched
3+
* @tanstack/[email protected] that was installed from the public
4+
* registry. The workspace-level pnpm patch does the same thing locally, but
5+
* patchedDependencies do not propagate to consumers of a published package, so
6+
* this postinstall bridge fills the gap.
7+
*
8+
* The script is idempotent: it exits silently when the handler already carries
9+
* the fix (patched by pnpm, or on a newer upstream release).
10+
*/
11+
12+
import { readFileSync, writeFileSync } from 'node:fs';
13+
import { createRequire } from 'node:module';
14+
import { dirname, join } from 'node:path';
15+
16+
const require = createRequire(import.meta.url);
17+
18+
let handlerPath;
19+
try {
20+
const pkgPath = require.resolve('@tanstack/start-server-core/package.json');
21+
handlerPath = join(dirname(pkgPath), 'dist', 'esm', 'server-functions-handler.js');
22+
} catch {
23+
process.exit(0);
24+
}
25+
26+
let source;
27+
try {
28+
source = readFileSync(handlerPath, 'utf8');
29+
} catch {
30+
process.exit(0);
31+
}
32+
33+
if (!source.includes('payload.method = methodUpper')) {
34+
process.exit(0);
35+
}
36+
37+
const replacements = [
38+
{
39+
old: 'const payload = payloadParam ? parsePayload(JSON.parse(payloadParam)) : {};\n\t\t\t\t\tpayload.context = safeObjectMerge(payload.context, context);\n\t\t\t\t\tpayload.method = methodUpper;\n\t\t\t\t\treturn await action(payload)',
40+
new: 'const payload = payloadParam ? parsePayload(JSON.parse(payloadParam)) : void 0;\n\t\t\t\t\treturn await action({\n\t\t\t\t\t\tdata: payload?.data,\n\t\t\t\t\t\tcontext: safeObjectMerge(payload?.context, context),\n\t\t\t\t\t\tmethod: methodUpper\n\t\t\t\t\t})',
41+
},
42+
{
43+
old: 'const payload = jsonPayload ? parsePayload(jsonPayload) : {};\n\t\t\t\tpayload.context = safeObjectMerge(payload.context, context);\n\t\t\t\tpayload.method = methodUpper;\n\t\t\t\treturn await action(payload)',
44+
new: 'const payload = jsonPayload ? parsePayload(jsonPayload) : void 0;\n\t\t\t\treturn await action({\n\t\t\t\t\tdata: payload?.data,\n\t\t\t\t\tcontext: safeObjectMerge(payload?.context, context),\n\t\t\t\t\tmethod: methodUpper\n\t\t\t\t})',
45+
},
46+
{
47+
old: 'const unwrapped = res.result || res.error',
48+
new: 'const unwrapped = res.error !== void 0 ? res.error : res.result',
49+
},
50+
{
51+
old: 'if (!isServerFn) return unwrapped;',
52+
new: 'if (!isServerFn && (unwrapped instanceof Response || unwrapped === null || typeof unwrapped !== "object")) return unwrapped;',
53+
},
54+
];
55+
56+
let patched = source;
57+
for (const { old: from, new: to } of replacements) {
58+
patched = patched.replace(from, to);
59+
}
60+
61+
if (patched === source) {
62+
console.warn(
63+
'[@octanejs/tanstack-start] Could not auto-apply the CVE-2026-102989 fix.\n' +
64+
'If using pnpm, add to pnpm-workspace.yaml:\n' +
65+
' patchedDependencies:\n' +
66+
" '@tanstack/[email protected]': " +
67+
"'node_modules/@octanejs/tanstack-start/patches/@[email protected]'",
68+
);
69+
process.exit(0);
70+
}
71+
72+
try {
73+
writeFileSync(handlerPath, patched);
74+
} catch {
75+
console.warn(
76+
'[@octanejs/tanstack-start] Could not write the CVE-2026-102989 fix (read-only node_modules).\n' +
77+
'If using pnpm, add to pnpm-workspace.yaml:\n' +
78+
' patchedDependencies:\n' +
79+
" '@tanstack/[email protected]': " +
80+
"'node_modules/@octanejs/tanstack-start/patches/@[email protected]'",
81+
);
82+
}

0 commit comments

Comments
 (0)