sveltejs/kit · error · Error
The ${port_header} header specified ${port} which is an inva
Error message
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) What it means
If PORT_HEADER is configured, its value must be a pure numeric port (e.g. 443), because it is appended to `protocol://host` to rebuild the origin. A non-numeric value like 'https,443' or '443/tcp' makes isNaN(+port) true and the adapter throws.
Source
Thrown at packages/adapter-bun/src/handler.js:88
(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
* @returns {string}
*/
function get_client_address(request, bun_server) {
if (!address_header) {
// requestIP() is null over unix sockets; undefined matches adapter-node
return /** @type {string} */ (bun_server.requestIP(request)?.address);
}View on GitHub (pinned to 03f1687fe6)
Solutions
- Configure the outermost/innermost proxy to send a single numeric port, e.g. nginx: `proxy_set_header X-Forwarded-Port $server_port;`.
- Strip the header at the trusted edge so only one value survives: `proxy_set_header X-Forwarded-Port $http_x_forwarded_port;` replacing multi-value input.
- Remove the PORT_HEADER config if you don't need a custom port header.
Example fix
// before proxy_set_header X-Forwarded-Port "$http_host"; // after proxy_set_header X-Forwarded-Port $server_port;
Defensive patterns
Strategy: validation
Validate before calling
const port = req.headers.get('x-forwarded-port');
if (port && isNaN(Number(port.trim()))) throw new Error(`Non-numeric forwarded port: ${port}`); Try / catch
try {
origin = getOrigin(req);
} catch (err) {
if (/is an invalid port/.test(err.message)) {
console.error('Proxy must send a single numeric port in the port header');
}
throw err;
} Prevention
- Use $server_port (nginx) or equivalent for the forwarded port header.
- Overwrite rather than append multi-hop port values at the trusted edge.
- Don't set PORT_HEADER unless you need origin-port fidelity.
When it happens
Trigger: A proxy sends a composite value in the port header such as `x-forwarded-port: 8443,8443` (multiple hops) or `host:443` including the host part.
Common situations: Multi-layer proxies appending to X-Forwarded-Port; misconfigured proxy forwarding the full host:port pair into the port header.
Related errors
- The ${protocol_header} header specified ${protocol} which is
- Could not determine host from the ${host_header ? `${host_he
- Address header was specified with ${env_prefix}ADDRESS_HEADE
- ${env_prefix}XFF_DEPTH is ${xff_depth}, but only found ${add
- Cannot build with ${JSON.stringify(file)} because Bun treats
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/1d789f783287f542.
Report an issue: GitHub.