{"record":{"id":"9e2c68a36b6ed7a3","repo":"facebook/react","slug":"only-objects-or-functions-can-be-passed-to-taintob-9e2c68","errorCode":null,"errorMessage":"Only objects or functions can be passed to taintObjectReference.","messagePattern":"Only objects or functions can be passed to taintObjectReference\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react/src/ReactTaint.js","lineNumber":136,"sourceCode":"  message: ?string,\n  object: Reference,\n): void {\n  if (!enableTaint) {\n    throw new Error('Not implemented.');\n  }\n  // eslint-disable-next-line react-internal/safe-string-coercion\n  message = '' + (message || defaultMessage);\n  if (typeof object === 'string' || typeof object === 'bigint') {\n    throw new Error(\n      'Only objects or functions can be passed to taintObjectReference. Try taintUniqueValue instead.',\n    );\n  }\n  if (\n    // $FlowFixMe[invalid-compare]\n    object === null ||\n    (typeof object !== 'object' && typeof object !== 'function')\n  ) {\n    throw new Error(\n      'Only objects or functions can be passed to taintObjectReference.',\n    );\n  }\n  TaintRegistryObjects.set(object, message);\n}\n","sourceCodeStart":118,"sourceCodeEnd":142,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react/src/ReactTaint.js#L118-L142","documentation":"taintObjectReference throws for anything that is not an object or function — including null, numbers, booleans, and undefined. Unlike the string/bigint case, no alternative API is suggested because no taint registry can track primitives with identity semantics; this is a pure argument-validation error.","triggerScenarios":"Calling taintObjectReference(message, null), taintObjectReference(message, 0), or with a variable that is undefined (e.g. a lookup that returned nothing).","commonSituations":"Passing a possibly-null database row or cache entry without checking it first; argument-order mistakes putting the message or lifetime into the object slot.","solutions":["Ensure the second argument is an actual object or function before calling (check with typeof)","Fix upstream null/undefined: verify the row/session actually loaded before tainting it","Use taintUniqueValue instead if the secret is a string or bigint"],"exampleFix":"// before\nconst user = await findUser(id); // may be undefined\ntaintObjectReference(msg, user); // throws when undefined\n\n// after\nconst user = await findUser(id);\nif (user != null) {\n  taintObjectReference(msg, user);\n}","handlingStrategy":"type-guard","validationCode":"// Validate before tainting a reference\nif (object !== null && (typeof object === 'object' || typeof object === 'function')) {\n  taintObjectReference(message, object);\n} else {\n  console.warn('taintObjectReference skipped non-object:', object);\n}","typeGuard":"const isObjectReference = (v: unknown): v is object | Function =>\n  v != null && (typeof v === 'object' || typeof v === 'function');","tryCatchPattern":null,"preventionTips":["Check that the row/session/record actually loaded (non-null) before tainting it","Type the parameter as object | Function so primitives fail at compile time"],"tags":["security","taint-apis","taintobjectreference","null-argument","invalid-type"],"backgroundTag":"taint-api-misuse","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}