sveltejs/kit · error · Error
Could not determine host. The request must have a value prov
Error message
Could not determine host. The request must have a value provided by the ${header_names} What it means
adapter-node must construct an absolute origin for each request, which requires a host from the configured HOST_HEADER or the standard 'host' header. If neither is present the origin cannot be computed and the request fails. This guards against routing/URL generation breaking silently.
Source
Thrown at packages/adapter-node/src/handler.js:260
*/
function get_origin(headers) {
const protocol = decodeURIComponent(
normalise_header(protocol_header, headers[protocol_header]) || 'https'
);
// this helps us avoid host injections through the protocol header
if (protocol.includes(':')) {
throw new Error(
`The ${protocol_header} header specified ${protocol} which is an invalid because it includes \`:\`. It should only contain the protocol scheme (e.g. \`https\`)`
);
}
const host =
normalise_header(host_header, headers[host_header]) ||
normalise_header('host', headers['host']);
if (!host) {
const header_names = host_header ? `${host_header} or host headers` : 'host header';
throw new Error(
`Could not determine host. The request must have a value provided by the ${header_names}`
);
}
const port = normalise_header(port_header, headers[port_header]);
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)`
);
}
return port ? `${protocol}://${host}:${port}` : `${protocol}://${host}`;
}
export const handler = sequence(
/** @type {(RequestHandler | Middleware)[]} */
([serve(path.join(dir, 'client'), true), serve_prerendered(), ssr].filter(Boolean))
);View on GitHub (pinned to 03f1687fe6)
Solutions
- Ensure your proxy always sets/forwards a Host header to the Node server
- Set PROTOCOL_HEADER/HOST_HEADER (HOST_HEADER env) to a header your infrastructure reliably provides (e.g. x-forwarded-host)
- Fix the client sending Host-less requests; per RFC 7230 HTTP/1.1 clients must send Host
Example fix
// nginx: before proxy_pass http://node; # host header dropped // after proxy_set_header host $host; proxy_pass http://node;
Defensive patterns
Strategy: validation
Validate before calling
if (!req.headers.host && !(process.env.HOST_HEADER && req.headers[process.env.HOST_HEADER.toLowerCase()])) {
throw new Error('Request is missing a Host header; cannot determine origin');
} Try / catch
try {
const res = await server.respond(request);
} catch (err) {
if (String(err.message).includes('Could not determine host')) {
console.error('Ensure proxy forwards Host or set HOST_HEADER to a reliable header');
} else {
throw err;
}
} Prevention
- Always forward Host through the proxy chain (proxy_set_header host $host)
- Set HOST_HEADER env to x-forwarded-host when proxies rewrite Host
- Reject Host-less requests at the load balancer
When it happens
Trigger: A request without a Host header arrives (HTTP/1.1 requires one; possible with hand-crafted or broken clients), while no alternative HOST_HEADER provides a value.
Common situations: Extremely low-level HTTP clients or health checks omitting Host, proxies stripping the Host header, or HTTP/2 requests relying on a :authority mapping your proxy doesn't forward as a host header.
Related errors
- ${env_prefix + 'XFF_DEPTH'} must be a positive integer
- Address header was specified with ${env_prefix + 'ADDRESS_HE
- ${env_prefix + 'XFF_DEPTH'} is ${xff_depth}, but only found
- The ${port_header} header specified ${port} which is an inva
- Multiple values provided for ${name} header where only one e
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/9eb3a1c7fc49864a.
Report an issue: GitHub.