Skip to content

fix(react-router): use own-property lookups in getDocumentHeadersImpl - #15810

Open
ragib-mrb wants to merge 1 commit into
remix-run:mainfrom
ragib-mrb:fix/document-headers-own-property-checks
Open

ragib-mrb wants to merge 1 commit into
remix-run:mainfrom
ragib-mrb:fix/document-headers-own-property-checks

Conversation

@ragib-mrb

Copy link
Copy Markdown
Contributor

Summary

In packages/react-router/lib/server-runtime/headers.ts, getDocumentHeadersImpl() performs direct property lookups and calls .hasOwnProperty() directly on context maps (errors, actionData, loaderData, actionHeaders, loaderHeaders):

  1. Calling actionData.hasOwnProperty(id) or loaderData.hasOwnProperty(id) throws TypeError: ...hasOwnProperty is not a function when actionData/loaderData is a null-prototype object (Object.create(null)) or contains a route with id "hasOwnProperty", and throws if loaderData is nullish.
  2. Direct lookups like context.errors[id], context.loaderHeaders[id], and context.actionHeaders[id] match inherited Object.prototype properties (such as a route id "toString"), falsely triggering error-boundary slicing or passing Object.prototype.toString to prependCookies() (which then crashes with TypeError: parentHeaders.get is not a function).

Fix

  • Use Object.prototype.hasOwnProperty.call(...) for errors, actionData, loaderData, actionHeaders, and loaderHeaders lookups in getDocumentHeadersImpl() (and guard nullish loaderData).
  • Add a regression test in packages/react-router/__tests__/server-runtime/headers-test.ts.

Testing

  • NODE_OPTIONS="--experimental-vm-modules" jest packages/react-router/__tests__/server-runtime/headers-test.ts (1 passed)
  • tsc --noEmit -p packages/react-router/tsconfig.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant