Skip to content

Commit 971322e

Browse files
claudiamurialdoclaudiamurialdo
andauthored
CodeQL: Sanitize log entries created from user input (#1203)
Co-authored-by: claudiamurialdo <c.murialdo@globant.com>
1 parent ad381bc commit 971322e

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

dotnet/src/dotnetframework/GxClasses/Core/GXApplication.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3721,7 +3721,7 @@ internal string ClientTimeZoneId
37213721
if (!DateTimeUtil.ValidTimeZone(sTZ))
37223722
{
37233723
sTZ = (string)GetUndecodedCookie(GX_REQUEST_TIMEZONE);
3724-
GXLogging.Debug(Logger, "Try reading undecoded ClientTimeZone GX_REQUEST_TIMEZONE cookie:", sTZ);
3724+
GXLogging.DebugSanitized(Logger, "Try reading undecoded ClientTimeZone GX_REQUEST_TIMEZONE cookie:", sTZ);
37253725
}
37263726
try
37273727
{
@@ -3733,7 +3733,7 @@ internal string ClientTimeZoneId
37333733
}
37343734
catch (Exception ex)//DateTimeZoneNotFound
37353735
{
3736-
GXLogging.Warn(Logger, $"Client timezone not found: {sTZ}", ex);
3736+
GXLogging.WarnSanitized(Logger, ex, $"Client timezone not found: {sTZ}");
37373737
}
37383738
_currentTimeZoneId = DateTimeZoneProviders.Tzdb.GetSystemDefault().Id;
37393739
GXLogging.Warn(Logger, $"Setting Client timezone to System default: {_currentTimeZoneId}");

dotnet/src/dotnetframework/GxClasses/Data/GXDataCommon.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ protected static byte[] GetBinary(string fileNameParm, bool dbBlob)
940940
}
941941
break;
942942
default:
943-
GXLogging.Error(log, "Schema not supported: ", fileName);
943+
GXLogging.WarnSanitized(log, "Schema not supported: ", fileName);
944944
break;
945945
}
946946
GXLogging.Debug(log, "GetBinary fileName ", uri.AbsolutePath, ",ReadBytes:", binary != null ? binary.Length.ToString() : "0");

dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,18 @@ internal static void WarnSanitized(IGXLogger log, string msg, params string[] li
844844
log.LogWarning(strBuilder.ToString());
845845
}
846846
}
847+
internal static void WarnSanitized(IGXLogger log, Exception ex, params string[] list)
848+
{
849+
if (log.IsDebugEnabled)
850+
{
851+
StringBuilder strBuilder = new StringBuilder();
852+
foreach (string parm in list)
853+
{
854+
strBuilder.Append(StringUtil.Sanitize(parm, StringUtil.LogUserEntryWhiteList));
855+
}
856+
log.LogWarning(ex, strBuilder.ToString());
857+
}
858+
}
847859
public static void Warn(IGXLogger logger, string msg, params string[] list)
848860
{
849861
if (logger != null)

0 commit comments

Comments
 (0)