|
1 | | -// |
| 1 | +// |
2 | 2 | // Copyright (c) .NET Foundation and Contributors |
3 | 3 | // Portions Copyright (c) Microsoft Corporation. All rights reserved. |
4 | 4 | // See LICENSE file in the project root for full license information. |
@@ -206,21 +206,26 @@ internal void ParseHTTPRequest() |
206 | 206 | if (headerName == "authorization") |
207 | 207 | { |
208 | 208 | int sepSpace = headerValue.IndexOf(' '); |
209 | | - string authType = headerValue.Substring(0, sepSpace); |
210 | | - if (authType.ToLower() == "basic") |
| 209 | + // Authorization header value must be in format "type credentials". If not, ignore. |
| 210 | + if (sepSpace > 0) |
211 | 211 | { |
212 | | - string authInfo = headerValue.Substring(sepSpace + 1); |
213 | | - // authInfo is base64 encoded username and password. |
214 | | - byte[] authInfoDecoded = Convert.FromBase64String(authInfo); |
215 | | - char[] authInfoDecChar = System.Text.Encoding.UTF8.GetChars(authInfoDecoded); |
216 | | - string strAuthInfo = new string(authInfoDecChar); |
217 | | - // The strAuthInfo comes in format username:password. Parse it. |
218 | | - int sepColon = strAuthInfo.IndexOf(':'); |
219 | | - if (sepColon != -1) |
| 212 | + string authType = headerValue.Substring(0, sepSpace); |
| 213 | + if (authType.ToLower() == "basic") |
220 | 214 | { |
221 | | - m_NetworkCredentials = new NetworkCredential(strAuthInfo.Substring(0, sepColon), strAuthInfo.Substring(sepColon + 1)); |
| 215 | + string authInfo = headerValue.Substring(sepSpace + 1); |
| 216 | + // authInfo is base64 encoded username and password. |
| 217 | + byte[] authInfoDecoded = Convert.FromBase64String(authInfo); |
| 218 | + char[] authInfoDecChar = System.Text.Encoding.UTF8.GetChars(authInfoDecoded); |
| 219 | + string strAuthInfo = new string(authInfoDecChar); |
| 220 | + // The strAuthInfo comes in format username:password. Parse it. |
| 221 | + int sepColon = strAuthInfo.IndexOf(':'); |
| 222 | + if (sepColon != -1) |
| 223 | + { |
| 224 | + m_NetworkCredentials = new NetworkCredential(strAuthInfo.Substring(0, sepColon), strAuthInfo.Substring(sepColon + 1)); |
| 225 | + } |
222 | 226 | } |
223 | 227 | } |
| 228 | + |
224 | 229 | } |
225 | 230 | } |
226 | 231 |
|
|
0 commit comments