
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
@tanstack/server-functions-plugin
Advanced tools
Modern and scalable routing for React applications
Create a new instance of the plugin with the following options:
const TanStackServerFnsPlugin = createTanStackServerFnPlugin({
// This is the ID (virtual module) that will be made available to look up
// and import our server function manifest and resolve its modules.
manifestVirtualImportId: 'tanstack:server-fn-manifest',
client: {
getRuntimeCode: () =>
`import { createClientRpc } from '@tanstack/react-start/client-runtime'`,
replacer: (opts) => `createClientRpc(${JSON.stringify(opts.functionId)})`,
},
ssr: {
getRuntimeCode: () =>
`import { createSsrRpc } from '@tanstack/react-start/ssr-runtime'`,
replacer: (opts) => `createSsrRpc(${JSON.stringify(opts.functionId)})`,
},
server: {
getRuntimeCode: () =>
`import { createServerRpc } from '@tanstack/react-start/server-runtime'`,
replacer: (opts) =>
`createServerRpc(${JSON.stringify(opts.functionId)}, ${opts.fn})`,
},
})
Then you can inject the plugin into the appropriate vite config plugin arrays:
clientVitePlugins: [TanStackServerFnsPlugin.client]
ssrVitePlugins: [TanStackServerFnsPlugin.ssr]
serverVitePlugins: [TanStackServerFnsPlugin.server]
Each runtime replacement should be implemented by your framework. Generally, on the client and SSR runtimes, you'll end up using a fetch
call to call the server function your desired endpoint, like this:
function createClientRpc(functionId: string) {
const url = `${process.env.YOUR_SERVER_BASE}/_serverFn/${functionId}`
const fn = async (...args: any[]) => {
const res = await fetch(url, {
method: 'POST',
// You'll likely want to use a better serializer here
body: JSON.stringify(args),
})
return await res.json()
}
// You can also assign any other properties you want to the function
// for things like form actions, or debugging
Object.assign(fn, {
url: url,
})
return fn
}
In your server handler, you can import the manifest and use it to look up and dynamically import the server function you want to call.
import serverFnManifest from 'tanstack:server-fn-manifest'
export const handler = async (req: Request) => {
const functionId = req.url.split('/').pop()
invariant(functionId, 'No function ID provided')
const fnInfo = serverFnManifest[functionId]
invariant(fn, `Server function ${functionId} not found`)
const fnModule = await fnInfo.importer()
invariant(fnModule, `Server function ${functionId} could not be imported`)
const args = await req.json()
return await fnModule(...args)
}
FAQs
Modern and scalable routing for React applications
The npm package @tanstack/server-functions-plugin receives a total of 68,096 weekly downloads. As such, @tanstack/server-functions-plugin popularity was classified as popular.
We found that @tanstack/server-functions-plugin demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.