Skip to content

Commit cc451c3

Browse files
feat(dotnet): masking (#1074)
| 🚥 Resolves [RM-8742](https://linear.app/readme-io/issue/RM-8742) | | :------------------- | ## 🧰 Changes Adds sensitive data masking to the Dotnet SDK The logic is the same as we will have in Python SDK (PR #955)
1 parent b24b2d8 commit cc451c3

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ cleanup-failure:
1616
test-metrics-dotnet: ## Run Metrics tests against the .NET SDK
1717
docker compose up --build --detach integration_dotnet_metrics_v6.0
1818
sleep 5
19-
npm run test:integration-metrics || make cleanup-failure
19+
SUPPORTS_HASHING=true npm run test:integration-metrics || make cleanup-failure
2020
@make cleanup
2121

2222
test-webhooks-dotnet: ## Run webhooks tests against the .NET SDK
2323
docker compose up --build --detach integration_dotnet_webhooks_v6.0
24-
npm run test:integration-webhooks || make cleanup-failure
24+
SUPPORTS_HASHING=true npm run test:integration-webhooks || make cleanup-failure
2525
@make cleanup
2626

2727
##

packages/dotnet/ReadMe/HarJsonTranslationLogics/HarJsonBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public async Task<string> BuildHar()
4444
private Group BuildGroup()
4545
{
4646
Group group = new Group();
47-
group.id = this.configValues.group.id;
47+
group.id = MaskHelper.Mask(this.configValues.group.id);
4848
group.label = this.configValues.group.label;
4949
group.email = this.configValues.group.email;
5050
return group;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Security.Cryptography;
3+
using System.Text;
4+
5+
public static class MaskHelper
6+
{
7+
public static string Mask(string data)
8+
{
9+
using (SHA512 sha512 = SHA512.Create())
10+
{
11+
byte[] hashBytes = sha512.ComputeHash(Encoding.UTF8.GetBytes(data));
12+
string base64Hash = Convert.ToBase64String(hashBytes);
13+
string opts = data.Length >= 4 ? data.Substring(data.Length - 4) : data;
14+
return $"sha512-{base64Hash}?{opts}";
15+
}
16+
}
17+
}

packages/dotnet/ReadMe/HarJsonTranslationLogics/RequestProcessor.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,31 +145,25 @@ private List<Headers> GetHeaders()
145145
{
146146
foreach (var reqHeader in this.request.Headers)
147147
{
148+
Headers header = new Headers();
149+
header.name = reqHeader.Key;
150+
header.value = reqHeader.Key == "Authorization" ? MaskHelper.Mask(reqHeader.Value) : reqHeader.Value.ToString();
148151
if (!this.configValues.options.isAllowListEmpty)
149152
{
150153
if (this.CheckAllowList(reqHeader.Key))
151154
{
152-
Headers header = new Headers();
153-
header.name = reqHeader.Key;
154-
header.value = reqHeader.Value;
155155
headers.Add(header);
156156
}
157157
}
158158
else if (!this.configValues.options.isDenyListEmpty)
159159
{
160160
if (!this.CheckDenyList(reqHeader.Key))
161161
{
162-
Headers header = new Headers();
163-
header.name = reqHeader.Key;
164-
header.value = reqHeader.Value;
165162
headers.Add(header);
166163
}
167164
}
168165
else
169166
{
170-
Headers header = new Headers();
171-
header.name = reqHeader.Key;
172-
header.value = reqHeader.Value;
173167
headers.Add(header);
174168
}
175169
}

0 commit comments

Comments
 (0)