在CheckMarx 9中显示严重性问题,用于日志锻造

发布于 2025-02-13 13:10:23 字数 1177 浏览 2 评论 0原文

以下是我的代码

private String getCorrelationId(HttpServletRequest request) {
    String correlationId = null;        
    String valuesList = request.getHeader(CORRELATION_ID_HEADER);       
    String valueLists = StringEscapeUtils.escapeJava(valuesList);
    if (valueLists != null && !valueLists.isEmpty()) {
        correlationId = valueLists;
    }
    return correlationId;
}



private void startTransaction(HttpServletRequest request, String serviceName, Object... args) {
    String correlationId = getCorrelationId(request);
    String correlationIds = StringEscapeUtils.escapeJava(correlationId);                        
    if (correlationIds == null || correlationIds.isEmpty()) {
        logger.info(LOG_SERVICE_TYPE + serviceName + args);
    } else {
        logger.error(LOG_SERVICE_TYPE , serviceName , correlationIds , args);
    }
}

收到的错误

方法getCorrelationId从元素getheader获取用户输入。该元素的值在代码中流过,而不会得到正确的消毒或验证,并最终用于编写startertransaction中的审核日志。 这可能启用 log forging

我已经浏览了一些Google链接,但无法理解。任何帮助将不胜感激

This below is my code

private String getCorrelationId(HttpServletRequest request) {
    String correlationId = null;        
    String valuesList = request.getHeader(CORRELATION_ID_HEADER);       
    String valueLists = StringEscapeUtils.escapeJava(valuesList);
    if (valueLists != null && !valueLists.isEmpty()) {
        correlationId = valueLists;
    }
    return correlationId;
}



private void startTransaction(HttpServletRequest request, String serviceName, Object... args) {
    String correlationId = getCorrelationId(request);
    String correlationIds = StringEscapeUtils.escapeJava(correlationId);                        
    if (correlationIds == null || correlationIds.isEmpty()) {
        logger.info(LOG_SERVICE_TYPE + serviceName + args);
    } else {
        logger.error(LOG_SERVICE_TYPE , serviceName , correlationIds , args);
    }
}

Error Received

Method getCorrelationId gets user input from element getHeader. This element’s value flows through the code without being properly sanitized or validated, and is eventually used in writing an audit log in startTransaction.
This may enable Log Forging.

I have gone through some google links but not able to understand. any help would be appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

童话 2025-02-20 13:10:24

对此很抱歉。

  1. htmlutils.htmlescape - >不工作
  2. stringscapeutils.escapejava - > 无法工作

最终

  1. 字符串cleanCorrelationId = correlationId.replace('\ t','_')。替换('\ n','_')。替换('\ r','_');

并将“ CleanCorrelationId”放置在日志记录中,logForging从Checkmarks报告解决的问题。

非常感谢@zvi Rosenfeld和@erickson

Sorry on late answer on this..I have made many attempts to resolve this for checkmarks report here below.

  1. HtmlUtils.htmlEscape -> not worked
  2. StringEscapeUtils.escapeJava -> not worked

finally

  1. String cleanCorrelationId = correlationId.replace('\t', '_').replace('\n', '_').replace('\r', '_');

and placed "cleanCorrelationId" in logging and LogForging issue resolved from checkmarks report.

Many thanks @Zvi Rosenfeld and @erickson

酷到爆炸 2025-02-20 13:10:24

当攻击者可以控制写入日志的字符串时(在这种情况下为“相关性”)时,就会发生日志锻造。
有2种危险:

  1. 他们可以通过更改日志来隐藏自己的曲目(例如,添加一条新线条,说他们记录了下来)。
  2. 很多时候,日志是通过监视工具加载的。攻击者可以向日志注入命令或XSS,希望工具很脆弱,并将运行它们。

您可以阅读有关它的更多信息在这里

在您的情况下,最好的解决方案可能是验证相关性为预期的格式(假设coloreLationId formant不包含任何特殊字符。如果剂量剂量,则应禁止它们)。

Log Forging happens when an attacker can control a string that's written to the log (the "correlationId" in this case).
There are 2 dangers with this:

  1. They can hide their tracks by changing the log (say, by adding a new line that says that they logged out).
  2. Many times logs are loaded by monitoring tools. The attacker can inject a command or XSS to the log, hoping that the tools are vulnerable, and will run them.

You can read more about it here.

In your case, the best solution would probably be to validate that the correlationId is in the expected format (assuming that the correlationId formant doesn't contain any specials characters. If it dose you should disallow them).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文