Skip to content

Commit d599de9

Browse files
committed
Add additional security checks for GSS session encryption and GSS authentication (#6525)
Closes #6523 (cherry picked from commit 5f26d61)
1 parent 370d755 commit d599de9

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/Npgsql/Internal/NpgsqlConnector.Auth.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,14 @@ async Task AuthenticateMD5(string username, byte[] salt, bool async, Cancellatio
330330
internal async ValueTask AuthenticateGSS(bool async, CancellationToken cancellationToken)
331331
{
332332
var targetName = $"{KerberosServiceName}/{Host}";
333+
// See https://github.com/postgres/postgres/blob/a0dd0702e464f206b08c99a74cb58809c51aafa5/src/interfaces/libpq/fe-auth.c#L111-L123
334+
// We do not support delegation (TokenImpersonationLevel.Delegation) for now (#6540)
335+
var clientOptions = new NegotiateAuthenticationClientOptions
336+
{
337+
TargetName = targetName,
338+
RequireMutualAuthentication = true
339+
};
333340

334-
var clientOptions = new NegotiateAuthenticationClientOptions { TargetName = targetName };
335341
NegotiateOptionsCallback?.Invoke(clientOptions);
336342

337343
using var authContext = new NegotiateAuthentication(clientOptions);

src/Npgsql/Internal/NpgsqlConnector.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,14 @@ internal async ValueTask<GssEncryptionResult> GSSEncrypt(bool async, bool isRequ
673673
ConnectionLogger.LogTrace("Negotiating GSS encryption");
674674

675675
var targetName = $"{KerberosServiceName}/{Host}";
676-
var clientOptions = new NegotiateAuthenticationClientOptions { TargetName = targetName };
676+
// See https://github.com/postgres/postgres/blob/a0dd0702e464f206b08c99a74cb58809c51aafa5/src/interfaces/libpq/fe-secure-gssapi.c#L651-L658
677+
// We do not support delegation (TokenImpersonationLevel.Delegation) for now (#6540)
678+
var clientOptions = new NegotiateAuthenticationClientOptions
679+
{
680+
TargetName = targetName,
681+
RequireMutualAuthentication = true,
682+
RequiredProtectionLevel = ProtectionLevel.EncryptAndSign
683+
};
677684

678685
NegotiateOptionsCallback?.Invoke(clientOptions);
679686

0 commit comments

Comments
 (0)