{"record":{"id":"25c3b96f12a6cefa","repo":"abhigyanpatwari/GitNexus","slug":"gitnexus-serve-ignoring-trust-proxy-env-val","errorCode":null,"errorMessage":"[gitnexus serve] Ignoring ${TRUST_PROXY_ENV}=${value} (${reason}); falling back to '${DEFAULT_TRUST_PROXY}'.","messagePattern":"\\[gitnexus serve\\] Ignoring (.+?)=(.+?) \\((.+?)\\); falling back to '(.+?)'\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"gitnexus/src/server/middleware.ts","lineNumber":392,"sourceCode":" *   accepts traffic on every interface, a load balancer included.\n */\nexport function warnIfRateLimitKeysCollapse(boundHost?: string): void {\n  if (process.env[TRUST_PROXY_ENV]?.trim()) return;\n  if (!boundHost) return;\n  // normalizeBoundHost returns undefined for a wildcard or unparseable host,\n  // neither of which is loopback — so both warn.\n  if (isLoopbackHostname(normalizeBoundHost(boundHost))) return;\n  logger.warn(\n    { host: boundHost, trustProxy: DEFAULT_TRUST_PROXY },\n    `[gitnexus serve] Bound to ${boundHost} with ${TRUST_PROXY_ENV} unset, so 'trust proxy' is ` +\n      `'${DEFAULT_TRUST_PROXY}'. A load balancer outside those ranges is not trusted, so req.ip ` +\n      `is the balancer on every request and the per-IP rate limit becomes one shared limit across ` +\n      `all callers. Set ${TRUST_PROXY_ENV} to the number of proxies you control.`,\n  );\n}\n\nfunction rejectTrustProxy(value: string, reason: string): string {\n  logger.warn(\n    { [TRUST_PROXY_ENV]: value },\n    `[gitnexus serve] Ignoring ${TRUST_PROXY_ENV}=${value} (${reason}); falling back to ` +\n      `'${DEFAULT_TRUST_PROXY}'.`,\n  );\n  return DEFAULT_TRUST_PROXY;\n}\n","sourceCodeStart":374,"sourceCodeEnd":399,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/aac7515d2a8c50a1f8f923c6fb77218b333560d6/gitnexus/src/server/middleware.ts#L374-L399","documentation":"rejectTrustProxy fires when GITNEXUS_TRUST_PROXY is set to a value that fails resolveTrustProxy's validation (the parenthesized reason in the message says why). The value is ignored and trust falls back to DEFAULT_TRUST_PROXY ('loopback, linklocal, uniquelocal') with this warning. A separate earlier warning covers the unset case; this one covers set-but-invalid.","triggerScenarios":"Starting serve with GITNEXUS_TRUST_PROXY set to something that is not a valid proxy-hop count — 'true', 'yes', '1.5', 'one proxy' — so the value is rejected at validation and the default is used.","commonSituations":"Assuming boolean env-var semantics; copying an nginx-style config value; trailing units or whitespace. The server keeps running, but proxy headers are not honored and rate-limit keys collapse exactly as in the unset case.","solutions":["Set it to an integer hop count: GITNEXUS_TRUST_PROXY=1 for one trusted proxy, 2 behind two","Re-check startup logs after changing it: silence of both trust-proxy warnings means it parsed","Remember an invalid value falls back to the safe default — it never widens trust"],"exampleFix":"# before\nexport GITNEXUS_TRUST_PROXY=true      # rejected, falls back to default\n\n# after\nexport GITNEXUS_TRUST_PROXY=1         # one trusted proxy hop","handlingStrategy":"validation","validationCode":"const v = process.env.GITNEXUS_TRUST_PROXY?.trim();\nif (v !== undefined && !/^\\d+$/.test(v)) {\n  throw new Error(`GITNEXUS_TRUST_PROXY=${v} will be rejected; use an integer hop count`);\n}","typeGuard":"function isValidTrustProxy(value: string): boolean {\n  return /^\\d+$/.test(value.trim()) && Number(value) > 0;\n}","tryCatchPattern":null,"preventionTips":["The variable is a hop count, not a boolean — 'true' is rejected","Re-check startup logs after setting it to confirm it parsed","Invalid values fall back to the safe default; they never widen trust"],"tags":["proxy","env-var","validation","configuration","rate-limit"],"backgroundTag":"trust-proxy-misconfiguration","analyzedSha":"aac7515d2a8c50a1f8f923c6fb77218b333560d6","analyzedAt":"2026-08-20T23:29:22.980Z","contentChangedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}