Skip to content

Commit c5458a5

Browse files
committed
Fix #3485 (#3486)
* Fix #3485 Passing username/pass in the node URI directly bleeds into DebugInformation. If you use BasicAuthentication(username, password) on ConnectionSettings which is the recomended route this does not happen. * fix tabs in DebugInformation.doc.cs * bad merge (cherry picked from commit 7fc9ca0)
1 parent 42414ec commit c5458a5

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

src/Elasticsearch.Net/Responses/ResponseStatics.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using System.Text;
45

@@ -49,10 +50,26 @@ public static void DebugAuditTrail(List<Audit> auditTrail, StringBuilder sb)
4950
{
5051
var audit = a.a;
5152
sb.Append($" - [{a.i + 1}] {audit.Event.GetStringValue()}:");
52-
if (audit.Node?.Uri != null) sb.Append($" Node: {audit.Node.Uri}");
53+
54+
AuditNodeUrl(sb, audit);
55+
5356
if (audit.Exception != null) sb.Append($" Exception: {audit.Exception.GetType().Name}");
5457
sb.AppendLine($" Took: {(audit.Ended - audit.Started).ToString()}");
5558
}
5659
}
60+
61+
private static void AuditNodeUrl(StringBuilder sb, Audit audit)
62+
{
63+
var uri = audit.Node?.Uri;
64+
if (uri == null) return;
65+
66+
if (!string.IsNullOrEmpty(uri.UserInfo))
67+
{
68+
var builder = new UriBuilder(uri);
69+
builder.Password = "redacted";
70+
uri = builder.Uri;
71+
}
72+
sb.Append($" Node: {uri}");
73+
}
5774
}
5875
}

src/Tests/Tests/ClientConcepts/Troubleshooting/DebugInformation.doc.cs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using FluentAssertions;
1010
using Nest;
1111
using Tests.Core.Client;
12+
using Tests.Core.Client.Settings;
1213
using Tests.Core.ManagedElasticsearch.Clusters;
1314
using Tests.Domain;
1415
using Tests.Framework;
@@ -28,8 +29,7 @@ public class DebugInformation : IntegrationDocumentationTestBase, IClusterFixtur
2829
{
2930
public DebugInformation(ReadOnlyCluster cluster) : base(cluster) {}
3031

31-
[I]
32-
public void DefaultDebug()
32+
[I] public void DefaultDebug()
3333
{
3434
// hide
3535
var client = this.Client;
@@ -42,6 +42,41 @@ public void DefaultDebug()
4242

4343
response.DebugInformation.Should().Contain("Valid NEST response");
4444
}
45+
//hide
46+
[U] public void PasswordIsNotExposedInDebugInformation()
47+
{
48+
// hide
49+
var client = new ElasticClient(new AlwaysInMemoryConnectionSettings()
50+
.DefaultIndex("index")
51+
.BasicAuthentication("user1", "pass2")
52+
);
53+
54+
var response = client.Search<Project>(s => s
55+
.Query(q => q
56+
.MatchAll()
57+
)
58+
);
59+
60+
response.DebugInformation.Should().NotContain("pass2");
61+
}
62+
63+
//hide
64+
[U] public void PasswordIsNotExposedInDebugInformationWhenPartOfUrl()
65+
{
66+
// hide
67+
var pool = new SingleNodeConnectionPool(new Uri("http://user1:pass2@localhost:9200"));
68+
var client = new ElasticClient(new ConnectionSettings(pool, new InMemoryConnection())
69+
.DefaultIndex("index")
70+
);
71+
72+
var response = client.Search<Project>(s => s
73+
.Query(q => q
74+
.MatchAll()
75+
)
76+
);
77+
78+
response.DebugInformation.Should().NotContain("pass2");
79+
}
4580
/**
4681
* This can be useful in tracking down numerous problems and can also be useful when filing an
4782
* {github}/issues[issue] on our github repository.

0 commit comments

Comments
 (0)