diff --git a/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf b/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf index 7033c7923..ddcd35672 100644 --- a/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf +++ b/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf @@ -78,7 +78,12 @@ SecRule REQUEST_LINE "!@rx ^(?i:(?:[a-z]{3,10}\s+(?:\w{3,7}?://[\w\-\./]*(?::\d+ # These rules check for the existence of the ' " ; = meta-characters in # either the file or file name variables. # HTML entities may lead to false positives, why they are allowed on PL1. -# Negative look behind assertions allow frequently used entities &_; +# Frequently used HTML entities such as ä are allowed. +# +# To be compatible with non-PCRE regex engines, negative lookbehinds are +# avoided. Instead the script in util/regexp-negativelookbehind was used to +# generate an alternative equivalent regex: +# ./negativelookbehind.py negativelookbehind-920120.data # # -=[ Targets, characters and html entities ]=- # @@ -90,13 +95,11 @@ SecRule REQUEST_LINE "!@rx ^(?i:(?:[a-z]{3,10}\s+(?:\w{3,7}?://[\w\-\./]*(?::\d+ # 920121: PL2 : FILES_NAMES, FILES # ['\";=] : ' " ; = meta-characters # -# Not supported by re2 (? 0: + charsInCommon = "".join(set(e2.remainder[k]) & set(e1.remainder[k])) + e2.remainder[k] = removeChars(e2.remainder[k], charsInCommon) + + # Remove duplicate expressions + exprsFiltered = [] + for i in range(len(exprs)): + e1 = exprs[i] + alreadyExists = False + for j in range(len(exprs)): + if i == j: + break + + e2 = exprs[j] + + sameC = set(e1.curChar) == set(e2.curChar) + sameR = True + for k in range(len(e1.remainder)): + if set(e1.remainder[k]) != set(e2.remainder[k]): + sameR = False + break + if sameC and sameR: + alreadyExists = True + break + + if not alreadyExists: + exprsFiltered.append(e1) + + allexprs.extend(exprsFiltered) + + suffixLength += 1 + continue + +out = "(?:\n" +for i in range(len(allexprs)): + e = allexprs[i] + out += ("(?:^|[^" + e.curChar + "])") + for c in e.remainder: + if len(c) > 1: + out += "[" + c + "]" + else: + out += c + if i != len(allexprs)-1: + out += "|" + out += "\n" +out += ")" + +print("Human readable:") +print(out) +print() +print("Single line:") +print(out.replace("\n","")) + + + +