Asymmetric denial of service - ReDoS
Description
Within the source code there is evidence of the use of dangerous regular expressions, because they make use of complex operations to find matches, which can lead to an attacker sending a specific string of data that could cause the server to crash when evaluating the string with the dangerous regular expression.
Impact
Generate server crash.
Recommendation
Use optimized regular expressions to perform functions without much computational overhead.
Threat
Anonymous attacker from the Internet.
Expected Remediation Time
⌚ 60 minutes.
Score
Default score using CVSS 3.1. It may change depending on the context of the vulnerability.
Base
- Attack vector: N
- Attack complexity: L
- Privileges required: N
- User interaction: N
- Scope: U
- Confidentiality: N
- Integrity: N
- Availability: L
Temporal
- Exploit code madurity: U
- Remediation level: X
- Report confidence: R
Result
- Vector string: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L/E:U/RL:X/RC:R
- Score:
- Base: 5.3
- Temporal: 4.7
- Severity:
- Base: Medium
- Temporal: Medium
Code Examples
Compliant code
The application simplifies the regular expressions used to compare input strings
using System.Text.RegularExpressions;
//use standard regex to verify and sanitize input
namespace Controllers {
public class Controller : Controller {
public IActionResult Validate(string regex, string input) {
var expreg = ^\+[0-9]{11};
Regex reg = new Regex(pat, RegexOptions.IgnoreCase);
bool match = reg.IsMatch(input, reg.Escape(regex));
}
}
}
Non compliant code
Complex regular expressions can cause a server overload
using System.Text.RegularExpressions;
namespace Controllers {
public class Controller : Controller {
public IActionResult Validate(string regex, string input) {
var expreg = "^(http|https|ftp):[\/]{2}([a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4})(:[0-9]+)?\/?([a-zA-Z0-9\-\._\?\,\'\/\\+&%\$#\=~]*);
Regex reg = new Regex(pat, RegexOptions.IgnoreCase);
bool match2 = reg.IsMatch(input, expreg);
}
}
}
Example where the application uses unverified input to search in regex
using System;
using System.Text.RegularExpressions;
public partial class WebForm : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
string findTerm = Request.Form["findTerm"];
Match m = Regex.Match(SearchableText, "^term=" + findTerm);
}
}
Requirements
Search for vulnerabilities in your apps for free with our automated security testing! Start your 21-day free trial and discover the benefits of our Continuous Hacking Machine Plan. If you prefer a full service that includes the expertise of our ethical hackers, don't hesitate to contact us for our Continuous Hacking Squad Plan.