{"record":{"id":"47cae916cdc38edd","repo":"sveltejs/kit","slug":"could-not-determine-host-from-the-host-header","errorCode":null,"errorMessage":"Could not determine host from the ${host_header ? `${host_header} or ` : ''}host header","messagePattern":"Could not determine host from the (.+?) or ` : ''\\}host header","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-bun/src/handler.js","lineNumber":81,"sourceCode":" * @param {Request} request\n * @param {URL} url\n * @returns {string}\n */\nfunction get_origin(request, url) {\n\t// assume TLS terminates upstream, like adapter-node; an http origin would fail CSRF checks\n\tconst protocol = decodeURIComponent(\n\t\t(protocol_header && request.headers.get(protocol_header)) || 'https'\n\t);\n\tif (!/^https?$/i.test(protocol)) {\n\t\tthrow new Error(\n\t\t\t`The ${protocol_header} header specified ${protocol} which is an invalid protocol scheme. It should only contain the protocol scheme (e.g. \\`https\\`)`\n\t\t);\n\t}\n\n\tconst host =\n\t\t(host_header && request.headers.get(host_header)) || (request.headers.get('host') ?? url.host);\n\tif (!host) {\n\t\tthrow new Error(\n\t\t\t`Could not determine host from the ${host_header ? `${host_header} or ` : ''}host header`\n\t\t);\n\t}\n\n\tconst port = port_header ? request.headers.get(port_header) : null;\n\tif (port && isNaN(+port)) {\n\t\tthrow new Error(\n\t\t\t`The ${port_header} header specified ${port} which is an invalid port because it is not a number. The value should only contain the port number (e.g. 443)`\n\t\t);\n\t}\n\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","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/adapter-bun/src/handler.js#L63-L99","documentation":"adapter-bun builds the origin URL from the configured HOST_HEADER (or the standard host header, falling back to the URL host). If none of these yield a non-empty host it throws, because a request without a usable host cannot have its origin determined (breaking CSRF checks and absolute URL generation).","triggerScenarios":"A request arrives with no Host header and no configured host_header match — e.g. HTTP/1.0 clients, custom header names set via HOST_HEADER that the proxy never sends, or stripped headers at a load balancer.","commonSituations":"HOST_HEADER set to a custom name (e.g. 'x-original-host') but the proxy doesn't forward it; health-check or monitoring probes that omit the Host header.","solutions":["Ensure your proxy forwards the configured host header (e.g. nginx: `proxy_set_header Host $host;`).","Correct the HOST_HEADER env var to a header your proxy actually sends, or remove it to use the standard Host header.","Update health-check/probe configurations to include a Host header."],"exampleFix":"// env before\nHOST_HEADER=x-orig-host   # proxy never sends it\n// env after\nHOST_HEADER=x-forwarded-host  # and proxy sets proxy_set_header X-Forwarded-Host $host;","handlingStrategy":"validation","validationCode":"const host = req.headers.get('host');\nif (!host) throw new Error('Request has no Host header; configure proxy to forward it');","typeGuard":null,"tryCatchPattern":"try {\n  origin = getOrigin(req);\n} catch (err) {\n  if (/Could not determine host/.test(err.message)) {\n    console.error('Ensure Host (or your HOST_HEADER) is forwarded by the proxy');\n  }\n  throw err;\n}","preventionTips":["Always forward Host (or X-Forwarded-Host) at every proxy hop.","Match HOST_HEADER exactly to a header your proxy actually emits.","Include a Host header in health-check probes."],"tags":["http-headers","proxy","adapter-bun"],"backgroundTag":"missing-host-header","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}