0

I need an regular expression to check whether a particular argument is in a floating point range.For ex i want the Param only in the range 0.01 to 999.9 . I have configured the below rule ,but it fails to work .

SecRule ARGS:Param "![0.01-999.9]" "deny,id:2200"

If the value of param is say 1000 it gets rejected which is correct , if the value of Param is 0 then its being accepted which should not be the case .Please let me know the exact way of configuring the regular expression for the same.

4

2 回答 2

1

这听起来像是一个商业逻辑规则——应该在服务器逻辑中完成,而不是通过 mod_security,但无论如何:

范围内[0..999.9]的浮点数是

  • 从可选的零序列开始(您可能允许也可能不允许)
  • 后跟最多三位数字,其中第一位不为零
  • 可选地后跟一个点,除了数字之外什么都没有(您可能要求最后一个数字至少有一个数字非零)
  • 999.9除了以可选零开头的数字
  • 除了999.9它本身是允许的(如果范围从右边包括在内)

限制最少的变体,编译成正则表达式:

^0*(?:(?!999\.9\d*$)\d{0,3}(?:\.\d*)?|999\.0*)$
  • ^- 字符串开头(不确定它是否由 mod-security 添加)
  • 0*- 0-n 个零
  • (?:...)- 非捕获组
    • (?!...)- 如果没有跟...
      • 999.\9- 字面意思999.9
      • \d*- 0-n 位数字和
      • $- 字符串的结尾
    • \d- 数字
    • {0,3}- 零到三倍
    • (?:...)- 非捕获组
      • \.- 字面意思.
      • \d*- 0-n 位数
    • ?- 可选的
    • |- 或者
    • 999\.9-999.9本身
    • 0*- 可选零
  • $- 字符串的结尾
于 2013-09-17T10:31:40.780 回答
1
(^0\.0?[1-9]\d*|^[1-9]{1,3}\.\d+)

第一个匹配替代匹配想要的数字小于一个,第二个匹配一个或更大但小于一千。不匹配不包含点的数字,并且匹配像 999.999 这样的数字,但前提是小于一千(我猜这就是你需要的)。

于 2013-09-17T10:32:08.407 回答