{"record":{"id":"21a48b6a1787b2ba","repo":"diegosouzapw/OmniRoute","slug":"pii-blocked-response-due-to-sanitization-failure","errorCode":null,"errorMessage":"[PII] Blocked response due to sanitization failure","messagePattern":"\\[PII\\] Blocked response due to sanitization failure","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/lib/piiSanitizer.ts","lineNumber":341,"sourceCode":"      }\n      return obj;\n    };\n\n    return deepSanitize(response);\n  } catch (err: any) {\n    if (err?.message?.startsWith(\"[PII] Blocked response\")) {\n      throw err;\n    }\n    // Fail secure — try raw string sanitization instead of failing open\n    try {\n      const serialized = JSON.stringify(response);\n      const { text: sanitized } = sanitizePII(serialized);\n      return JSON.parse(sanitized);\n    } catch (fallbackErr) {\n      // Suppress err.message — never surface upstream error detail to the client\n      // (Hard Rule #12). The underlying error is available in server logs.\n      console.warn(\"[PII] Sanitization fallback failed:\", err?.message);\n      throw new Error(\"[PII] Blocked response due to sanitization failure\");\n    }\n  }\n}\n\n// ── Checksum Validation Helpers ──\n\nfunction isValidLuhn(digits: string): boolean {\n  let sum = 0;\n  let shouldDouble = false;\n  for (let i = digits.length - 1; i >= 0; i--) {\n    let digit = parseInt(digits[i], 10);\n    if (shouldDouble) {\n      digit *= 2;\n      if (digit > 9) digit -= 9;\n    }\n    sum += digit;\n    shouldDouble = !shouldDouble;\n  }","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/piiSanitizer.ts#L323-L359","documentation":"sanitizePIIResponse fail-secure path: normal deep sanitization threw an unexpected error, and the JSON.stringify fallback also failed. Rather than returning unsanitized data (fail-open), the function throws a generic '[PII] Blocked response due to sanitization failure'. The underlying error stays in server logs only.","triggerScenarios":"Thrown at src/lib/piiSanitizer.ts:341 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect server logs for the fallbackErr to find why both passes failed","Check the response payload for structures that break JSON.stringify (cycles, BigInt)","Retry the request — transient failures may not recur","Temporarily disable PII response sanitization if the payload is trusted"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}