Skip to content

Commit 80ff8b3

Browse files
oh0873pan3793
authored andcommitted
[KYUUBI #7403] Password with colon bug fixes
### Why are the changes needed? If a password contains a colon, REST API does not pick up colons. Similarly, password string like `correctpassword:random-charachars` gets parsed as `correctpassword`. ### How was this patch tested? Tested in local build, password with colon are getting parsed properly. ### Was this patch authored or co-authored using generative AI tooling? Test Suite was helped by Cursor auto-complete. Closes #7404 from oh0873/hoonoh/colon-password-bug-fix. Closes #7403 1bd8e19 [Hoon Oh] Password with colon bug fixes Authored-by: Hoon Oh <hoonoh@geico.com> Signed-off-by: Cheng Pan <chengpan@apache.org>
1 parent e2ea980 commit 80ff8b3

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

kyuubi-server/src/main/scala/org/apache/kyuubi/server/http/authentication/BasicAuthenticationHandler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class BasicAuthenticationHandler(basicAuthType: AuthType)
6969
val authorization = getAuthorization(request)
7070
val inputToken = Option(authorization).map(a => Base64.getDecoder.decode(a.getBytes()))
7171
.getOrElse(Array.empty[Byte])
72-
val creds = new String(inputToken, Charset.forName("UTF-8")).split(":")
72+
val creds = new String(inputToken, Charset.forName("UTF-8")).split(":", 2)
7373

7474
if (allowAnonymous) {
7575
authUser = creds.take(1).headOption.filterNot(_.isEmpty).getOrElse("anonymous")

kyuubi-server/src/main/scala/org/apache/kyuubi/server/http/authentication/KyuubiInternalAuthenticationHandler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class KyuubiInternalAuthenticationHandler extends AuthenticationHandler with Log
4848
val authorization = getAuthorization(request)
4949
val inputToken = Option(authorization).map(a => Base64.getDecoder.decode(a.getBytes()))
5050
.getOrElse(Array.empty[Byte])
51-
val creds = new String(inputToken, StandardCharsets.UTF_8).split(":")
51+
val creds = new String(inputToken, StandardCharsets.UTF_8).split(":", 2)
5252

5353
if (creds.size < 2 || creds(0).trim.isEmpty || creds(1).trim.isEmpty) {
5454
response.setHeader(WWW_AUTHENTICATE_HEADER, authScheme.toString)

kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiRestAuthenticationSuite.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ class KyuubiRestCustomAuthenticationTest extends KyuubiRestAuthenticationSuite {
240240
assert(HttpServletResponse.SC_OK == response.getStatus)
241241
}
242242

243+
test("test with invalid CUSTOM http basic authorization that contains colon") {
244+
val response = webTarget.path("api/v1/sessions/count")
245+
.request()
246+
.header(AUTHORIZATION_HEADER, basicAuthorizationHeader("user", "password:with:colons"))
247+
.get()
248+
249+
assert(HttpServletResponse.SC_FORBIDDEN == response.getStatus)
250+
}
251+
243252
test("test with invalid CUSTOM http basic authorization") {
244253
val response = webTarget.path("api/v1/sessions/count")
245254
.request()

0 commit comments

Comments
 (0)