{"record":{"id":"fee83faca0595439","repo":"paperclipai/paperclip","slug":"trust-proxy-invalid-integer-value-json-stringif","errorCode":null,"errorMessage":"TRUST_PROXY: invalid integer value ${JSON.stringify(raw)} — use a positive integer with no leading zeros or whitespace","messagePattern":"TRUST_PROXY: invalid integer value (.+?) — use a positive integer with no leading zeros or whitespace","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/src/middleware/trust-proxy.ts","lineNumber":88,"sourceCode":" * Throws `Error` with an explanatory message if the value is malformed.\n */\nexport function parseTrustProxyEnv(raw: string | undefined): TrustProxyValue | undefined {\n  if (raw === undefined) return undefined;\n  // We intentionally trim only the *outer* value — tokens inside the\n  // comma list are trimmed individually below. Leading/trailing whitespace\n  // around the whole value (e.g. \" 2 \") is accepted because trim() reduces\n  // it to \"2\" before STRICT_POS_INT_RE is applied; only *internal*\n  // whitespace (e.g. \"1 2\") falls through to the subnet path and errors as\n  // an unrecognised token.\n  const value = raw.trim();\n  if (value === \"\" || value === \"false\" || value === \"0\") return undefined;\n  if (value === \"true\") return true;\n  if (STRICT_POS_INT_RE.test(value)) return Number(value);\n  // Reject the \"01\" / \" 2\" forms explicitly — if the value is *purely*\n  // digits-or-whitespace but didn't match STRICT_POS_INT_RE, it's a\n  // typo, not a subnet list.\n  if (/^\\s*\\d+\\s*$/.test(raw)) {\n    throw new Error(\n      `TRUST_PROXY: invalid integer value ${JSON.stringify(raw)} — use a positive integer with no leading zeros or whitespace`,\n    );\n  }\n  const tokens = value\n    .split(\",\")\n    .map((t) => t.trim())\n    .filter((t) => t.length > 0);\n  if (tokens.length === 0) return undefined;\n  for (const token of tokens) {\n    if (!isValidSubnetToken(token)) {\n      throw new Error(\n        `TRUST_PROXY: unrecognized token ${JSON.stringify(token)} — expected one of {loopback, linklocal, uniquelocal} or a CIDR like 10.0.0.0/8 or fd00::/8`,\n      );\n    }\n  }\n  return tokens;\n}\n","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/paperclipai/paperclip/blob/120ae5428fa29bee300bcf806491cd4d965fbb7c/server/src/middleware/trust-proxy.ts#L70-L106","documentation":"parseTrustProxyEnv guard: the TRUST_PROXY value is purely digits-and-whitespace (e.g. \"01\" or \" 2\") but did not match the strict positive-integer pattern. Such values are treated as typo'd hop counts, not subnet lists, and rejected with guidance instead of being misinterpreted.","triggerScenarios":"Thrown at server/src/middleware/trust-proxy.ts:88 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set TRUST_PROXY to a positive integer with no leading zeros or whitespace, e.g. TRUST_PROXY=1."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"120ae5428fa29bee300bcf806491cd4d965fbb7c","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}