From b107a6d01066d60e798ec02511672310fe952811 Mon Sep 17 00:00:00 2001 From: Drew McCormack Date: Mon, 5 Nov 2018 10:54:50 +0100 Subject: [PATCH] fix: Colons in the password of a HTTP Basic Authentication. (#55) The existing code was taking the first component of the colon-separated array as the user name, and the second as the password. In fact, all components after the first must be treated as belonging to the password. --- Sources/CredentialsHTTP/CredentialsHTTPBasic.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/CredentialsHTTP/CredentialsHTTPBasic.swift b/Sources/CredentialsHTTP/CredentialsHTTPBasic.swift index 025935f..b5b5800 100644 --- a/Sources/CredentialsHTTP/CredentialsHTTPBasic.swift +++ b/Sources/CredentialsHTTP/CredentialsHTTPBasic.swift @@ -107,14 +107,14 @@ public class CredentialsHTTPBasic : CredentialsPluginProtocol { authorization = userAuthorization as String } - let credentials = authorization.components(separatedBy: ":") - guard credentials.count >= 2 else { + let credentials = authorization.split(separator: ":", maxSplits: 1) + guard credentials.count == 2 else { onFailure(.badRequest, nil) return } - let userid = credentials[0] - let password = credentials[1] + let userid = String(credentials[0]) + let password = String(credentials[1]) if let userProfileLoader = self.userProfileLoader { userProfileLoader(userid) { userProfile, storedPassword in