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..04219e8ede --- /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}"; + } + } +} diff --git a/packages/dotnet/ReadMe/HarJsonTranslationLogics/RequestProcessor.cs b/packages/dotnet/ReadMe/HarJsonTranslationLogics/RequestProcessor.cs index 1f76a5d637..b14b0da1b4 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); } }