Skip to content
This repository was archived by the owner on Mar 19, 2019. It is now read-only.

Commit 1631e84

Browse files
committed
#337 Clean up Windows Auth
1 parent 287a48c commit 1631e84

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Microsoft.Net.Http.Server/RequestProcessing/NativeRequestContext.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,14 @@ internal ClaimsPrincipal GetUser()
224224
&& info->InfoType == HttpApi.HTTP_REQUEST_INFO_TYPE.HttpRequestInfoTypeAuth
225225
&& info->pInfo->AuthStatus == HttpApi.HTTP_AUTH_STATUS.HttpAuthStatusSuccess)
226226
{
227-
return new WindowsPrincipal(new WindowsIdentity(info->pInfo->AccessToken,
228-
GetAuthTypeFromRequest(info->pInfo->AuthType).ToString()));
227+
// Duplicates AccessToken
228+
var identity = new WindowsIdentity(info->pInfo->AccessToken,
229+
GetAuthTypeFromRequest(info->pInfo->AuthType).ToString());
230+
231+
// Close the original
232+
UnsafeNclNativeMethods.SafeNetHandles.CloseHandle(info->pInfo->AccessToken);
233+
234+
return new WindowsPrincipal(identity);
229235
}
230236
}
231237
return new ClaimsPrincipal(new ClaimsIdentity()); // Anonymous / !IsAuthenticated

src/Microsoft.Net.Http.Server/RequestProcessing/Request.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Net;
88
using System.Security.Claims;
99
using System.Security.Cryptography.X509Certificates;
10+
using System.Security.Principal;
1011
using System.Threading;
1112
using System.Threading.Tasks;
1213

@@ -303,6 +304,7 @@ internal void Dispose()
303304
// TODO: Verbose log
304305
_isDisposed = true;
305306
_nativeRequestContext.Dispose();
307+
(User?.Identity as WindowsIdentity)?.Dispose();
306308
if (_nativeStream != null)
307309
{
308310
_nativeStream.Dispose();

0 commit comments

Comments
 (0)