Skip to main content
Menu
Advisories

Prototype pollution in normalizeQueryParams allows unauthenticated process-wide state changes (cross-user data exposure, DoS)

GHSA-8982-G8XM-3X5HPublished Updated GitHub

Description

Affected versions (verified): @mastra/server 1.62.0, 1.75.0 (current latest) and 1.76.0-alpha.6; @mastra/deployer 1.75.0 still calls normalizeQueryParams(request.queries()) in getParams and uses the same parseFormData. Earlier versions not checked.

Summary

normalizeQueryParams (@mastra/server, dist/server/server-adapter/index.js) groups bracket-notation query keys (parent[child]=value) into a plain object literal:

const bracketGroups = {};
// ...
if (!bracketGroups[parent]) bracketGroups[parent] = {};
bracketGroups[parent][child] = strValue;

For parent = "__proto__", bracketGroups["__proto__"] resolves to Object.prototype, so ?__proto__[foo]=bar sets Object.prototype.foo = "bar" for the whole Node process. For parent = "toString" (or hasOwnProperty, valueOf, …) it resolves to the shared built-in function, so ?toString[call]=x makes Object.prototype.toString.call a string until the process restarts.

@mastra/deployer's getParams calls normalizeQueryParams(request.queries()) for every registered route, after checkRouteAuth but regardless of the result for routes with requiresAuth: false. Framework-public routes such as GET /api/auth/me therefore allow this without credentials, and Mastra skips user server middleware on those routes, so an application cannot filter it.

Impact

  • Process-wide state change from a single unauthenticated request.
  • Zod object schemas read inherited properties, so a polluted key (for example include on GET /api/memory/threads/:threadId/messages) is parsed into the input of later, unrelated requests from other users.
  • ?toString[call]=x / ?hasOwnProperty[call]=x break any code path that uses Object.prototype.toString.call(...) or hasOwnProperty.call(...) (denial of service until restart).

Related, lower impact: parseFormData in @mastra/deployer (dist/server/index.js) assigns result[key] = … on a plain object, so a multipart field named __proto__ replaces the request body's prototype.

Reproduction

curl -s "http://localhost:4111/api/auth/me?__proto__%5Bpolluted%5D=yes" >/dev/null
# in the server process afterwards: ({}).polluted === "yes"

Suggested fix

Build both objects without a prototype (or use a Map), e.g.

const queryParams = Object.create(null);
const bracketGroups = Object.create(null);
// ...
if (!bracketGroups[parent]) bracketGroups[parent] = Object.create(null);

and skip __proto__ in parseFormData (or build result with Object.create(null)). Optionally reject keys with a __proto__, constructor or prototype segment outright.

We currently carry this as a local patch (bun patchedDependencies).

Reported by Sjoerd Tiemensma (TwoFeetUp). The reproduction above was run only against our own local instance; no third-party systems were tested. Happy to share our patch and regression tests.

Affected versions

References

GitHub · mastra-ai/mastra