【问题标题】:Remediating Veracode CWE ID 117 (Improper Output Neutralization for Logs) in VB.NET修复 VB.NET 中的 Veracode CWE ID 117(不正确的日志输出中和)
【发布时间】:2020-08-29 11:30:29
【问题描述】:

我有以下代码,如果我正确阅读了有关此主题的其他主题,则不应导致 Veracode 扫描标记 CWE 117,但确实如此。 Java/C# 还有其他一些“答案”,但我没有找到任何适用于 VB.NET 的东西。

我的代码是这样的:

    Public Function WriteToEventLog(ByVal Entry As String, Optional ByVal AppName As String = "adCoreLibrary", Optional ByVal EventType As EventLogEntryType = Nothing, Optional ByVal LogName As String = "Application", Optional ByVal EventID As Integer = 0, Optional ByVal TaskCategory As TaskCategory = 0) As Boolean

    Dim objEventLog As New EventLog()

    Try
        ' We will try and create our own event log but if not, use the optional default 
        If Not EventLog.SourceExists(AppName) Then
            EventLog.CreateEventSource(AppName, LogName)
        End If

        ' Initialise event log
        objEventLog.BeginInit()

        ' Set the source
        objEventLog.Source = AppName

        ' Write entry
        If Entry IsNot Nothing Then
            ' THE FOLLOWING LINE IS BEING FLAGGED AS CWE-117 NON-COMPLIANT
            objEventLog.WriteEntry(Entry.Replace(vbLf, "_"c).Replace(vbCr, "_"c).Replace(vbTab, "_"c), EventType, EventID, CShort(TaskCategory))
        End If


        ' End initialisation
        objEventLog.EndInit()

        Return True
        Exit Function

    Catch ex As Exception
        If CType(My.Settings.adLogMode, LogMode) <> adCoreLogging.LogMode.Empty Then
            My.Application.Log.WriteEntry("An error occured when trying to write to the Windows Event Log: " & ex.Message.ToString)
            Return False
        End If
    Finally
    End Try

    ' If we get here, we've had a problem
    Return False

End Function

谁能告诉我我在这里做错了什么?

【问题讨论】:

  • 您是否尝试过应用 Java/C# 答案之一?
  • 这些答案让我添加了 Replace(vbLf, ""c).Replace(vbCr, ""c).Replace(vbTab, "_"c) 但那似乎没有补救。另外,我不擅长阅读 Java/C#

标签: vb.net veracode secure-coding


【解决方案1】:

好吧,对于任何偶然发现这一点的人......我找到了答案。

我不得不用以下有问题的行替换(在导入 System.Web 之后):

Dim newEntry As String = HttpUtility.HtmlEncode(Entry)
objEventLog.WriteEntry(newEntry, EventType, EventID, CShort(TaskCategory))

我不知道为什么 Veracode 允许这样做,因为它本质上仍然是相同的东西,但我们就是这样。

【讨论】:

    猜你喜欢
    • 2017-12-10
    • 1970-01-01
    • 2018-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-11
    • 2020-01-14
    • 1970-01-01
    相关资源
    最近更新 更多