Skip to content

Commit dfc309b

Browse files
Removed NewtonSoft.Json
1 parent e167bbc commit dfc309b

File tree

3 files changed

+14
-28
lines changed

3 files changed

+14
-28
lines changed

Form/KeyAuth.cs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
using System.Collections.Generic;
1212
using System.Security.Cryptography.X509Certificates;
1313
using System.Net.Security;
14-
using Newtonsoft.Json;
1514
using System.Threading;
1615
using System.Runtime.CompilerServices;
17-
using Newtonsoft.Json.Linq;
1816

1917
namespace KeyAuth
2018
{
@@ -910,22 +908,19 @@ public static void LogEvent(string content)
910908

911909
try
912910
{
913-
JObject jsonObject = JsonConvert.DeserializeObject<JObject>(content);
914-
915911
// Redact sensitive fields - Add more if you would like.
916-
RedactField(jsonObject, "sessionid");
917-
RedactField(jsonObject, "ownerid");
918-
RedactField(jsonObject, "app");
919-
RedactField(jsonObject, "secret");
920-
RedactField(jsonObject, "version");
921-
RedactField(jsonObject, "fileid");
922-
RedactField(jsonObject, "webhooks");
923-
RedactField(jsonObject, "nonce");
924-
string redactedContent = jsonObject.ToString(Newtonsoft.Json.Formatting.None);
912+
content = RedactField(content, "sessionid");
913+
content = RedactField(content, "ownerid");
914+
content = RedactField(content, "app");
915+
content = RedactField(content, "secret");
916+
content = RedactField(content, "version");
917+
content = RedactField(content, "fileid");
918+
content = RedactField(content, "webhooks");
919+
content = RedactField(content, "nonce");
925920

926921
using (StreamWriter writer = File.AppendText(logFilePath))
927922
{
928-
writer.WriteLine($"[{DateTime.Now}] [{AppDomain.CurrentDomain.FriendlyName}] {redactedContent}");
923+
writer.WriteLine($"[{DateTime.Now}] [{AppDomain.CurrentDomain.FriendlyName}] {content}");
929924
}
930925
}
931926
catch (Exception ex)
@@ -934,13 +929,12 @@ public static void LogEvent(string content)
934929
}
935930
}
936931

937-
private static void RedactField(JObject jsonObject, string fieldName)
932+
private static string RedactField(string content, string fieldName)
938933
{
939-
JToken token;
940-
if (jsonObject.TryGetValue(fieldName, out token))
941-
{
942-
jsonObject[fieldName] = "REDACTED";
943-
}
934+
string pattern = $"\"{fieldName}\":\"[^\"]*\"";
935+
string replacement = $"\"{fieldName}\":\"REDACTED\"";
936+
937+
return System.Text.RegularExpressions.Regex.Replace(content, pattern, replacement);
944938
}
945939

946940
public static void error(string message)

Form/Loader.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
<PropertyGroup />
3636
<PropertyGroup />
3737
<ItemGroup>
38-
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
39-
<HintPath>packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
40-
</Reference>
4138
<Reference Include="PresentationFramework" />
4239
<Reference Include="System" />
4340
<Reference Include="System.Design" />
@@ -73,7 +70,6 @@
7370
</ItemGroup>
7471
<ItemGroup>
7572
<None Include="App.config" />
76-
<None Include="packages.config" />
7773
</ItemGroup>
7874
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7975
</Project>

Form/packages.config

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)