{"record":{"id":"4384515f6bbb253d","repo":"sveltejs/kit","slug":"address-header-was-specified-with-env-prefix-add","errorCode":null,"errorMessage":"Address header was specified with ${env_prefix}ADDRESS_HEADER=${address_header} but is absent from request","messagePattern":"Address header was specified with (.+?)ADDRESS_HEADER=(.+?) but is absent from request","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-bun/src/handler.js","lineNumber":110,"sourceCode":"\n\t// canonicalized so the caller's comparison with url.origin matches (case, default ports)\n\treturn new URL(`${protocol}://${host}${port ? `:${port}` : ''}`).origin;\n}\n\n/**\n * @param {Request} request\n * @param {BunServer<undefined>} bun_server\n * @returns {string}\n */\nfunction get_client_address(request, bun_server) {\n\tif (!address_header) {\n\t\t// requestIP() is null over unix sockets; undefined matches adapter-node\n\t\treturn /** @type {string} */ (bun_server.requestIP(request)?.address);\n\t}\n\n\tconst value = request.headers.get(address_header);\n\tif (value === null) {\n\t\tthrow new Error(\n\t\t\t`Address header was specified with ${env_prefix}ADDRESS_HEADER=${address_header} but is absent from request`\n\t\t);\n\t}\n\tif (address_header !== 'x-forwarded-for') return value;\n\n\tconst addresses = value.split(',');\n\tif (xff_depth > addresses.length) {\n\t\tthrow new Error(\n\t\t\t`${env_prefix}XFF_DEPTH is ${xff_depth}, but only found ${addresses.length} addresses`\n\t\t);\n\t}\n\treturn addresses[addresses.length - xff_depth].trim();\n}\n","sourceCodeStart":92,"sourceCodeEnd":124,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/adapter-bun/src/handler.js#L92-L124","documentation":"When ADDRESS_HEADER is set, get_client_address first tries Bun's requestIP(); if that returns null (e.g. unix sockets), it falls back to reading the configured header. If that header is missing from the request the adapter throws rather than silently returning undefined. This means the deployment is configured to trust a header that the proxy did not send.","triggerScenarios":"env has ADDRESS_HEADER=x-forwarded-for (or a custom name) but the request lacks that header — direct connections that bypass the proxy, or a proxy that doesn't set the header; requestIP() null over unix sockets plus missing header.","commonSituations":"Running Bun on a unix socket behind a proxy that strips X-Forwarded-For; mis-typed header name in ADDRESS_HEADER; local testing against a deployment-configured adapter.","solutions":["Configure your proxy to always set the address header, e.g. nginx: `proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;`.","Verify the ADDRESS_HEADER value matches the exact header name your proxy sends (lowercase).","Unset ADDRESS_HEADER so the adapter uses Bun's requestIP() when you are not behind a proxy."],"exampleFix":"// nginx before\nproxy_set_header Host $host; // X-Forwarded-For never set\n// after\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;","handlingStrategy":"try-catch","validationCode":"if (process.env.ADDRESS_HEADER && !req.headers.has(process.env.ADDRESS_HEADER)) {\n  console.warn(`${process.env.ADDRESS_HEADER} missing; client IP will fail`);\n}","typeGuard":null,"tryCatchPattern":"let ip;\ntry {\n  ip = getClientAddress(event);\n} catch (err) {\n  if (/Address header .* absent/.test(err.message)) {\n    ip = '127.0.0.1'; // or log and continue with a fallback\n  } else throw err;\n}","preventionTips":["Have the proxy always set the address header (e.g. X-Forwarded-For).","Only set ADDRESS_HEADER when you are actually behind a proxy.","Note unix sockets make requestIP() null — the header becomes mandatory."],"tags":["http-headers","proxy","adapter-bun","client-ip"],"backgroundTag":"missing-address-header","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}