Start: server function ids naming Object.prototype members (constructor, __proto__) hit a TypeError in the resolver

Abierto Apto para principiantes
#8,974 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
85/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
node.js, typescript, vite
Área
backend, tooling

Línea de trabajo

Empieza en packages/start-plugin-core/src/start-compiler/server-fn-resolver-module.ts en la búsqueda en el manifiesto dentro de getServerFnById; el issue indica la corrección exacta (Object.hasOwn). Luego abre packages/start-plugin-core/src/vite/start-compiler-plugin/plugin.ts y aplica la misma comprobación de propiedad propia a ambas guardas serverFnsById[fnId]. Ejecuta las pruebas del resolver y del compilador de start-plugin-core. Está terminado cuando los ids como constructor, __proto__ y toString lanzan el mismo error 'Server function info not found for' que un id desconocido, tanto en el resolver generado como en el servidor de desarrollo.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Which project does this relate to?

Start

Describe the bug

A server function request whose id names an Object.prototype member (constructor, __proto__, toString, hasOwnProperty, …) fails with a TypeError inside the resolver instead of the "not found" error an unknown id gets, so an app that answers unknown ids with a 404 (by catching Server function info not found for) still answers these with a 500.

The generated resolver looks the id up with a plain property read (packages/start-plugin-core/src/start-compiler/server-fn-resolver-module.ts):

const manifest = { /* ids */ }

export async function getServerFnById(id, access) {
  const serverFnInfo = manifest[id]          // manifest['constructor'] === Object
  if (!serverFnInfo) {
    throw new Error('Server function info not found for ' + id)
  }
  // with includeClientReferencedCheck false (the Vite plugin when ssr is the provider)
  const fnModule = serverFnInfo.module ?? (await serverFnInfo.importer())
  // TypeError: serverFnInfo.importer is not a function

manifest is an object literal, so inherited members pass the !serverFnInfo check and the resolver throws a TypeError instead of its own "not found" error. Any client can send such an id, so stray or probing traffic turns into 500s and server errors.

The dev server has the same lookup in packages/start-plugin-core/src/vite/start-compiler-plugin/plugin.ts (if (fnId && serverFnsById[fnId]) and if (serverFnsById[fnId])), so a prototype id passes the "Invalid server function ID" guard there and fails later.

Complete minimal reproducer

No separate repository: it reproduces in any Start app built with the Vite plugin and default settings, with the request below. We confirmed it by importing the module generateServerFnResolverModule emits with includeClientReferencedCheck: false and calling getServerFnById('constructor'), which throws TypeError: serverFnInfo.importer is not a function where an unknown id throws Server function info not found for ….

Steps to Reproduce the Bug
  1. Build and start any Start app (vite build, then run the server output).
  2. curl -i -X POST -H 'Sec-Fetch-Site: same-origin' http://localhost:3000/_serverFn/constructor
  3. Compare with curl -i -X POST -H 'Sec-Fetch-Site: same-origin' http://localhost:3000/_serverFn/no-such-id.

The server log for step 2 shows TypeError: serverFnInfo.importer is not a function; step 3 shows Server function info not found for no-such-id. __proto__ and toString behave like step 2, for GET and POST. In dev, the prototype id passes the Invalid server function ID guard and fails later with a different error.

Expected behavior

Every id the manifest does not own resolves like an unknown id. An own-property check fixes all four lookups; we run this as a local patch:

-  const serverFnInfo = manifest[id]
+  const serverFnInfo = Object.hasOwn(manifest, id) ? manifest[id] : undefined
-          if (fnId && serverFnsById[fnId]) {
+          if (fnId && Object.hasOwn(serverFnsById, fnId)) {

(and the same for the second serverFnsById[fnId] check in the dev-server plugin). The rsbuild path uses the same generator, so it is covered by the first change. A Object.create(null) manifest would work too.

Platform
  • @tanstack/start-plugin-core 1.172.0 (also present on main today)
  • @tanstack/react-start 1.169.7
  • Node 26.13.0, macOS and Linux
Additional context

With includeClientReferencedCheck: true the request fails earlier as "Server function not accessible from client", so only builds where that check is off (the Vite plugin when the ssr environment is the provider) reach the TypeError; the dev-server guard is affected either way.

Lenguaje dominante
TypeScript
Estrellas
15.3k
Forks
1.9k
Merge medio
1 d 5 h
PR fusionados (30 d)
46

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de TanStack/router

Todos los issues de TanStack/router

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.