From 12db1917215366ca3b34898393c61f2e5318c8e3 Mon Sep 17 00:00:00 2001 From: Andrii Andreiev <129078694+AndriiAndreiev@users.noreply.github.com> Date: Tue, 10 Sep 2024 15:58:38 +0300 Subject: [PATCH 1/3] add hash masking for group.id and Authorization header --- Makefile | 4 ++-- .../HarJsonTranslationLogics/HarJsonBuilder.cs | 2 +- .../HarJsonTranslationLogics/MaskHelper.cs | 17 +++++++++++++++++ .../RequestProcessor.cs | 14 ++++---------- 4 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 packages/dotnet/ReadMe/HarJsonTranslationLogics/MaskHelper.cs diff --git a/Makefile b/Makefile index 11da6ad495..c8104ad270 100644 --- a/Makefile +++ b/Makefile @@ -16,12 +16,12 @@ cleanup-failure: test-metrics-dotnet: ## Run Metrics tests against the .NET SDK docker compose up --build --detach integration_dotnet_metrics_v6.0 sleep 5 - npm run test:integration-metrics || make cleanup-failure + SUPPORTS_HASHING=true npm run test:integration-metrics || make cleanup-failure @make cleanup test-webhooks-dotnet: ## Run webhooks tests against the .NET SDK docker compose up --build --detach integration_dotnet_webhooks_v6.0 - npm run test:integration-webhooks || make cleanup-failure + SUPPORTS_HASHING=true npm run test:integration-webhooks || make cleanup-failure @make cleanup ## diff --git a/packages/dotnet/ReadMe/HarJsonTranslationLogics/HarJsonBuilder.cs b/packages/dotnet/ReadMe/HarJsonTranslationLogics/HarJsonBuilder.cs index 2e2a277769..32a0d105aa 100644 --- a/packages/dotnet/ReadMe/HarJsonTranslationLogics/HarJsonBuilder.cs +++ b/packages/dotnet/ReadMe/HarJsonTranslationLogics/HarJsonBuilder.cs @@ -44,7 +44,7 @@ public async Task BuildHar() private Group BuildGroup() { Group group = new Group(); - group.id = this.configValues.group.id; + group.id = MaskHelper.Mask(this.configValues.group.id); group.label = this.configValues.group.label; group.email = this.configValues.group.email; return group; diff --git a/packages/dotnet/ReadMe/HarJsonTranslationLogics/MaskHelper.cs b/packages/dotnet/ReadMe/HarJsonTranslationLogics/MaskHelper.cs new file mode 100644 index 0000000000..ebc54a8765 --- /dev/null +++ b/packages/dotnet/ReadMe/HarJsonTranslationLogics/MaskHelper.cs @@ -0,0 +1,17 @@ +using System; +using System.Security.Cryptography; +using System.Text; + +public static class MaskHelper +{ + public static string Mask(string data) + { + using (SHA512 sha512 = SHA512.Create()) + { + byte[] hashBytes = sha512.ComputeHash(Encoding.UTF8.GetBytes(data)); + string base64Hash = Convert.ToBase64String(hashBytes); + string opts = data.Length >= 4 ? data.Substring(data.Length - 4) : data; + return $"sha512-{base64Hash}?{opts}"; + } + } +} \ No newline at end of file diff --git a/packages/dotnet/ReadMe/HarJsonTranslationLogics/RequestProcessor.cs b/packages/dotnet/ReadMe/HarJsonTranslationLogics/RequestProcessor.cs index 1f76a5d637..ed2f3aa909 100644 --- a/packages/dotnet/ReadMe/HarJsonTranslationLogics/RequestProcessor.cs +++ b/packages/dotnet/ReadMe/HarJsonTranslationLogics/RequestProcessor.cs @@ -145,13 +145,13 @@ private List GetHeaders() { foreach (var reqHeader in this.request.Headers) { + Headers header = new Headers(); + header.name = reqHeader.Key; + header.value = reqHeader.Key == "Authorization" ? MaskHelper.Mask(reqHeader.Value) : reqHeader.Value.ToString(); if (!this.configValues.options.isAllowListEmpty) { if (this.CheckAllowList(reqHeader.Key)) { - Headers header = new Headers(); - header.name = reqHeader.Key; - header.value = reqHeader.Value; headers.Add(header); } } @@ -159,17 +159,11 @@ private List GetHeaders() { if (!this.CheckDenyList(reqHeader.Key)) { - Headers header = new Headers(); - header.name = reqHeader.Key; - header.value = reqHeader.Value; headers.Add(header); } } else { - Headers header = new Headers(); - header.name = reqHeader.Key; - header.value = reqHeader.Value; headers.Add(header); } } @@ -227,4 +221,4 @@ private List GetCookies() return cookies; } } -} +} \ No newline at end of file From 59adf6ff2bdce6869aebe0075d851d95cbff2a1a Mon Sep 17 00:00:00 2001 From: Andrii Andreiev <129078694+AndriiAndreiev@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:10:45 +0300 Subject: [PATCH 2/3] fix warning --- .../dotnet/ReadMe/HarJsonTranslationLogics/RequestProcessor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dotnet/ReadMe/HarJsonTranslationLogics/RequestProcessor.cs b/packages/dotnet/ReadMe/HarJsonTranslationLogics/RequestProcessor.cs index ed2f3aa909..df7842d88f 100644 --- a/packages/dotnet/ReadMe/HarJsonTranslationLogics/RequestProcessor.cs +++ b/packages/dotnet/ReadMe/HarJsonTranslationLogics/RequestProcessor.cs @@ -147,7 +147,7 @@ private List GetHeaders() { Headers header = new Headers(); header.name = reqHeader.Key; - header.value = reqHeader.Key == "Authorization" ? MaskHelper.Mask(reqHeader.Value) : reqHeader.Value.ToString(); + header.value = reqHeader.Key == "Authorization" ? MaskHelper.Mask(reqHeader.Value) : reqHeader.Value.ToString(); if (!this.configValues.options.isAllowListEmpty) { if (this.CheckAllowList(reqHeader.Key)) From ef8b50be8015e7ddfc9d6e381032a1de188ffae4 Mon Sep 17 00:00:00 2001 From: Andrii Andreiev <129078694+AndriiAndreiev@users.noreply.github.com> Date: Tue, 17 Sep 2024 13:47:46 +0300 Subject: [PATCH 3/3] (fix formatting) --- packages/dotnet/ReadMe/HarJsonTranslationLogics/MaskHelper.cs | 2 +- .../dotnet/ReadMe/HarJsonTranslationLogics/RequestProcessor.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/dotnet/ReadMe/HarJsonTranslationLogics/MaskHelper.cs b/packages/dotnet/ReadMe/HarJsonTranslationLogics/MaskHelper.cs index ebc54a8765..04219e8ede 100644 --- a/packages/dotnet/ReadMe/HarJsonTranslationLogics/MaskHelper.cs +++ b/packages/dotnet/ReadMe/HarJsonTranslationLogics/MaskHelper.cs @@ -14,4 +14,4 @@ public static string Mask(string data) return $"sha512-{base64Hash}?{opts}"; } } -} \ No newline at end of file +} diff --git a/packages/dotnet/ReadMe/HarJsonTranslationLogics/RequestProcessor.cs b/packages/dotnet/ReadMe/HarJsonTranslationLogics/RequestProcessor.cs index df7842d88f..b14b0da1b4 100644 --- a/packages/dotnet/ReadMe/HarJsonTranslationLogics/RequestProcessor.cs +++ b/packages/dotnet/ReadMe/HarJsonTranslationLogics/RequestProcessor.cs @@ -221,4 +221,4 @@ private List GetCookies() return cookies; } } -} \ No newline at end of file +}