1111using System . Collections . Generic ;
1212using System . Security . Cryptography . X509Certificates ;
1313using System . Net . Security ;
14- using Newtonsoft . Json ;
1514using System . Threading ;
1615using System . Runtime . CompilerServices ;
17- using Newtonsoft . Json . Linq ;
1816
1917namespace 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 )
0 commit comments