sveltejs/kit · error · Error

Could not determine host from the ${host_header ? `${host_he

Error message

Could not determine host from the ${host_header ? `${host_header} or ` : ''}host header

What it means

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).

Source

Thrown at packages/adapter-bun/src/handler.js:81

 * @param {Request} request
 * @param {URL} url
 * @returns {string}
 */
function get_origin(request, url) {
	// assume TLS terminates upstream, like adapter-node; an http origin would fail CSRF checks
	const protocol = decodeURIComponent(
		(protocol_header && request.headers.get(protocol_header)) || 'https'
	);
	if (!/^https?$/i.test(protocol)) {
		throw new Error(
			`The ${protocol_header} header specified ${protocol} which is an invalid protocol scheme. It should only contain the protocol scheme (e.g. \`https\`)`
		);
	}

	const host =
		(host_header && request.headers.get(host_header)) || (request.headers.get('host') ?? url.host);
	if (!host) {
		throw new Error(
			`Could not determine host from the ${host_header ? `${host_header} or ` : ''}host header`
		);
	}

	const port = port_header ? request.headers.get(port_header) : null;
	if (port && isNaN(+port)) {
		throw new Error(
			`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)`
		);
	}

	// canonicalized so the caller's comparison with url.origin matches (case, default ports)
	return new URL(`${protocol}://${host}${port ? `:${port}` : ''}`).origin;
}

/**
 * @param {Request} request
 * @param {BunServer<undefined>} bun_server

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Ensure your proxy forwards the configured host header (e.g. nginx: `proxy_set_header Host $host;`).
  2. Correct the HOST_HEADER env var to a header your proxy actually sends, or remove it to use the standard Host header.
  3. Update health-check/probe configurations to include a Host header.

Example fix

// env before
HOST_HEADER=x-orig-host   # proxy never sends it
// env after
HOST_HEADER=x-forwarded-host  # and proxy sets proxy_set_header X-Forwarded-Host $host;
Defensive patterns

Strategy: validation

Validate before calling

const host = req.headers.get('host');
if (!host) throw new Error('Request has no Host header; configure proxy to forward it');

Try / catch

try {
  origin = getOrigin(req);
} catch (err) {
  if (/Could not determine host/.test(err.message)) {
    console.error('Ensure Host (or your HOST_HEADER) is forwarded by the proxy');
  }
  throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/47cae916cdc38edd. Report an issue: GitHub.