Skip to content

Commit 1453b26

Browse files
cathleenyIsaac
andcommitted
fix(kernel): reject a _connection_uri with an empty port
urlsplit reads "https://h.io:/sql/x" as having no port, so the URI passed validation and "https://h.io:" went to the kernel. An authority that ends in ":" is now rejected as malformed, like port 0. Covered for a host name and a bracketed IPv6 literal. Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com> Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 01999fa commit 1453b26

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

‎src/databricks/sql/session.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ def _uri_host_and_path(uri: str) -> Tuple[str, str]:
117117
or not parts.hostname
118118
or "@" in parts.netloc
119119
or port == 0
120+
# urlsplit reads "h.io:" as no port; an empty port is malformed.
121+
or parts.netloc.endswith(":")
120122
or parts.path in ("", "/")
121123
):
122124
raise ValueError(

‎tests/unit/test_session.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,8 @@ def test_connection_uri_only_resolves_host_and_path():
12841284
({"_connection_uri": "https://h.io:8443/"}, "Invalid _connection_uri"),
12851285
({"_connection_uri": "https://h.io:notaport/sql/x"}, "Invalid _connection_uri"),
12861286
({"_connection_uri": "https://h.io:0/sql/x"}, "Invalid _connection_uri"),
1287+
({"_connection_uri": "https://h.io:/sql/x"}, "Invalid _connection_uri"),
1288+
({"_connection_uri": "https://[::1]:/sql/x"}, "Invalid _connection_uri"),
12871289
({"_connection_uri": "https://u:p@h.io/sql/x"}, "Invalid _connection_uri"),
12881290
({"_connection_uri": "https:///sql/x"}, "Invalid _connection_uri"),
12891291
],

0 commit comments

Comments
 (0)