{"record":{"id":"a42357d5a1f8637b","repo":"facebook/react","slug":"taintuniquevalue-cannot-taint-objects-or-functions","errorCode":null,"errorMessage":"taintUniqueValue cannot taint objects or functions. Try taintObjectReference instead.","messagePattern":"taintUniqueValue cannot taint objects or functions\\. Try taintObjectReference instead\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react/src/ReactTaint.js","lineNumber":93,"sourceCode":"  let entryValue: string | bigint;\n  if (typeof value === 'string' || typeof value === 'bigint') {\n    // Use as is.\n    entryValue = value;\n  } else if (\n    value instanceof TypedArrayConstructor ||\n    value instanceof DataView\n  ) {\n    // For now, we just convert binary data to a string so that we can just use the native\n    // hashing in the Map implementation. It doesn't really matter what form the string\n    // take as long as it's the same when we look it up.\n    // We're not too worried about collisions since this should be a high entropy value.\n    TaintRegistryByteLengths.add(value.byteLength);\n    entryValue = binaryToComparableString(value);\n  } else {\n    // $FlowFixMe[invalid-compare]\n    const kind = value === null ? 'null' : typeof value;\n    if (kind === 'object' || kind === 'function') {\n      throw new Error(\n        'taintUniqueValue cannot taint objects or functions. Try taintObjectReference instead.',\n      );\n    }\n    throw new Error(\n      'Cannot taint a ' +\n        kind +\n        ' because the value is too general and not unique enough to block globally.',\n    );\n  }\n  const existingEntry = TaintRegistryValues.get(entryValue);\n  if (existingEntry === undefined) {\n    TaintRegistryValues.set(entryValue, {\n      message,\n      count: 1,\n    });\n  } else {\n    existingEntry.count++;\n  }","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react/src/ReactTaint.js#L75-L111","documentation":"taintUniqueValue registers a specific high-entropy value (string, bigint, or binary view) in a global registry keyed by the value itself. Objects and functions are reference-unique but not value-unique, so they cannot be looked up this way; React throws and points you to taintObjectReference, which uses a WeakMap keyed by identity.","triggerScenarios":"Calling taintUniqueValue(message, lifetime, someObject) or taintUniqueValue(message, lifetime, someFunction) as the value argument.","commonSituations":"Trying to block accidental serialization of a user object or class instance; assuming one taint API covers all types when hardening a Server Components app.","solutions":["Use taintObjectReference(message, obj) for objects and functions","If the sensitive part is a property of the object, extract it and taint that unique string/binary value with taintUniqueValue","Review the taint API split: unique values -> taintUniqueValue, references -> taintObjectReference"],"exampleFix":"// before\ntaintUniqueValue(msg, lifetime, userObject); // object value -> throws\n\n// after\ntaintObjectReference(msg, userObject);\n// and/or for the sensitive field:\ntaintUniqueValue(msg, lifetime, userObject.apiKey);","handlingStrategy":"type-guard","validationCode":"// Route to the correct taint API by value type\nfunction taintAny(message: string, lifetime: object, value: unknown) {\n  if (value != null && (typeof value === 'object' || typeof value === 'function')) {\n    taintObjectReference(message, value);\n  } else {\n    taintUniqueValue(message, lifetime, value as string | bigint | $ArrayBufferView);\n  }\n}","typeGuard":"const isTaintableObject = (v: unknown): v is object | Function =>\n  v != null && (typeof v === 'object' || typeof v === 'function');","tryCatchPattern":null,"preventionTips":["Use one shared helper that picks taintObjectReference vs taintUniqueValue by typeof","Remember: identity-based secrets (objects/functions) go to taintObjectReference, always"],"tags":["security","taint-apis","taintuniquevalue","taintobjectreference","wrong-api"],"backgroundTag":"taint-api-misuse","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}