facebook/react · error · Error
Only objects or functions can be passed to taintObjectRefere
Error message
Only objects or functions can be passed to taintObjectReference.
What it means
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.
Source
Thrown at packages/react/src/ReactTaint.js:136
message: ?string,
object: Reference,
): void {
if (!enableTaint) {
throw new Error('Not implemented.');
}
// eslint-disable-next-line react-internal/safe-string-coercion
message = '' + (message || defaultMessage);
if (typeof object === 'string' || typeof object === 'bigint') {
throw new Error(
'Only objects or functions can be passed to taintObjectReference. Try taintUniqueValue instead.',
);
}
if (
// $FlowFixMe[invalid-compare]
object === null ||
(typeof object !== 'object' && typeof object !== 'function')
) {
throw new Error(
'Only objects or functions can be passed to taintObjectReference.',
);
}
TaintRegistryObjects.set(object, message);
}
View on GitHub (pinned to eafeac097b)
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
Example fix
// before
const user = await findUser(id); // may be undefined
taintObjectReference(msg, user); // throws when undefined
// after
const user = await findUser(id);
if (user != null) {
taintObjectReference(msg, user);
} Defensive patterns
Strategy: type-guard
Validate before calling
// Validate before tainting a reference
if (object !== null && (typeof object === 'object' || typeof object === 'function')) {
taintObjectReference(message, object);
} else {
console.warn('taintObjectReference skipped non-object:', object);
} Type guard
const isObjectReference = (v: unknown): v is object | Function => v != null && (typeof v === 'object' || typeof v === 'function');
Prevention
- 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
When it happens
Trigger: Calling taintObjectReference(message, null), taintObjectReference(message, 0), or with a variable that is undefined (e.g. a lookup that returned nothing).
Common situations: 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.
Related errors
- taintUniqueValue cannot taint objects or functions. Try tain
- Cannot taint a ${kind} because the value is too general and
- Only objects or functions can be passed to taintObjectRefere
- To taint a value, a lifetime must be defined by passing an o
- Invalid tag: ${tag}
AI-assisted analysis of facebook/react@eafeac097b (2026-08-21).
Data as JSON: /api/errors/9e2c68a36b6ed7a3.
Report an issue: GitHub.