Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d2e2169
fix(kernel): honor a custom port over HTTPS on the kernel backend
cathleeny Nov 19, 2026
97d67cb
Kernel: embedded host port wins over explicit port; falsy port is def…
cathleeny Nov 19, 2026
a4c91da
Kernel: reject a host path, query or fragment when a port is set
cathleeny Nov 19, 2026
9b2e94d
Kernel: reject a host path only when the port is folded or follows th…
cathleeny Nov 19, 2026
468af3a
Kernel: pass a path host through unless a folded port applies
cathleeny Nov 19, 2026
23ffcf6
Merge main into fix/kernel-honor-https-port
cathleeny Nov 20, 2026
195a115
Merge main into fix/kernel-honor-https-port
cathleeny Nov 20, 2026
2fa5c5e
docs(kernel): correct the reason an explicit port 443 is not warned a…
cathleeny Nov 20, 2026
c8dc980
fix(kernel): keep userinfo out of port detection and messages
cathleeny Nov 23, 2026
f4eef33
fix(kernel): reject an empty host when a port is folded in
cathleeny Nov 23, 2026
110acaf
Merge main into fix/kernel-honor-https-port
cathleeny Nov 23, 2026
fbffc2f
fix(kernel): redact host userinfo up to the last @
cathleeny Nov 23, 2026
69855ec
fix(kernel): leave path hosts unparsed and warn on an HTTP 443 conflict
cathleeny Nov 23, 2026
3be0d05
Merge main into fix/kernel-honor-https-port
cathleeny Nov 23, 2026
2e9227d
refactor(kernel): let the kernel apply the port
cathleeny Nov 25, 2026
1962201
fix(kernel): always send an explicit port to the kernel
cathleeny Nov 25, 2026
09cb0e8
docs(kernel): say any explicit port is sent in KernelPortOptions
cathleeny Nov 25, 2026
bbc4d01
docs(kernel): fix the comment above base.port
cathleeny Nov 25, 2026
2ac73f9
Merge origin/main into fix/kernel-honor-https-port
cathleeny Nov 30, 2026
ed827f4
docs(changelog): shorten the port entry
cathleeny Nov 30, 2026
c5a0855
refactor(kernel): pass port to the kernel as is
cathleeny Nov 30, 2026
73a84a1
style(tests): apply prettier to the kernel connection-options test
cathleeny Nov 30, 2026
5fcc5b3
chore(kernel): pin KERNEL_REV to the merged kernel port change
cathleeny Nov 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Kernel backend: `port` is passed to the kernel as is, so a custom port works over HTTPS as on Thrift. IPv6 hosts need brackets, an invalid port or host fails with a `ParameterError`, and the published `@databricks/databricks-sql-kernel-*` native packages must be bumped to a release that includes databricks/databricks-sql-kernel#505, since older packages ignore `port`.
- Release completed Thrift CloudFetch body-reader listeners so idle connections do not retain downloaded result buffers.

## 3.1.0
Expand Down
18 changes: 9 additions & 9 deletions CONNECTION_PARAMETERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ backend (the default), the **SEA / Kernel** backend, or both.

## Connection identity and backend selection

| Option | Type | Thrift | Kernel | Default Value | Note |
| ----------------------- | --------- | :----: | :----: | ------------- | -------------------------------------------------------------------------------------- |
| `host` | `string` | ✅ | ✅ | — (required) | Required on both. |
| `path` | `string` | ✅ | ✅ | — (required) | Kernel also derives `x-databricks-org-id` from a `?o=<id>` query parameter. |
| `port` | `number` | ✅ | ⚠️ | `443` / — | Kernel uses it only with `https: false`; otherwise put a non-default port in `host`. |
| `https` | `boolean` | ✅ | ✅ | `true` | `false` selects plain HTTP; see [Plain HTTP transport](#plain-http-transport). |
| `userAgentEntry` | `string` | ✅ | ✅ | — | Folded into the connector `User-Agent` on both. |
| `useKernel` (internal) | `boolean` | — | — | `false` | Selects the backend: `false`/omitted → Thrift, `true` → Kernel. |
| `clientId` (deprecated) | `string` | ✅ | ✅ | — | Runtime-only alias for `userAgentEntry`. `userAgentEntry` wins when both are supplied. |
| Option | Type | Thrift | Kernel | Default Value | Note |
| ----------------------- | --------- | :----: | :----: | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `host` | `string` | ✅ | ✅ | — (required) | Required on both. |
| `path` | `string` | ✅ | ✅ | — (required) | Kernel also derives `x-databricks-org-id` from a `?o=<id>` query parameter. |
| `port` | `number` | ✅ | ✅ | `443` / — | Passed to the kernel as is, and the kernel folds it into `host`: a port other than the scheme default (443 over HTTPS, 80 with `https: false`) connects to `host:port`, while the default and `0` change nothing. An IPv6 `host` needs brackets (`[::1]`). A non-default port already in `host` wins over `port`, and a default port in `host` counts as none. The kernel rejects an invalid `port` (not an integer in `0..65535`) or `host` (credentials, a path, a query or a fragment) with a `ParameterError` when the session opens. Error messages never include the host. With OAuth, the kernel uses the same `host:port` for its OAuth endpoints; Thrift keeps OAuth on the bare `host` (port 443). |
| `https` | `boolean` | ✅ | ✅ | `true` | `false` selects plain HTTP; see [Plain HTTP transport](#plain-http-transport). |
| `userAgentEntry` | `string` | ✅ | ✅ | — | Folded into the connector `User-Agent` on both. |
| `useKernel` (internal) | `boolean` | — | — | `false` | Selects the backend: `false`/omitted → Thrift, `true` → Kernel. |
| `clientId` (deprecated) | `string` | ✅ | ✅ | — | Runtime-only alias for `userAgentEntry`. `userAgentEntry` wins when both are supplied. |

Set `client.getConfig().useCloudFetch = false` (default `true`) before opening a session to fetch
complete results without cloud-storage downloads. On the kernel backend this
Expand Down
2 changes: 1 addition & 1 deletion KERNEL_REV
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5c3a909771f749174567af074bfe18c24a335f5c
3b691d2a2c235ef847d61b308c31604979830994
36 changes: 22 additions & 14 deletions lib/kernel/KernelAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,21 @@ export interface KernelFederationOptions {
identityFederationClientId?: string;
}

/**
* Connection port forwarded as is to the napi binding's `ConnectionOptions.port`.
* The kernel validates it and folds it into the host.
*/
export interface KernelPortOptions {
port?: number;
}

export type KernelNativeConnectionOptions = KernelSessionDefaults &
KernelTlsOptions &
KernelHttpOptions &
KernelTelemetryOptions &
KernelProxyOptions &
KernelFederationOptions &
KernelPortOptions &
(
| {
hostName: string;
Expand Down Expand Up @@ -830,20 +839,13 @@ export function buildKernelProxyOptions(options: ConnectionOptions): KernelProxy
return { proxy: out };
}

// The kernel prepends `https://` to a bare host but keeps an explicit scheme.
// It otherwise ignores `port`, so carry it into the URL unless `host` already has one.
// The host is passed through as given. The kernel owns port folding, IPv6 bracketing,
// userinfo and path checks, and trailing-slash handling, and it prepends `https://` to a
// bare host. The one rewrite left here is plain HTTP: `https: false` sends an explicit
// `http://` scheme, and the kernel's scheme-based default port then applies.
function buildKernelHostName(options: ConnectionOptions): string {
if (options.https !== false) {
return options.host;
}
// The kernel accepts a full URL in `host`, so drop an existing `http://` or
// `https://` scheme before applying HTTP (`https: false` selects the scheme).
// Then strip a trailing `/` like the Thrift URL builder does.
const host = options.host.replace(/^https?:\/\//i, '').replace(/\/$/, '');
// `name:port` or `[ipv6]:port`; a bare IPv6 literal like `::1` has no port.
const hasPort = /^(\[[^\]]+\]|[^:]+):\d+$/.test(host);
const port = options.port && !hasPort ? `:${options.port}` : '';
return `http://${host}${port}`;
if (options.https !== false) return options.host;
return `http://${options.host.replace(/^https?:\/\//i, '')}`;
Comment thread
cathleeny marked this conversation as resolved.
Resolved
Comment thread
cathleeny marked this conversation as resolved.
Resolved
Comment thread
cathleeny marked this conversation as resolved.
Resolved
Comment thread
cathleeny marked this conversation as resolved.
Resolved
Comment thread
cathleeny marked this conversation as resolved.
Resolved
}
Comment thread
cathleeny marked this conversation as resolved.
Resolved

export function buildKernelConnectionOptions(options: ConnectionOptions): KernelNativeConnectionOptions {
Expand All @@ -858,7 +860,8 @@ export function buildKernelConnectionOptions(options: ConnectionOptions): Kernel
} & KernelTlsOptions &
KernelHttpOptions &
KernelProxyOptions &
KernelFederationOptions = {
KernelFederationOptions &
KernelPortOptions = {
hostName: buildKernelHostName(options),
httpPath: prependSlash(options.path),
// Match the NodeJS Thrift driver, which surfaces INTERVAL columns as
Expand All @@ -881,6 +884,11 @@ export function buildKernelConnectionOptions(options: ConnectionOptions): Kernel
...buildKernelProxyOptions(options),
};

// Passed through as is; the kernel validates it. Omitted when not set.
if (options.port !== undefined && options.port !== null) {
Comment thread
cathleeny marked this conversation as resolved.
Resolved
Comment thread
cathleeny marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thrift treats a falsy port as the default (the new test at DBSQLClient.test.ts:258 pins this), but this forwards NaN/''/false as is. With a #505 binding, port: Number(process.env.PORT) with PORT unset fails at openSession on the kernel, including the Reyden fallback for existing Thrift users. port: '8443' hits a napi f64 conversion error that decodeNapiKernelError passes through as a plain Error, not the ParameterError the docs promise. Suggest: omit port when falsy, throw a ParameterError for non-numbers, and add tests.

base.port = options.port;
}

if (options.enableGeoSpatialSupport !== undefined) {
if (typeof options.enableGeoSpatialSupport !== 'boolean') {
throw new HiveDriverError(
Expand Down
10 changes: 10 additions & 0 deletions native/kernel/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions tests/unit/DBSQLClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,40 @@ describe('DBSQLClient.connect', () => {
expect(connectionOptions.port).to.equal(3015);
});

it('keeps the Thrift URL for a host with an embedded port unchanged (current behavior, not changed by the kernel fix)', async () => {
const client = new DBSQLClient();

// Thrift appends options.port (443 by default) after the host, so an embedded port becomes
// `h:8443:443`, which node-fetch rejects as an invalid URL. This pins that current behavior.
const https = client['getConnectionOptions']({ ...connectOptions, host: 'h.databricks.com:8443', port: 443 });
expect(https.host).to.equal('h.databricks.com:8443');
expect(https.port).to.equal(443);
const httpsConnection = await new HttpConnection(https, client).getThriftConnection();
expect(httpsConnection.url).to.equal('https://h.databricks.com:8443:443/');

const http = client['getConnectionOptions']({
...connectOptions,
host: 'localhost:3015',
port: 80,
https: false,
});
const httpConnection = await new HttpConnection(http, client).getThriftConnection();
expect(httpConnection.url).to.equal('http://localhost:3015:80/');
});

it('treats a falsy port as the default (443 over HTTPS, 80 over HTTP) on Thrift', async () => {
const client = new DBSQLClient();

for (const port of [0, Number.NaN, undefined, null, '', false]) {
const label = String(port);
expect(client['getConnectionOptions']({ ...connectOptions, port: port as any }).port, label).to.equal(443);
expect(
client['getConnectionOptions']({ ...connectOptions, port: port as any, https: false }).port,
label,
).to.equal(80);
}
});

it('should only switch to plain HTTP for an explicit https: false', async () => {
const client = new DBSQLClient();

Expand Down
73 changes: 23 additions & 50 deletions tests/unit/kernel/connectionOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,71 +64,44 @@ describe('KernelAuth connection options — geospatial result representation', (
});

describe('KernelAuth connection options — https transport', () => {
const hostName = (extra: Record<string, unknown>) => buildKernelConnectionOptions(opts(extra)).hostName;

it('forwards host unchanged by default (kernel prepends https://)', () => {
expect(buildKernelConnectionOptions(opts({})).hostName).to.equal('h.databricks.com');
expect(buildKernelConnectionOptions(opts({ https: true })).hostName).to.equal('h.databricks.com');
expect(hostName({})).to.equal('h.databricks.com');
expect(hostName({ https: true })).to.equal('h.databricks.com');
});

it('selects plain HTTP via an explicit http:// host when https is false', () => {
expect(buildKernelConnectionOptions(opts({ https: false })).hostName).to.equal('http://h.databricks.com');
expect(hostName({ https: false })).to.equal('http://h.databricks.com');
expect(hostName({ host: 'localhost:3015', https: false })).to.equal('http://localhost:3015');
});

it('carries the port into the http:// host (matching the Thrift URL)', () => {
expect(buildKernelConnectionOptions(opts({ host: 'localhost', port: 3015, https: false })).hostName).to.equal(
'http://localhost:3015',
);
// A port already embedded in `host` (the kernel convention) is preserved.
expect(buildKernelConnectionOptions(opts({ host: 'localhost:3015', https: false })).hostName).to.equal(
'http://localhost:3015',
);
});

it('does not double the port when it is set in both host and port', () => {
expect(buildKernelConnectionOptions(opts({ host: 'localhost:3015', port: 3015, https: false })).hostName).to.equal(
'http://localhost:3015',
);
expect(buildKernelConnectionOptions(opts({ host: '[::1]:3015', port: 3015, https: false })).hostName).to.equal(
'http://[::1]:3015',
);
});

it('strips a trailing slash from host before adding the port (matching Thrift)', () => {
expect(buildKernelConnectionOptions(opts({ host: 'localhost/', port: 3015, https: false })).hostName).to.equal(
'http://localhost:3015',
);
expect(buildKernelConnectionOptions(opts({ host: 'localhost:3015/', port: 3015, https: false })).hostName).to.equal(
'http://localhost:3015',
);
});

const hostName = (extra: Record<string, unknown>) => buildKernelConnectionOptions(opts(extra)).hostName;

it('normalizes an existing http:// scheme in host instead of prefixing it again', () => {
it('replaces an existing http(s):// scheme in host with http:// when https is false', () => {
expect(hostName({ host: 'http://localhost:3015', https: false })).to.equal('http://localhost:3015');
expect(hostName({ host: 'http://localhost:3015', port: 3015, https: false })).to.equal('http://localhost:3015');
expect(hostName({ host: 'HTTP://localhost', port: 3015, https: false })).to.equal('http://localhost:3015');
expect(hostName({ host: 'http://localhost:3015/', https: false })).to.equal('http://localhost:3015');
});

it('replaces an existing https:// scheme in host with http:// when https is false', () => {
expect(hostName({ host: 'HTTP://localhost', https: false })).to.equal('http://localhost');
expect(hostName({ host: 'https://localhost:3015', https: false })).to.equal('http://localhost:3015');
expect(hostName({ host: 'https://localhost', port: 3015, https: false })).to.equal('http://localhost:3015');
expect(hostName({ host: 'https://[::1]:3015', port: 3015, https: false })).to.equal('http://[::1]:3015');
expect(hostName({ host: 'https://[::1]:3015', https: false })).to.equal('http://[::1]:3015');
});

it('forwards a full-URL host unchanged when https is not false', () => {
expect(hostName({ host: 'https://h.databricks.com' })).to.equal('https://h.databricks.com');
expect(hostName({ host: 'http://localhost:3015', https: true })).to.equal('http://localhost:3015');
});
});

describe('KernelAuth connection options — port passthrough', () => {
const native = (extra: Record<string, unknown>) =>
buildKernelConnectionOptions(opts(extra)) as { hostName: string; port?: number };

it('passes a set port to the binding unchanged', () => {
expect(native({ port: 8443 })).to.include({ hostName: 'h.databricks.com', port: 8443 });
expect(native({ port: 3015, https: false })).to.include({ hostName: 'http://h.databricks.com', port: 3015 });
});

it('does not mistake an IPv6 literal for an embedded port', () => {
expect(buildKernelConnectionOptions(opts({ host: '[::1]', port: 3015, https: false })).hostName).to.equal(
'http://[::1]:3015',
);
// Same URL shape as the Thrift transport, which also requires brackets.
expect(buildKernelConnectionOptions(opts({ host: '::1', port: 3015, https: false })).hostName).to.equal(
'http://::1:3015',
);
it('sends no port key when the port is omitted', () => {
for (const extra of [{}, { port: undefined }, { port: null }]) {
expect(native(extra), JSON.stringify(extra)).to.not.have.property('port');
}
});
});

Expand Down
Loading