11
11
using System . Collections . Generic ;
12
12
using System . Security . Cryptography . X509Certificates ;
13
13
using System . Net . Security ;
14
- using Newtonsoft . Json ;
15
14
using System . Threading ;
16
15
using System . Runtime . CompilerServices ;
17
- using Newtonsoft . Json . Linq ;
18
16
19
17
namespace KeyAuth
20
18
{
@@ -910,22 +908,19 @@ public static void LogEvent(string content)
910
908
911
909
try
912
910
{
913
- JObject jsonObject = JsonConvert . DeserializeObject < JObject > ( content ) ;
914
-
915
911
// 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" ) ;
925
920
926
921
using ( StreamWriter writer = File . AppendText ( logFilePath ) )
927
922
{
928
- writer . WriteLine ( $ "[{ DateTime . Now } ] [{ AppDomain . CurrentDomain . FriendlyName } ] { redactedContent } ") ;
923
+ writer . WriteLine ( $ "[{ DateTime . Now } ] [{ AppDomain . CurrentDomain . FriendlyName } ] { content } ") ;
929
924
}
930
925
}
931
926
catch ( Exception ex )
@@ -934,13 +929,12 @@ public static void LogEvent(string content)
934
929
}
935
930
}
936
931
937
- private static void RedactField ( JObject jsonObject , string fieldName )
932
+ private static string RedactField ( string content , string fieldName )
938
933
{
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 ) ;
944
938
}
945
939
946
940
public static void error ( string message )
0 commit comments