We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
正则表达式(Regex)经常遭受拒绝服务(DOS)攻击(称为ReDOS),根据特定的正则表达式定义,当分析某些字符串时,正则表达式引擎可能会花费大量时间甚至导致宕机。
脆弱代码:
符号 | 符号 [] 符号 + 三者联合使用可能受到 ReDOS 攻击: 表达式: (\d+|[1A])+z 需求: 会匹配任意数字或任意(1或A)字符串加上字符z 匹配字符串: 111111111 (10 chars) 计算步骤数: 46342 如果两个重复运算符过近,那么有可能收到攻击。请看以下例子: 例子1: 表达式: .*\d+\.jpg 需求: 会匹配任意字符加上数字加上.jpg 匹配字符串: 1111111111111111111111111 (25 chars) 计算步骤数: 9187 例子2: 表达式: .*\d+.*a 需求: 会匹配任意字符串加上数字加上任意字符串加上a字符 匹配字符串: 1111111111111111111111111 (25 chars) 计算步骤数: 77600 最典型的例子,重复运算符嵌套: 表达式: ^(a+)+$ 处理 aaaaaaaaaaaaaaaaX 将使正则表达式引擎分析65536个不同的匹配路径。
解决方案:
对正则表达式处理的内容应进行长度限制 消除正则表达式的歧义,避免重复运算符嵌套。例如表达式^(a+)+$应替换成^a+$
The text was updated successfully, but these errors were encountered:
No branches or pull requests
正则表达式(Regex)经常遭受拒绝服务(DOS)攻击(称为ReDOS),根据特定的正则表达式定义,当分析某些字符串时,正则表达式引擎可能会花费大量时间甚至导致宕机。
脆弱代码:
解决方案:
对正则表达式处理的内容应进行长度限制
消除正则表达式的歧义,避免重复运算符嵌套。例如表达式^(a+)+$应替换成^a+$
The text was updated successfully, but these errors were encountered: