简体   繁体   English

CloudLoggerFactory的Sanitized Logger显示了Veracode Scan中的CRLF Injection漏洞

[英]CloudLoggerFactory's Sanitized Logger shows CRLF Injection vulnerability in Veracode Scan

We are using S4 SDK's CloudLoggerFactory to log exceptions throughout our application. 我们使用S4 SDK的CloudLoggerFactory来记录整个应用程序中的异常。 For a class "SampleClass", we create a logger like this: 对于“SampleClass”类,我们创建一个这样的记录器:

private static final Logger logger = CloudLoggerFactory.getSanitizedLogger(SampleClass.class, "(END)");

and call it for an Exception e: 并将其称为例外e:

    logger.error(e.getMessage(), e);

A Veracode scan has shown this logging line to be vulnerable to CLRF Injection. Veracode扫描显示此日志记录行易受CLRF注入攻击。 To my understanding, the getSanitizedLogger in conjunction with the "(END)" argument should solve this issue. 据我所知,getSanitizedLogger与“(END)”参数一起解决了这个问题。 Can you provide some insight into this matter, please? 你能提供一些有关这个问题的见解吗?

Thank you in advance! 先感谢您!

Update: As Sander mentioned in his answer below we dropped the CloudLoggerFactory starting with version 3.0.0 of the SAP Cloud SDK. 更新:正如Sander在下面的回答中提到的,我们从SAP Cloud SDK 3.0.0版开始删除了CloudLoggerFactory

Our reasoning behind this is that we cannot change the used Logger implementation of every library our consumers might use in their application. 我们的理由是,我们无法更改消费者可能在其应用程序中使用的每个库的已使用Logger实现。 This means we are not able to add the token mentioned below to all log messages of the consumer, which reduces its effectiveness tremendously. 这意味着我们无法将下面提到的令牌添加到消费者的所有日志消息中,这极大地降低了其效率。

Therefore we decided to drop the CloudLoggerFactory and advise the consumer to configure his logging implementation in a such way, that this token is automatically added. 因此,我们决定放弃CloudLoggerFactory并建议消费者以这种方式配置他的日志记录实现,以便自动添加此令牌。 On this level it is possible to have this token at the end of every log message, allowing for automated tests on forged logs. 在此级别上,可以在每条日志消息的末尾都有此令牌,允许对伪造日志进行自动测试。


What the sanitized logger is supposed to do is making log forging identifiable. 清理过的记录器应该做的是使日志锻造可识别。 To allow this it does the following: 为此,它执行以下操作:

  • This logger has your provided class ( SampleClass.class in your case) as the logger name. 此记录器具有您提供的类(在您的情况下为SampleClass.class )作为记录器名称。 This name will be placed in the printed output depending on the configuration of your logger implementation. 此名称将放置在打印输出中,具体取决于记录器实现的配置。 This is the default behavior of SLF4J. 这是SLF4J的默认行为。

  • Add (END OF LOG ENTRY) (or your provided token) at the end of every log message created with this logger. 在使用此记录器创建的每条日志消息的末尾添加(END OF LOG ENTRY) (或您提供的令牌)。 If this token is encountered in your log message it is replaced with (MESSAGE MIGHT BE FORGED!) , as that would be an indicator that some input tried to tamper with your log messages. 如果在您的日志消息中遇到此令牌,则会替换为(MESSAGE MIGHT BE FORGED!) ,因为这将指示某些输入试图篡改您的日志消息。

Both of these properties allow you to identify whether a log message is actually valid or was created via Log Forging. 这两个属性都允许您识别日志消息是否实际有效或是否通过Log Forging创建。

To see that have a look at the following example, at first with the "unsanitized" logger: 要查看以下示例,首先使用“unsanitized”记录器:

final Logger logger = CloudLoggerFactory.getLogger(SampleClass.class);

logger.error("Some valid first message");
logger.info("Something still valid\n[main] ERROR very.important.class Major Database Error!");
logger.error("Some valid last message");

On my machine the output of this looks like 在我的机器上,输出看起来像

[main] ERROR com.sap.sandbox.SampleClass - Some valid first message
[main] INFO com.sap.sandbox.SampleClass - Something still valid
[main] ERROR very.important.class Major Database Error!
[main] ERROR com.sap.sandbox.SampleClass - Some valid last message

So there is no chance to identify that something is wrong with those messages. 因此,没有机会确定这些消息有问题。

Therefore, if you use CloudLoggerFactory.getSanitizedLogger instead of CloudLoggerFactory.getLogger you get the following log output: 因此,如果您使用CloudLoggerFactory.getSanitizedLogger而不是CloudLoggerFactory.getLogger则会获得以下日志输出:

[main] ERROR com.sap.sandbox.SampleClass - Some valid first message (END OF LOG ENTRY)
[main] INFO com.sap.sandbox.SampleClass - Something still valid
[main] ERROR very.important.class Major Database Error! (END OF LOG ENTRY)
[main] ERROR com.sap.sandbox.SampleClass - Some valid last message (END OF LOG ENTRY)

Here you can see that one of the messages from the SampleClass , which should actually end with the token, ends without one. 在这里,您可以看到SampleClass中的一条消息实际上以令牌结尾,但没有一条消息结束。 Therefore you can deduce that there is some error in the log and you need to investigate this issue further. 因此,您可以推断日志中存在一些错误,您需要进一步调查此问题。

So much for the Log Forging aspect, which is the actual attack the sanitized logger makes identifiable. 对于Log Forging方面来说太多了,这就是消毒后的记录器可识别的实际攻击。

Regarding the CLRF injection issue: This issue heavily depends on the further usage of the created log output: 关于CLRF注入问题:此问题在很大程度上取决于创建的日志输出的进一步使用:

  • If you store the log messages in a database there needs to be some way to prevent SQL injection. 如果将日志消息存储在数据库中,则需要某种方法来防止SQL注入。
  • If you watch the log files with a web-based log analyzer there needs to be some way to prevent XSS. 如果您使用基于Web的日志分析器查看日志文件,则需要某种方法来阻止XSS。
  • ... ...

If we would escape all of those potential use case it would make actually just reading the log files with an editor, which is imo the most common use case, much more complicated. 如果我们要逃避所有这些潜在的用例,它实际上只是用编辑器读取日志文件,这是最常见的用例,更复杂。

So you would need to decide whether for your case this is an actual issue or just a false positive. 所以你需要决定你的情况是实际问题还是误报。

Another point is that also all your other dependencies would need to escape their log messages for your use case. 另一点是,您的所有其他依赖项也需要为您的用例转义其日志消息。 This means an easier and overarching solution would be to configure that on the actual logger implementation, eg for Logback: https://logback.qos.ch/manual/layouts.html#replace . 这意味着更简单和最重要的解决方案是在实际的记录器实现上配置它,例如用于Logback: https ://logback.qos.ch/manual/layouts.html#replace。

Actually we plan to remove the log sanitizing feature in the upcoming major release. 实际上我们计划在即将发布的主要版本中删除日志清理功能。

We have come to the conclusion that it actually gives a false sense of security and that it should be addressed on the logger implementation level instead, which we cannot do on SDK level as we only rely on the Slf4j abstraction. 我们得出结论,它实际上给出了一种错误的安全感,并且应该在记录器实现级别上解决,而我们不能在SDK级别上执行,因为我们只依赖于Slf4j抽象。

(Disclaimer: I'm one of the SAP Cloud SDK developers.) (免责声明:我是SAP Cloud SDK开发人员之一。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM