codeskyblue / codeskyblue/go-reactjs-example

Potential ReDoS Vulnerability or Inefficient Regular Expression in Project: Need for Assessment and Mitigation

未关闭
#2 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Go
星标
57
派生
15
PR 合并指标
30 天内没有已合并 PR

描述

Hello,

I am writing to report a potential Regular Expression Denial of Service (ReDoS) vulnerability or Inefficient Regular Expression in the project. This issue arises when specially crafted input strings are used in the context of distributed, high-volume requests, potentially leading to a denial-of-service attack.

**Location of Issue:**

The vulnerability is related to a regular expression used in the following validation file, which may result in significantly prolonged execution times under certain conditions.

https://github.com/codeskyblue/go-reactjs-example/blob/e5500094cb05566980f6282e8826b065a411a9f5/vendor/github.com/Unknwon/com/html.go#L47

**PoC Files and Comparisons:**

```go
// Proof of concept
filename := os.Args[1]
content, err := ioutil.ReadFile(filename)
re := regexp.MustCompile("(?s)<(?:style|script)[^<>]*>.*?|]*>|")
re.ReplaceAllString(string(content), "")
```

PoC Files Here:
[poc.zip](https://github.com/codeskyblue/go-reactjs-example/files/15400553/poc.zip)

To evaluate the performance of this inefficient regular expression matching with varying input contents, the following commands can be executed within the PoC folder:

```bash
time ./poc AttackString10MB.txt
# real 72m38.173s
# user 72m30.083s
# sys 0m5.653s
time ./poc RandomString10MB.txt
# real 0m0.029s
# user 0m0.016s
# sys 0m0.026s
time ./poc AttackString1MB.txt
# real 0m54.028s
# user 0m53.917s
# sys 0m0.088s
time ./poc RandomString1MB.txt
# real 0m0.011s
# user 0m0.007s
# sys 0m0.011s
```

The significant difference in processing time between random strings and malicious strings highlights the potential effectiveness of this regex for malicious exploitation. And as string length grows, the nonlinear increase in processing time reflects potentially greater risks.

**Proposed Solution:**

A possible mitigation strategy could include limiting the input length to prevent excessive processing times. If the corresponding function or feature is not in use, it is recommended to clean up risky third-party packages or code content to prevent malicious exploitation through methods such as code injection.

**Additional Considerations:**

Historically, it was believed that using regex engines with non-backtracking implementations (such as those in Rust or Go) would not lead to ReDoS vulnerabilities. However, recent studies have shown that this is not always the case. I recommend an assessment of how this issue might impact this project.

Thank you for your attention to this matter. Your evaluation and response to this potential security concern would be greatly appreciated.

Best regards,

贡献指南

这个仓库没有索引到贡献指南

调研方向

检查 vendor/github.com/Unknwon/com/html.go 第 47 行附近的代码,然后使用提供的 PoC 对 AttackString10MB.txt、RandomString10MB.txt、AttackString1MB.txt 和 RandomString1MB.txt 运行测试。比较计时结果,并追踪项目是否使用了此验证路径;完成标准是记录影响并确定适当的缓解措施,或确认该代码未被使用。

由索引模型根据 Issue 内容生成。

评估

技术栈
go
领域
backend, security
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。