Skip to content

Commit 2992a9c

Browse files
committed
Mask request URLs in HTTP exchanges actuator
1 parent 81f57a0 commit 2992a9c

3 files changed

Lines changed: 26 additions & 14 deletions

File tree

src/Management/src/Endpoint/Actuators/HttpExchanges/HttpExchangeRequest.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System.Text.Json.Serialization;
66
using Microsoft.Extensions.Primitives;
7+
using Steeltoe.Common.Extensions;
78
using Steeltoe.Common.Json;
89

910
namespace Steeltoe.Management.Endpoint.Actuators.HttpExchanges;
@@ -13,9 +14,19 @@ public sealed class HttpExchangeRequest
1314
[JsonPropertyName("method")]
1415
public string Method { get; }
1516

16-
[JsonPropertyName("uri")]
17+
[JsonIgnore]
1718
public Uri Uri { get; }
1819

20+
[JsonPropertyName("uri")]
21+
public string JsonUri
22+
{
23+
get
24+
{
25+
MaskedUri masked = Uri;
26+
return masked.ToString();
27+
}
28+
}
29+
1930
[JsonPropertyName("headers")]
2031
[JsonIgnoreEmptyCollection]
2132
public IDictionary<string, StringValues> Headers { get; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
#nullable enable
2+
Steeltoe.Management.Endpoint.Actuators.HttpExchanges.HttpExchangeRequest.JsonUri.get -> string!

src/Management/test/Endpoint.Test/Actuators/HttpExchanges/HttpExchangesActuatorTest.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public async Task Endpoint_returns_expected_data_without_filters(HostBuilderType
183183
},
184184
"request": {
185185
"method": "GET",
186-
"uri": "http://api.test.com:8080/path/to/data?filter=A",
186+
"uri": "http://****:****@api.test.com:8080/path/to/data?filter=A",
187187
"headers": {
188188
"Accept": [
189189
"application/json"
@@ -250,7 +250,7 @@ public async Task Endpoint_returns_expected_data_with_filters()
250250
"timestamp": "2025-01-01T21:18:43Z",
251251
"request": {
252252
"method": "GET",
253-
"uri": "http://api.test.com:8080/"
253+
"uri": "http://****:****@api.test.com:8080/"
254254
},
255255
"response": {
256256
"status": 200
@@ -301,7 +301,7 @@ public async Task Configured_header_names_are_case_insensitive()
301301
"timestamp": "2025-01-01T21:18:43Z",
302302
"request": {
303303
"method": "POST",
304-
"uri": "http://localhost:80/",
304+
"uri": "http://localhost/",
305305
"headers": {
306306
"X-Whitelisted-Request-Header": [
307307
"visible-request-header-value"
@@ -366,7 +366,7 @@ public async Task Respects_maximum_queue_capacity()
366366
"timestamp": "2024-09-19T00:00:25",
367367
"request": {
368368
"method": "GET",
369-
"uri": "http://localhost:80/id/25"
369+
"uri": "http://localhost/id/25"
370370
},
371371
"response": {
372372
"status": 200
@@ -376,7 +376,7 @@ public async Task Respects_maximum_queue_capacity()
376376
"timestamp": "2024-09-19T00:00:24",
377377
"request": {
378378
"method": "GET",
379-
"uri": "http://localhost:80/id/24"
379+
"uri": "http://localhost/id/24"
380380
},
381381
"response": {
382382
"status": 200
@@ -386,7 +386,7 @@ public async Task Respects_maximum_queue_capacity()
386386
"timestamp": "2024-09-19T00:00:23",
387387
"request": {
388388
"method": "GET",
389-
"uri": "http://localhost:80/id/23"
389+
"uri": "http://localhost/id/23"
390390
},
391391
"response": {
392392
"status": 200
@@ -396,7 +396,7 @@ public async Task Respects_maximum_queue_capacity()
396396
"timestamp": "2024-09-19T00:00:22",
397397
"request": {
398398
"method": "GET",
399-
"uri": "http://localhost:80/id/22"
399+
"uri": "http://localhost/id/22"
400400
},
401401
"response": {
402402
"status": 200
@@ -406,7 +406,7 @@ public async Task Respects_maximum_queue_capacity()
406406
"timestamp": "2024-09-19T00:00:21",
407407
"request": {
408408
"method": "GET",
409-
"uri": "http://localhost:80/id/21"
409+
"uri": "http://localhost/id/21"
410410
},
411411
"response": {
412412
"status": 200
@@ -467,7 +467,7 @@ public async Task Can_change_configuration_at_runtime()
467467
"timestamp": "2024-09-19T00:00:02",
468468
"request": {
469469
"method": "GET",
470-
"uri": "http://localhost:80/id/2"
470+
"uri": "http://localhost/id/2"
471471
},
472472
"response": {
473473
"status": 200
@@ -477,7 +477,7 @@ public async Task Can_change_configuration_at_runtime()
477477
"timestamp": "2024-09-19T00:00:01",
478478
"request": {
479479
"method": "GET",
480-
"uri": "http://localhost:80/id/1"
480+
"uri": "http://localhost/id/1"
481481
},
482482
"response": {
483483
"status": 200
@@ -514,7 +514,7 @@ public async Task Can_change_configuration_at_runtime()
514514
"timestamp": "2024-09-19T00:00:01",
515515
"request": {
516516
"method": "GET",
517-
"uri": "http://localhost:80/id/1?q=test-query-string"
517+
"uri": "http://localhost/id/1?q=test-query-string"
518518
},
519519
"response": {
520520
"status": 200
@@ -524,7 +524,7 @@ public async Task Can_change_configuration_at_runtime()
524524
"timestamp": "2024-09-19T00:00:02",
525525
"request": {
526526
"method": "GET",
527-
"uri": "http://localhost:80/id/2?q=test-query-string"
527+
"uri": "http://localhost/id/2?q=test-query-string"
528528
},
529529
"response": {
530530
"status": 200
@@ -549,7 +549,7 @@ private static HttpExchange CreateTestHttpExchange()
549549
["X-Redacted-Response-Header"] = "Redact-Me"
550550
};
551551

552-
var request = new HttpExchangeRequest("GET", new Uri("http://api.test.com:8080/path/to/data?filter=A"), requestHeaders, "192.168.0.1");
552+
var request = new HttpExchangeRequest("GET", new Uri("http://johndoe:secret@api.test.com:8080/path/to/data?filter=A"), requestHeaders, "192.168.0.1");
553553
var response = new HttpExchangeResponse((int)HttpStatusCode.OK, responseHeaders);
554554

555555
return new HttpExchange(request, response, 1.January(2025).At(21, 18, 43).AsUtc(), new HttpExchangePrincipal("test-user"),

0 commit comments

Comments
 (0)