Skip to content

fix(kernel): honor a custom port over HTTPS on the kernel backend - #636

Open
cathleeny wants to merge 18 commits into
mainfrom
cathleeny/fix/kernel-honor-https-port
Open

cathleeny wants to merge 18 commits into
mainfrom
cathleeny/fix/kernel-honor-https-port

Conversation

@cathleeny

@cathleeny cathleeny commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

On the kernel backend, a custom port is now honored over HTTPS. Before this PR it was dropped unless https: false was set. Thrift is unchanged.

The kernel now applies the port (databricks/databricks-sql-kernel#505). The driver passes host through and sends port to the native binding, so the hand-written host parsing in KernelAuth.ts is gone.

Behavior

  • Kernel rules:
    • the scheme's default port (443 over HTTPS, 80 over HTTP) leaves the host unchanged;
    • any other port is applied as host:port, with a bare IPv6 host bracketed;
    • a port already in host wins, with a warning when it differs;
    • a host with credentials, a path, query or fragment, or no name is rejected. The kernel redacts credentials in its errors.
  • Driver:
    • a falsy port means the default, as on Thrift, and a numeric string is accepted;
    • an invalid port throws HiveDriverError;
    • https: false sends http://host, so 443 over HTTP is applied and 80 is not;
    • any explicit port is sent, and the kernel treats the scheme's default as a no-op.
  • OAuth: with OAuth and a non-default port, the kernel uses the same host:port for OAuth, while Thrift uses the bare host. This is documented, not guarded.

Before merge

  • KERNEL_REV points at the kernel PR's head (22ae6ec). Move it to the merged kernel commit.
  • Bump the @databricks/databricks-sql-kernel-* native packages to a release that includes the kernel change. An older native binding ignores port and connects to the default port, so this PR must not ship without that bump.

Testing

  • Unit tests (1849), type-check, lint and prettier pass.
  • The native binding was regenerated from KERNEL_REV; only the typed port field changed.

Related PRs: https://github.com/databricks/databricks-sql-kernel/pull/505, databricks/databricks-sql-python#1071, databricks/databricks-sql-go#581, https://github.com/databricks/databricks-driver-test/pull/2188

This pull request and its description were written by Isaac.

The kernel backend folded `port` into the host only when `https: false` was set,
so `port: 8443` over HTTPS connected to 443 while the Thrift backend honored it.

buildKernelHostName folds a supplied non-default port into the host for HTTPS too:

- A bare host with a non-default port becomes `host:port`. `port: 443`, an omitted
  port, and `0` (the Thrift `options.port || 443` default) leave the host unchanged.
- A bare IPv6 host gets brackets before the port is appended, on both HTTPS and
  `https: false` (`[::1]:8443`, `http://[::1]:3015`). With no port the host is unchanged.
- A decimal string port such as `'8443'` is accepted, as on Thrift. Non-numeric or
  out-of-range values throw HiveDriverError.
- A port already in `host` is kept, and an explicit `port` must match it. A different
  one throws HiveDriverError, so a port is never dropped silently.

Documented, not guarded: with a non-default port, OAuth on the kernel backend reaches
its endpoints at the same `host:port` (Thrift keeps OAuth on the bare host). This is
noted in CONNECTION_PARAMETERS.md and CHANGELOG.md.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

Comment thread lib/kernel/KernelAuth.ts Resolved
Comment thread lib/kernel/KernelAuth.ts Resolved
cathleeny and others added 5 commits November 19, 2026 23:06
…ault

The kernel path folds an explicit `port` into `host`. Review feedback showed
two regressions from the first version of this change, and this commit fixes
them to keep the pre-existing kernel precedence:

- A port embedded in `host` wins over `port`, as on origin/main, where
  `{host: 'h:8443', port: 443}` connected to 8443 and
  `{host: 'localhost:3015', port: 80, https: false}` connected to 3015.
  A differing explicit port is logged as a warning and not thrown. An explicit
  443 is treated as the default (getConnectionOptions fills it in) and is not
  reported.
- A falsy `port` (0, NaN, '', null, undefined, false) means the default, as on
  Thrift (`options.port || 443`). It no longer throws.
- A trailing "/" is dropped before port handling. A path, query or fragment is
  rejected only when a port has to be folded into the host, since that would
  produce a malformed authority. Inputs with no port are unchanged.
- Truthy invalid ports (non-numeric strings, out of range, true) still throw,
  as Thrift also fails on them.

The logger is passed from KernelBackend into buildKernelConnectionOptions.

Tests: table-driven cases in connectionOptions.test.ts cover the precedence,
falsy ports, the warning, and rejection of path and fragment hosts. A Thrift
case in DBSQLClient.test.ts covers falsy-port defaults.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
A host with a path, query or fragment cannot connect on the kernel path,
because the kernel puts its API paths after the host. Before this commit,
`host: 'h.io/path:8443'` also parsed as host `h.io/path` with embedded port
8443, which passed a broken host straight through. With an explicit `port`
(DBSQLClient always supplies 443 by default) such a host now throws
HiveDriverError before the embedded-port parse. Without a `port` the host is
passed through unchanged, as before.

Thrift is unchanged. A test in DBSQLClient.test.ts pins the current Thrift
URL for a host with an embedded port (`https://h:8443:443/`), which
node-fetch rejects, so the kernel fix does not alter Thrift.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
…e path

The path, query and fragment check from the previous commit rejected any
explicit port, including the default 443 that DBSQLClient always supplies.
That broke inputs that passed through on origin/main: `h/x` with no port or
with port 443 over HTTPS was passed to the kernel verbatim before this change.

The check now fires only when the port would be folded into the host
(`https: false`, or a non-443 port over HTTPS) or when the host carries a
port after the path (`h.io/path:8443`), which must not be read as port 8443.
With no port, or with 443 over HTTPS and no embedded port, the host passes
through unchanged. The check still runs before the embedded-port parse.

Tests cover the pass-through cases (no port, port 443, https://host/x) and
keep the rejection cases for the folded and embedded-after-path forms.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
The path, query and fragment check now fires only when the explicit port is
folded into the host (https: false, or a non-443 port over HTTPS). A host
with no folded port passes through unchanged, as on origin/main, including
a host with a port after the path (h.io/path:8443), which base passed to the
kernel verbatim. The check still runs before the embedded-port parse.

Tests keep the rejection cases for the folded form and add pass-through
cases for no port, port 443, and an embedded port after a path.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
Resolve the CHANGELOG.md conflict by keeping both Unreleased entries: this PR's
kernel port entry and main's Arrow row materialization entry. No code conflicts.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 Low

Looks good, with 1 low concern. Folding the port into the host keeps the old precedence for embedded ports, and the tests cover the cases well. The one concern is the exemption for port 443 in the warning: its stated reason doesn't hold, because the kernel receives the raw caller options.

Comment thread lib/kernel/KernelAuth.ts Resolved
cathleeny and others added 2 commits November 20, 2026 16:25
Resolve the CHANGELOG.md conflict by keeping both Unreleased entries: this PR's
kernel port entry and main's Arrow DECIMAL materialization entry. No code
conflicts.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
…bout

The comment said getConnectionOptions fills in 443, but backend.connect gets
the caller's raw options, so a 443 there was set explicitly. The behavior is
intended and unchanged: 443 is the default port, so a host carrying its own
port is used without a warning, the same rule as the Python and Go drivers.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

@cathleeny

cathleeny commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

@vuanhphung FYI on why this keeps the regex instead of Node's URL: with https://, URL drops the default port (new URL("https://h:443").port === ""), so host: "h:443", port: 8443 would switch to 8443 instead of keeping the host's port. Working around that made the URL version larger than the regex & slower, so we kept the regex.

Automated comment from the driver feature factory (Isaac).

A host with userinfo, such as `user:pw@h` with `port: 8443`, was folded
into `[user:pw@h]:8443`: the colon in the userinfo was read as a bare IPv6
literal, so it was bracketed. Userinfo is now set aside before port
detection and IPv6 bracketing, and kept in the result as on origin/main,
so the same input gives `user:pw@h:8443`. A userinfo host with an
embedded port, or with no port, is passed through unchanged as before.

The path error and the port-conflict warning echoed the raw host,
credentials included. Both now show the host with its userinfo replaced
by `***@`.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 2 Low

Looks good: 2 low concerns. The port handling is well covered by table-driven tests, keeps credentials out of errors and warnings, and leaves Thrift unchanged. Nit: the CHANGELOG says a warning is logged on a port conflict, but it doesn't mention that no warning is logged when the explicit port is 443.

Comment thread lib/kernel/KernelAuth.ts Resolved
Comment thread lib/kernel/KernelAuth.ts Resolved
cathleeny and others added 3 commits November 23, 2026 20:27
redactHost stopped at the first '/', '?' or '#', so a password containing one of them (for example user:p/w@h) was not redacted, and the path error echoed it. It now replaces everything up to the last '@' in the host, as the Go driver does. Tests cover passwords containing '/', '?' and '#'.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
The embedded-port check ran on the whole host text, so a path host with no folded port, such as h.io/x:99999, threw an out-of-range error instead of passing through unchanged as on origin/main. Path hosts that reach that check take no folded port, so they are no longer parsed for one.

The port-conflict warning skipped port: 443 even with https: false, where 443 is an explicit, non-default port. The warning now uses the same condition as folding: always with https: false, and only for a non-443 port over HTTPS.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
Resolve the CHANGELOG.md conflict after main's 3.1.0 release: this PR's kernel port entry moves to a new Unreleased section above 3.1.0, and main's 3.1.0 list is kept as is. The unit suite and tsc --noEmit pass on the merged tree.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

✅ No issues identified.

@vuanhphung

Copy link
Copy Markdown
Collaborator

Could this use a single parse instead of the hand-written regexes? new URL('x://' + host) keeps an explicit :443 (only special schemes like https: drop it), and the same parse handles finding the embedded port, range-checking it, userinfo and empty hosts. Bracket only when net.isIPv6() is true. Leaving the host out of messages removes the need for redactHost. I prototyped it: about 40 lines instead of about 85, the same result on 86 of the 94 cases in the PR's tables, and the differences are the malformed hosts (h.io:abc, [::1, a@b:c@h.io), which now throw or parse correctly.

Longer term, a port option in the kernel would let Node, Go (databricks/databricks-sql-go#581) and Python (databricks/databricks-sql-python#1071) drop their parsers entirely.


This comment was generated with GitHub MCP.

The driver no longer folds `port` into the host. It passes the host through
and sends `port` to the napi binding, which folds it (kernel
databricks/databricks-sql-kernel#505, KERNEL_REV b5aac45d54bb4842b7e04dd7fbf2368216b6de4e).

The driver keeps `explicitPort()` validation (falsy means default, numeric
strings accepted, invalid throws HiveDriverError) and the `https: false`
scheme handling (sends `http://host`). It omits `port` when it is the default
for the scheme it sends (443 over HTTPS, 80 over HTTP), since the kernel
treats the default as a no-op.

Removed from the driver: embedded-port detection and conflict warning, IPv6
bracketing, userinfo handling, redactHost, and the path checks.

native/kernel/index.d.ts regenerated with `npm run build:native` against
KERNEL_REV; only the typed `port` field changed.

Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 High · 1 Low

Looks good, with 1 low concern. As the PR already says, merging requires the published native-package bump: an older binding silently ignores port and connects to the default port, and the driver has no capability check to catch that.

This overview is Claude Opus 5.5's initial take; GPT-6.1 Sol added findings it doesn't mention — see the findings below.

Comment thread lib/kernel/KernelAuth.ts
// Omitted unless it is a non-default port, so the key is absent for the default.
const port = buildKernelPort(options);
if (port !== undefined) {
base.port = port;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High — The driver now drops host-side port folding, but the native packages stay pinned to 1.5.0, which does not read port. npm installs therefore lose the custom https: false port that worked before. The CHANGELOG admits this. Bump the native packages and lockfile in the same release, or keep the fallback folding until then.

🔀 Found by GPT-6.1 Sol · confirmed by the judge

Comment thread lib/kernel/KernelAuth.ts Resolved
The driver dropped port 443 whenever https was not false, even for a host that already carries http:// (for example host 'http://localhost', port 443), where 443 is not the default; the kernel then connected to port 80. The driver now sends any explicit port, and the kernel, which knows the effective scheme, treats that scheme's default as a no-op. KERNEL_REV moves to 22ae6ec250837b38d0e3dc720310d4dcfb81fa98 (databricks/databricks-sql-kernel#505 head).

Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>

Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 High

Needs changes: 1 high concern. KERNEL_REV is 22ae6ec, but the description says it points at b5aac45, so please reconcile the two. Nit: the KernelPortOptions JSDoc says the port is sent only when it isn't the scheme default, but buildKernelPort sends any explicit port, 443 included.

Comment thread lib/kernel/KernelAuth.ts
function buildKernelHostName(options: ConnectionOptions): string {
if (options.https !== false) return options.host;
return `http://${options.host.replace(/^https?:\/\//i, '')}`;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High — The driver no longer folds port into http://host:port for https: false. The npm packages are still pinned to 1.5.0 (package.json lines 95-102), which ignores port. So {host:'localhost', https:false, port:3015} worked before and now connects to port 80 on npm installs. The CHANGELOG admits the gap. Bump the pins in this PR, or keep the fold or add a capability check until the bump lands.

🔀 Found by both reviewers · confirmed by the judge

The JSDoc still said the port is sent only when it isn't the scheme
default. Since the previous commit, buildKernelPort sends any explicit
port, 443 included, and the kernel treats the scheme's default as a no-op.

Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 High

Needs changes: 1 high concern. Moving port folding to the kernel without bumping the published native binding breaks the https: false + custom port case that works today. Nit: the comment above base.port says 'Omitted unless it is a non-default port', but 443 and 80 are sent too.

Comment thread lib/kernel/KernelAuth.ts
// `http://` scheme, and the kernel's scheme-based default port then applies.
function buildKernelHostName(options: ConnectionOptions): string {
if (options.https !== false) return options.host;
return `http://${options.host.replace(/^https?:\/\//i, '')}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High — With https: false and a custom port, the driver no longer folds the port into the host. The @databricks/databricks-sql-kernel-* packages are still pinned to 1.5.0, which ignores port, so those connections now go to port 80. The CHANGELOG admits a follow-up bump is needed. Bump the pins together with this change, or keep folding the port for https: false until the binding ships.

🔀 Found by both reviewers · confirmed by the judge

It still said the port is omitted unless it is non-default. Any explicit
port, 443 and 80 included, is sent; the key is absent only when no port is
set.

Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
Co-authored-by: Isaac <no-reply@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).

Verdict: 1 High

Mostly sound, with 1 medium concern: the port validation and passthrough are correct and well tested, but with the native package pins unchanged, HTTP connections on a custom port go to port 80 until a binding that reads port is pinned. KERNEL_REV also still points at the unmerged kernel PR head (already listed in the PR's before-merge steps).

Comment thread lib/kernel/KernelAuth.ts
// Omitted when no port is set; any explicit port, 443 and 80 included, is sent.
const port = buildKernelPort(options);
if (port !== undefined) {
base.port = port;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High — The driver now sends port to the native binding and no longer folds it into host, but package.json still pins every platform package to 1.5.0, which does not read port. With the published binding, https: false plus a custom port regresses to port 80. Bump the pins and lockfile to a release containing kernel #505, or keep the old HTTP folding until then. The CHANGELOG already admits this gap.

🔀 Found by both reviewers · confirmed by the judge

This branch had an error being deployed

1 failed deployment
azure-prod — bbc4d015 Deployed Nov 25, 2026 by cathleeny via e2e-test (22.23.4, 22_23_4) #2237
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants