Skip to content

bug: max batch size handling bypass #7153

Closed

Description

@karrui

Provide environment information

Binaries:
Node: 24.13.0 - ~/fnm_multishells/98932_1770386641777/bin/node
pnpm: 10.17.1 - ~/fnm_multishells/98932_1770386641777/bin/pnpm
npmPackages:
@tanstack/react-query: catalog:react-query5 => 5.90.20
@trpc/client: catalog:trpc => 11.9.0
@trpc/server: catalog:trpc => 11.9.0
next: catalog:next => 16.1.5
react: catalog:react => 19.2.3
typescript: catalog: => 5.9.3

Describe the bug

The (specific) bug reported in #5825 is still not fixed in TRPC v11.
Even though the batch size can be handled in context as recommended:

{
  createContext: (opts) => {
    if (opts.info.calls.length > 5) {
      throw new TRPCError({
        code: 'BAD_REQUEST',
        message: `Batch size limit exceeded. Max batch size is ${MAX_BATCH_SIZE}.`,
      })
    }
  }
}

invalid trpc procedure paths never reach the createContext handler.

Steps to reproduce:

  1. GET http://localhost:3000/api/trpc/,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,?batch=1
  2. Depending on the number of "procedures", wait 0-timeout for the request to resolve, whilst hogging the connection
  3. Get a bunch of errors, (though attackers won't care)
   "error": {
      "json": {
        "message": "No procedure found on path \"\"",
        "code": -32004,
        "data": {
          "code": "NOT_FOUND",
          "httpStatus": 404,

Note that the error handling from createContext never triggers as the invalid procedure error triggers (as it should) before the context.

Suggest the batch handling function to also have a maxItem prop to limit the number to prevent denial of service in batch mode.

Link to reproduction

To reproduce

Seems to require using fetchRequestHandler + enableBatching.

Example NextJS API route handler:

import type { NextRequest } from 'next/server'
import { TRPCError } from '@trpc/server'
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'

import { appRouter } from '~/server/api/root'
import { createTRPCContext } from '~/server/api/trpc'

/**
 * Configure basic CORS headers
 * You should extend this to match your needs
 */
const setCorsHeaders = (res: Response) => {
  res.headers.set('Access-Control-Allow-Origin', '*')
  res.headers.set('Access-Control-Request-Method', '*')
  res.headers.set('Access-Control-Allow-Methods', 'OPTIONS, GET, POST')
  res.headers.set('Access-Control-Allow-Headers', '*')
}

export const OPTIONS = () => {
  const response = new Response(null, {
    status: 204,
  })
  setCorsHeaders(response)
  return response
}

const MAX_BATCH_SIZE = 20

const handler = async (req: NextRequest) => {
  const response = await fetchRequestHandler({
    endpoint: '/api/trpc',
    router: appRouter,
    req,
    allowBatching: true,
    createContext: (opts) => {
      if (opts.info.calls.length > 5) {
        throw new TRPCError({
          code: 'BAD_REQUEST',
          message: `Batch size limit exceeded. Max batch size is ${MAX_BATCH_SIZE}.`,
        })
      }
      return createTRPCContext({
        headers: req.headers,
        resHeaders: opts.resHeaders,
      })
    },
    onError({ error, path, ctx }) {
      if (error.code === 'UNAUTHORIZED') {
        ctx?.session.destroy()
      }
      console.error(`>>> tRPC Error on '${path}'`, error)
    },
  })

  setCorsHeaders(response)
  return response
}

export { handler as GET, handler as POST }

Steps to reproduce:

  1. GET http://localhost:3000/api/trpc/,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,?batch=1
  2. Depending on the number of "procedures", wait 0-timeout for the request to resolve, whilst hogging the connection
  3. Get a bunch of errors, (though attackers won't care)
   "error": {
      "json": {
        "message": "No procedure found on path \"\"",
        "code": -32004,
        "data": {
          "code": "NOT_FOUND",
          "httpStatus": 404,

Note that the error handling from createContext never triggers as the invalid procedure error triggers (as it should) before the context.

Additional information

No response

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I'd be down to file a PR fixing this bug!

EDIT:
Even if the procedures are valid, attackers can still spam with legitimate procedures. It still takes NxK seconds, where N is the number of procedures passed into the batch, and K is somewhat constant. Is there no way to short circuit the max item check?

All the context error handler does is return X amount of error messages back to the request like so:

[
  {
    "error": {
      "json": {
        "message": "Batch size limit exceeded. Max batch size is 20.",
        "code": -32600,
        "data": {
          "code": "BAD_REQUEST",
          "httpStatus": 400,
          "stack": "TRPCError: Batch size limit exceeded. Max batch size is 20.\n    at Object.createContext (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/[root-of-the-server]__943a866e._.js:4887:19)\n    at Object.createContext (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3491:133)\n    at Object.create (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3116:44)\n    at resolveResponse (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3148:26)\n    at async fetchRequestHandler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3500:12)\n    at async handler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/[root-of-the-server]__943a866e._.js:4881:22)\n    at async AppRouteRouteModule.do (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:5:37866)\n    at async AppRouteRouteModule.handle (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:5:45156)\n    at async responseGenerator (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12024:38)\n    at async AppRouteRouteModule.handleResponse (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:1:187713)\n    at async handleResponse (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12087:32)\n    at async Module.handler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12140:13)\n    at async DevServer.renderToResponseWithComponentsImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1442:9)\n    at async DevServer.renderPageComponent (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1494:24)\n    at async DevServer.renderToResponseImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1544:32)\n    at async DevServer.pipeImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1038:25)\n    at async NextNodeServer.handleCatchallRenderRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/next-server.js:395:17)\n    at async DevServer.handleRequestImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:929:17)\n    at async /Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/dev/next-dev-server.js:387:20\n    at async Span.traceAsyncFn (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/trace/trace.js:157:20)\n    at async DevServer.handleRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/dev/next-dev-server.js:383:24)\n    at async invokeRender (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:248:21)\n    at async handleRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:447:24)\n    at async requestHandlerImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:496:13)\n    at async Server.requestListener (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/start-server.js:226:13)",
          "path": "me.get",
          "zodError": null
        }
      }
    }
  },
  {
    "error": {
      "json": {
        "message": "Batch size limit exceeded. Max batch size is 20.",
        "code": -32600,
        "data": {
          "code": "BAD_REQUEST",
          "httpStatus": 400,
          "stack": "TRPCError: Batch size limit exceeded. Max batch size is 20.\n    at Object.createContext (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/[root-of-the-server]__943a866e._.js:4887:19)\n    at Object.createContext (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3491:133)\n    at Object.create (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3116:44)\n    at resolveResponse (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3148:26)\n    at async fetchRequestHandler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3500:12)\n    at async handler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/[root-of-the-server]__943a866e._.js:4881:22)\n    at async AppRouteRouteModule.do (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:5:37866)\n    at async AppRouteRouteModule.handle (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:5:45156)\n    at async responseGenerator (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12024:38)\n    at async AppRouteRouteModule.handleResponse (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:1:187713)\n    at async handleResponse (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12087:32)\n    at async Module.handler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12140:13)\n    at async DevServer.renderToResponseWithComponentsImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1442:9)\n    at async DevServer.renderPageComponent (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1494:24)\n    at async DevServer.renderToResponseImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1544:32)\n    at async DevServer.pipeImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1038:25)\n    at async NextNodeServer.handleCatchallRenderRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/next-server.js:395:17)\n    at async DevServer.handleRequestImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:929:17)\n    at async /Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/dev/next-dev-server.js:387:20\n    at async Span.traceAsyncFn (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/trace/trace.js:157:20)\n    at async DevServer.handleRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/dev/next-dev-server.js:383:24)\n    at async invokeRender (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:248:21)\n    at async handleRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:447:24)\n    at async requestHandlerImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:496:13)\n    at async Server.requestListener (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/start-server.js:226:13)",
          "path": "me.get",
          "zodError": null
        }
      }
    }
  },
  {
    "error": {
      "json": {
        "message": "Batch size limit exceeded. Max batch size is 20.",
        "code": -32600,
        "data": {
          "code": "BAD_REQUEST",
          "httpStatus": 400,
          "stack": "TRPCError: Batch size limit exceeded. Max batch size is 20.\n    at Object.createContext (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/[root-of-the-server]__943a866e._.js:4887:19)\n    at Object.createContext (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3491:133)\n    at Object.create (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3116:44)\n    at resolveResponse (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3148:26)\n    at async fetchRequestHandler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3500:12)\n    at async handler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/[root-of-the-server]__943a866e._.js:4881:22)\n    at async AppRouteRouteModule.do (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:5:37866)\n    at async AppRouteRouteModule.handle (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:5:45156)\n    at async responseGenerator (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12024:38)\n    at async AppRouteRouteModule.handleResponse (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:1:187713)\n    at async handleResponse (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12087:32)\n    at async Module.handler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12140:13)\n    at async DevServer.renderToResponseWithComponentsImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1442:9)\n    at async DevServer.renderPageComponent (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1494:24)\n    at async DevServer.renderToResponseImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1544:32)\n    at async DevServer.pipeImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1038:25)\n    at async NextNodeServer.handleCatchallRenderRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/next-server.js:395:17)\n    at async DevServer.handleRequestImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:929:17)\n    at async /Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/dev/next-dev-server.js:387:20\n    at async Span.traceAsyncFn (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/trace/trace.js:157:20)\n    at async DevServer.handleRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/dev/next-dev-server.js:383:24)\n    at async invokeRender (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:248:21)\n    at async handleRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:447:24)\n    at async requestHandlerImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:496:13)\n    at async Server.requestListener (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/start-server.js:226:13)",
          "path": "me.get",
          "zodError": null
        }
      }
    }
  },
  {
    "error": {
      "json": {
        "message": "Batch size limit exceeded. Max batch size is 20.",
        "code": -32600,
        "data": {
          "code": "BAD_REQUEST",
          "httpStatus": 400,
          "stack": "TRPCError: Batch size limit exceeded. Max batch size is 20.\n    at Object.createContext (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/[root-of-the-server]__943a866e._.js:4887:19)\n    at Object.createContext (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3491:133)\n    at Object.create (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3116:44)\n    at resolveResponse (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3148:26)\n    at async fetchRequestHandler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3500:12)\n    at async handler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/[root-of-the-server]__943a866e._.js:4881:22)\n    at async AppRouteRouteModule.do (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:5:37866)\n    at async AppRouteRouteModule.handle (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:5:45156)\n    at async responseGenerator (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12024:38)\n    at async AppRouteRouteModule.handleResponse (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:1:187713)\n    at async handleResponse (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12087:32)\n    at async Module.handler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12140:13)\n    at async DevServer.renderToResponseWithComponentsImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1442:9)\n    at async DevServer.renderPageComponent (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1494:24)\n    at async DevServer.renderToResponseImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1544:32)\n    at async DevServer.pipeImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1038:25)\n    at async NextNodeServer.handleCatchallRenderRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/next-server.js:395:17)\n    at async DevServer.handleRequestImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:929:17)\n    at async /Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/dev/next-dev-server.js:387:20\n    at async Span.traceAsyncFn (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/trace/trace.js:157:20)\n    at async DevServer.handleRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/dev/next-dev-server.js:383:24)\n    at async invokeRender (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:248:21)\n    at async handleRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:447:24)\n    at async requestHandlerImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:496:13)\n    at async Server.requestListener (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/start-server.js:226:13)",
          "path": "me.get",
          "zodError": null
        }
      }
    }
  },
  {
    "error": {
      "json": {
        "message": "Batch size limit exceeded. Max batch size is 20.",
        "code": -32600,
        "data": {
          "code": "BAD_REQUEST",
          "httpStatus": 400,
          "stack": "TRPCError: Batch size limit exceeded. Max batch size is 20.\n    at Object.createContext (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/[root-of-the-server]__943a866e._.js:4887:19)\n    at Object.createContext (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3491:133)\n    at Object.create (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3116:44)\n    at resolveResponse (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3148:26)\n    at async fetchRequestHandler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3500:12)\n    at async handler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/[root-of-the-server]__943a866e._.js:4881:22)\n    at async AppRouteRouteModule.do (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:5:37866)\n    at async AppRouteRouteModule.handle (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:5:45156)\n    at async responseGenerator (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12024:38)\n    at async AppRouteRouteModule.handleResponse (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:1:187713)\n    at async handleResponse (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12087:32)\n    at async Module.handler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12140:13)\n    at async DevServer.renderToResponseWithComponentsImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1442:9)\n    at async DevServer.renderPageComponent (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1494:24)\n    at async DevServer.renderToResponseImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1544:32)\n    at async DevServer.pipeImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1038:25)\n    at async NextNodeServer.handleCatchallRenderRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/next-server.js:395:17)\n    at async DevServer.handleRequestImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:929:17)\n    at async /Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/dev/next-dev-server.js:387:20\n    at async Span.traceAsyncFn (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/trace/trace.js:157:20)\n    at async DevServer.handleRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/dev/next-dev-server.js:383:24)\n    at async invokeRender (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:248:21)\n    at async handleRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:447:24)\n    at async requestHandlerImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:496:13)\n    at async Server.requestListener (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/start-server.js:226:13)",
          "path": "me.get",
          "zodError": null
        }
      }
    }
  },
  {
    "error": {
      "json": {
        "message": "Batch size limit exceeded. Max batch size is 20.",
        "code": -32600,
        "data": {
          "code": "BAD_REQUEST",
          "httpStatus": 400,
          "stack": "TRPCError: Batch size limit exceeded. Max batch size is 20.\n    at Object.createContext (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/[root-of-the-server]__943a866e._.js:4887:19)\n    at Object.createContext (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3491:133)\n    at Object.create (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3116:44)\n    at resolveResponse (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3148:26)\n    at async fetchRequestHandler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/9d556_@trpc_server_dist_3d201f77._.js:3500:12)\n    at async handler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/[root-of-the-server]__943a866e._.js:4881:22)\n    at async AppRouteRouteModule.do (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:5:37866)\n    at async AppRouteRouteModule.handle (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:5:45156)\n    at async responseGenerator (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12024:38)\n    at async AppRouteRouteModule.handleResponse (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js:1:187713)\n    at async handleResponse (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12087:32)\n    at async Module.handler (/Users/karrui/Projects/confetti/apps/web/.next/dev/server/chunks/030e1_next_98832fc2._.js:12140:13)\n    at async DevServer.renderToResponseWithComponentsImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1442:9)\n    at async DevServer.renderPageComponent (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1494:24)\n    at async DevServer.renderToResponseImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1544:32)\n    at async DevServer.pipeImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:1038:25)\n    at async NextNodeServer.handleCatchallRenderRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/next-server.js:395:17)\n    at async DevServer.handleRequestImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/base-server.js:929:17)\n    at async /Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/dev/next-dev-server.js:387:20\n    at async Span.traceAsyncFn (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/trace/trace.js:157:20)\n    at async DevServer.handleRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/dev/next-dev-server.js:383:24)\n    at async invokeRender (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:248:21)\n    at async handleRequest (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:447:24)\n    at async requestHandlerImpl (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/router-server.js:496:13)\n    at async Server.requestListener (/Users/karrui/Projects/confetti/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_babel-plugin-react-compile_045f1fd3954167ff84e35f4f269befe3/node_modules/next/dist/server/lib/start-server.js:226:13)",
          "path": "me.get",
          "zodError": null
        }
      }
    }
  },

Activity

  1. added 3 commits that reference this issue on Feb 14, 2026
    998be34
    59e2c83
    ddf2771
  2. idirdev commented on Mar 11, 2026

    @idirdev

    Yeah this is actually a real concern. When someone sends /api/trpc/,,,,,,,,,, with hundreds of commas, each comma creates an empty string procedure name. These empty-name procedures never match any router path so they skip createContext entirely and go straight to error handling. With enough commas you can tie up the connection for a while, basically a slow resource exhaustion thing.

    The workaround of checking opts.info.calls.length in the context factory wont help here because createContext never even runs for invalid procedure names.

    Easiest fix at the app level is catching it before tRPC sees it:

    app.use("/api/trpc", (req, res, next) => {
      const procedureCount = (req.path.match(/,/g) || []).length + 1;
      if (procedureCount > 20) {
        return res.status(400).json({ error: "Too many procedures in batch" });
      }
      next();
    });

    Or at the nginx level if you prefer:

    location /api/trpc/ {
      if ($uri ~ "^[^,]*(?:,[^,]*){20,}") {
        return 400;
      }
      proxy_pass http://localhost:3000;
    }

    On the tRPC side the proper fix would be to validate and cap the number of procedure paths right after splitting the URL by commas, before createContext and before any procedure resolution happens.

  3. Nick-Lucas commented on Mar 11, 2026

    @Nick-Lucas
    Contributor

    If someone would be willing to double-check the PR I opened which does exactly that, then we can get it merged and released, other tRPC maintainers have been quite busy of late so it's fallen by the wayside: #7191

  4. github-actions commented on Mar 24, 2026

    @github-actions
    Contributor

    This issue has been locked because we are very unlikely to see comments on closed issues. If you are running into a similar issue, please create a new issue. Thank you.

  5. locked as resolved and limited conversation to collaborators on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions