Operators
This section documents the operators currently available in ModSecurity.
ModSecurity v2 and libModSecurity v3 both look operator names up case-insensitively (@ipmatch, @ipMatch and @IPMATCH all resolve to the same operator); the spellings below are the documented ones.
beginsWith
Returns true if the parameter string is found at the beginning of the input. Macro expansion is performed on the parameter string before comparison.
| ModSecurity v2 | since 2.5.0 |
|---|---|
| libModSecurity v3 | supported |
Example:
contains
Returns true if the parameter string is found anywhere in the input. Macro expansion is performed on the parameter string before comparison.
| ModSecurity v2 | since 2.5.0 |
|---|---|
| libModSecurity v3 | supported |
Example:
containsWord
Returns true if the parameter string (with word boundaries) is found anywhere in the input. Macro expansion is performed on the parameter string before comparison.
| ModSecurity v2 | since 2.5.0 |
|---|---|
| libModSecurity v3 | supported |
Example:
Would match on -
-1 union select BENCHMARK(2142500,MD5(CHAR(115,113,108,109,97,112))) FROM wp_users WHERE ID=1 and (ascii(substr(user_login,1,1))&0x01=0) from wp_users where ID=1–
But not on -
Your site has a wide selection of computers.
detectSQLi
Returns true if SQL injection payload is found. This operator uses LibInjection to detect SQLi attacks. ModSecurity v2 bundles libinjection 4 since 2.9.13. libModSecurity v3 bundles libinjection 4 (updated to v4.0.0 in 3.0.15); since 3.0.15 a libinjection parser error counts as a match, and with capture the libinjection fingerprint is stored in TX:0.
| ModSecurity v2 | since 2.7.4 |
|---|---|
| libModSecurity v3 | supported |
Example:
Note
This operator supports the “capture” action.
detectXSS
Returns true if XSS injection is found. This operator uses LibInjection to detect XSS attacks. ModSecurity v2 bundles libinjection 4 since 2.9.13. libModSecurity v3 bundles libinjection 4 (updated to v4.0.0 in 3.0.15); since 3.0.15 a libinjection parser error counts as a match, and with capture the matched input is stored in TX:0.
| ModSecurity v2 | since 2.8.0 |
|---|---|
| libModSecurity v3 | supported |
Example:
Note
This operator supports the “capture” action.
endsWith
Returns true if the parameter string is found at the end of the input. Macro expansion is performed on the parameter string before comparison.
| ModSecurity v2 | since 2.5.0 |
|---|---|
| libModSecurity v3 | supported |
Example:
eq
Performs numerical comparison and returns true if the input value is equal to the provided parameter. Macro expansion is performed on the parameter string before comparison.
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
Example:
Note
If a value is provided that cannot be converted to an integer (i.e a string) this operator will treat that value as 0.
fuzzyHash
The fuzzyHash operator uses the ssdeep, which is a program for computing context triggered piecewise hashes (CTPH). Also called fuzzy hashes, CTPH can match inputs that have homologies. Such inputs have sequences of identical bytes in the same order, although bytes in between these sequences may be different in both content and length.
| ModSecurity v2 | since 2.9.0 |
|---|---|
| libModSecurity v3 | supported |
The operator takes two parameters: the path of a file containing one ssdeep hash per line (a relative path is resolved against the directory of the configuration file) and a similarity threshold between 1 and 100; the operator matches when any hash scores at least the threshold. ModSecurity v2 must be built with ssdeep support, otherwise the operator fails at run time. libModSecurity v3 must be built with ssdeep support, otherwise the rule is rejected at configuration load; v3 does not check that the threshold lies between 1 and 100 and does not skip comment lines in the hash file.
For further information on ssdeep, visit its site: http://ssdeep.sourceforge.net/
Example:
ge
Performs numerical comparison and returns true if the input value is greater than or equal to the provided parameter. Macro expansion is performed on the parameter string before comparison.
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
Example:
Note
If a value is provided that cannot be converted to an integer (i.e a string) this operator will treat that value as 0.
geoLookup
Performs a geolocation lookup using the IP address in input against the geolocation database previously configured using SecGeoLookupDb. If the lookup is successful, the obtained information is captured in the GEO collection. ModSecurity v2 reads the legacy MaxMind GeoIP binary format (GeoIP/GeoLiteCity .dat) with its own parser. libModSecurity v3 reads the MaxMind DB format (GeoIP2/GeoLite2 .mmdb) through libmaxminddb (since 3.0.1), or the legacy .dat format through libGeoIP, depending on which library it was built with. With libmaxminddb v3 fills GEO:COUNTRY_CODE, COUNTRY_NAME, COUNTRY_CONTINENT (the continent name), CITY, POSTAL_CODE, LATITUDE and LONGITUDE; COUNTRY_CODE3, REGION, DMA_CODE and AREA_CODE are only filled by the libGeoIP build. A v3 build with neither library rejects any rule using @geoLookup at configuration load, and a lookup without a configured database does not match.
| ModSecurity v2 | since 2.5.0 |
|---|---|
| libModSecurity v3 | supported |
Example: The geoLookup operator matches on success and is thus best used in combination with nolog,pass. If you wish to block on a failed lookup (which may be over the top, depending on how accurate the geolocation database is), the following example demonstrates how best to do it:
See the GEO variable for an example and more information on various fields available.
gsbLookup
Performs a local lookup of Google’s Safe Browsing using URLs in input against the GSB database previously configured using SecGsbLookupDb. When combined with capture operator it will save the matched url into tx.0 variable.
| Syntax | SecRule TARGET "@gsbLookup REGEX" ACTIONS |
|---|---|
| ModSecurity v2 | since 2.6.0 |
| libModSecurity v3 | not supported (the parser rejects the rule with Operator: GsbLookup is not yet supported) |
Example: The gsbLookup operator matches on success and is thus best used in combination with a block or redirect action. If you wish to block on successful lookups, the following example demonstrates how best to do it:
Note
This operator supports the “capture” action.
gt
Performs numerical comparison and returns true if the input value is greater than the operator parameter. Macro expansion is performed on the parameter string before comparison.
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
Example:
Note
If a value is provided that cannot be converted to an integer (i.e a string) this operator will treat that value as 0.
inspectFile
Executes an external program for every variable in the target list. The contents of the variable is provided to the script as the first parameter on the command line. The program must be specified as the first parameter to the operator. As of version 2.5.0, if the supplied program filename is not absolute, it is treated as relative to the directory in which the configuration file resides. Also as of version 2.5.0, if the filename is determined to be a Lua script (based on its .lua extension), the script will be processed by the internal Lua engine. Internally processed scripts will often run faster (there is no process creation overhead) and have full access to the transaction context of ModSecurity. libModSecurity v3 behaves the same way: a relative path is tried against the current working directory and then the configuration file directory, and .lua scripts are run by the built-in Lua engine when v3 was built with Lua support (since 3.0.4 the Lua script receives the FILES_TMPNAMES value as its argument, as in v2); without Lua support a .lua file is executed as an external program.
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
The @inspectFile operator was initially designed for file inspection (hence the name), but it can also be used in any situation that requires decision making using external logic.
An external program must print one line: output starting with 1 means the file is accepted (no match), anything else is treated as a rejection and the operator matches (the output is logged as the reason). A Lua script matches when its main function returns a string and does not match when it returns nil. In libModSecurity v3 the program must exit with status 0 and print at least two characters for a match to be possible, the output is not logged, and a Lua script matches only when main returns a non-empty string.
The OWASP CRS includes a utility script in the /util directory called runav.pl (util/av-scanning/runav.pl in CRS 3.3; CRS 4 no longer ships it) that allows the file approval mechanism to integrate with the ClamAV virus scanner. This is especially handy to prevent viruses and exploits from entering the web server through file upload.
Example: Using the runav.pl script:
Example of using Lua script (placed in the same directory as the configuration file):
The contents of inspect.lua:
Note
Starting in version 2.9 ModSecurity will not fill the FILES_TMPNAMES variable unless SecTmpSaveUploadedFiles directive is On, or the SecUploadKeepFiles directive is set to RelevantOnly. libModSecurity v3 fills FILES_TMPNAMES when SecTmpSaveUploadedFiles or SecUploadKeepFiles is On (the v3 parser rejects SecUploadKeepFiles RelevantOnly).
Note
Use @inspectFile with caution. It may not be safe to use @inspectFile with variables other than FILES_TMPNAMES. Other variables such as “FULL_REQUEST” may contains content that force your platform to fork process out of your control, making possible to an attacker to execute code using the same permissions of your web server. For other variables you may want to look at the Lua script engine. This observation was brought to our attention by “Gryzli”, on our users mailing list.
Reference: http://sourceforge.net/p/mod-security/mailman/mod-security-users/?viewmonth=201512
ipMatch
Performs a fast ipv4 or ipv6 match of REMOTE_ADDR variable data. Can handle the following formats:
| ModSecurity v2 | since 2.6.0 |
|---|---|
| libModSecurity v3 | supported |
- Full IPv4 Address - 192.168.1.100
- Network Block/CIDR Address - 192.168.1.0/24
- Full IPv6 Address - 2001:db8:85a3:8d3:1319:8a2e:370:7348
- Network Block/CIDR Address - 2001:db8:85a3:8d3:1319:8a2e:370:0/24
Examples:
Individual Address:
Multiple Addresses w/network block:
ipMatchF
| ModSecurity v2 | since 2.7.0 |
|---|---|
| libModSecurity v3 | supported |
short alias for ipMatchFromFile
ipMatchFromFile
Performs a fast ipv4 or ipv6 match of REMOTE_ADDR variable, loading data from a file. Can handle the following formats:
| ModSecurity v2 | since 2.7.0 |
|---|---|
| libModSecurity v3 | supported |
- Full IPv4 Address - 192.168.1.100
- Network Block/CIDR Address - 192.168.1.0/24
- Full IPv6 Address - 2001:db8:85a3:8d3:1319:8a2e:370:7348
- Network Block/CIDR Address - 2001:db8:85a3:8d3:1319:8a2e:370:0/24
Examples:
The file ips.txt may contain:
Note
As of v2.9.0-RC1 this operator also supports to load content served by an HTTPS server (https:// URL instead of a path). libModSecurity v3 supports this in all releases when built with libcurl.
Note
When used with content served by a HTTPS server, the directive SecRemoteRulesFailAction can be used to configure a warning instead of an abort, when the remote content could not be retrieved. This applies to ModSecurity v2 only: in libModSecurity v3 a failed download rejects the rule at configuration load regardless of SecRemoteRulesFailAction.
Note
Empty lines are ignored. Comment lines (beginning with the # character) are ignored by ModSecurity v2 and by libModSecurity v3 since 3.0.9; v3 also strips a trailing # comment from a line, and tries a relative file name against the current working directory before the directory of the rules file.
le
Performs numerical comparison and returns true if the input value is less than or equal to the operator parameter. Macro expansion is performed on the parameter string before comparison.
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
Example:
Note
If a value is provided that cannot be converted to an integer (i.e a string) this operator will treat that value as 0.
lt
Performs numerical comparison and returns true if the input value is less than to the operator parameter. Macro expansion is performed on the parameter string before comparison.
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
Example:
Note
If a value is provided that cannot be converted to an integer (i.e a string) this operator will treat that value as 0.
noMatch
Will force the rule to always return false.
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
pm
Performs a case-insensitive match of the provided phrases against the desired input value. The operator uses a set-based matching algorithm (Aho-Corasick), which means that it will match any number of keywords in parallel. When matching of a large number of keywords is needed, this operator performs much better than a regular expression.
| ModSecurity v2 | since 2.5.0 |
|---|---|
| libModSecurity v3 | supported |
Example:
Note
Starting on ModSecurity v2.6.0 this operator supports a snort/suricata content style. ie: “@pm A|42|C|44|F”.
Note
This operator does not support macro expansion (as of ModSecurity v2.9.1; neither does libModSecurity v3).
Note
This operator supports the “capture” action.
pmf
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
Short alias for pmFromFile.
pmFromFile
Performs a case-insensitive match of the provided phrases against the desired input value. The operator uses a set-based matching algorithm (Aho-Corasick), which means that it will match any number of keywords in parallel. When matching of a large number of keywords is needed, this operator performs much better than a regular expression.
| ModSecurity v2 | since 2.5.0 |
|---|---|
| libModSecurity v3 | supported |
This operator is the same as @pm, except that it takes a list of files as arguments. It will match any one of the phrases listed in the file(s) anywhere in the target value.
Example:
Notes:
- Files must contain exactly one phrase per line. End of line markers (both LF and CRLF) will be stripped from each phrase and any whitespace trimmed from both the beginning and the end. Empty lines and comment lines (those beginning with the # character) will be ignored.
- To allow easier inclusion of phrase files with rule sets, relative paths may be used to the phrase files. In this case, the path of the file containing the rule is prepended to the phrase file path.
- The @pm operator phrases do not support metacharacters.
- Because this operator does not check for boundaries when matching, false positives are possible in some cases. For example, if you want to use @pm for IP address matching, the phrase 1.2.3.4 will potentially match more than one IP address (e.g., it will also match 1.2.3.40 or 1.2.3.41). To avoid the false positives, you can use your own boundaries in phrases. For example, use /1.2.3.4/ instead of just 1.2.3.4. Then, in your rules, also add the boundaries where appropriate. You will find a complete example in the example.
The file blacklist.txt may contain:
Warning
Before ModSecurity 2.5.12, the @pmFromFile operator understood only the LF line endings and did not trim the whitespace from phrases. If you are using an older version of ModSecurity, you should take care when editing the phrase files to avoid using the undesired characters in patterns.e files should be one phrase per line. End of line markers will be stripped from the phrases (LF and CRLF), and whitespace is trimmed from both sides of the phrases. Empty lines and comment lines (beginning with a ‘#’) are ignored. To allow easier inclusion of phrase files with rulesets, relative paths may be used to the phrase files. In this case, the path of the file containing the rule is prepended to the phrase file path.
Note
Starting on ModSecurity v2.6.0 this operator supports a snort/suricata content style. ie: “A|42|C|44|F”.
Note
As of v2.9.0-RC1 this operator also supports to load content served by an HTTPS server. However, only one url can be used at a time.
Note
libModSecurity v3 differences: phrases are read verbatim (no whitespace trimming, so a CRLF file leaves a trailing carriage return in every phrase), the |hex| notation is not interpreted inside phrase files, a relative file name is tried against the current working directory before the rules file directory, every argument may be an https:// URL (libcurl build), and a file or URL that cannot be read rejects the rule at configuration load regardless of SecRemoteRulesFailAction. Empty lines and # comment lines are skipped since 3.0.4.
rbl
Looks up the input value in the RBL (real-time block list) given as parameter. The input value can be an IPv4 address or a hostname; IPv6 addresses are not supported.
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
Example:
Note
If the RBL used is dnsbl.httpbl.org (Honeypot Project RBL) then the SecHttpBlKey directive must specify the user’s registered API key.
Note
If the RBL used is either multi.uribl.com or zen.spamhaus.org combined RBLs, it is possible to also parse the return codes in the last octet of the DNS response to identify which specific RBL the IP was found in. libModSecurity v3 recognizes the provider by the substrings httpbl.org, uribl.com and spamhaus.org in the parameter and writes the decoded reason to the debug log only.
Note
This operator supports the “capture” action.
rsub
Performs regular expression data substitution when applied to either the STREAM_INPUT_BODY or STREAM_OUTPUT_BODY variables. This operator also supports macro expansion. Starting with ModSecurity 2.7.0 this operator supports the syntax |hex| allowing users to use special chars like \n \r
| Syntax | @rsub s/regex/str/[id] |
|---|---|
| ModSecurity v2 | since 2.6.0 |
| libModSecurity v3 | not supported (the parser rejects the rule with Operator: Rsub is not yet supported; the STREAM_* variables do not exist in v3 either) |
Examples: Removing HTML Comments from response bodies:
Note
If you plan to manipulate live data by using @rsub with the STREAM_ variables, you must also enable SecContentInjection directive.
Unlike @rx, the regular expression is compiled through Apache’s ap_regex API as a POSIX extended regular expression (no DOTALL or DOLLAR_ENDONLY settings). The optional flags after the last delimiter are i (case-insensitive match) and d (escape the regex metacharacters of the expanded macros when the pattern contains %{...}); any other flag is an error. The replacement string may reference the subexpressions of the match with \1 to \9. Patterns containing macros are expanded and compiled on every evaluation.
rx
Performs a regular expression match of the pattern provided as parameter. This is the default operator; the rules that do not explicitly specify an operator default to @rx. ModSecurity v2 builds against PCRE2 by default since 2.9.9 (PCRE2 is supported since 2.9.7; PCRE is used only when --with-pcre is given at build time); libModSecurity v3 uses PCRE2 (since 3.0.7, with PCRE only when explicitly requested at build time).
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
Examples:
Regular expressions are handled by the PCRE library 1. ModSecurity compiles its regular expressions with the following settings:
- The entire input is treated as a single line, even when there are newline characters present.
- All matches are case-sensitive. If you wish to perform case-insensitive matching, you can either use the lowercase transformation function or force case-insensitive matching by prefixing the regular expression pattern with the (?i) modifier (a PCRE feature; you will find many similar features in the PCRE documentation).
- The PCRE_DOTALL and PCRE_DOLLAR_ENDONLY flags are set during compilation, meaning that a single dot will match any character, including the newlines, and a $ end anchor will not match a trailing newline character.
Regular expressions are a very powerful tool. You are strongly advised to read the PCRE documentation to get acquainted with its features.
Macro expansion is supported since ModSecurity 2.6.2: a pattern containing %{...} is expanded and compiled on every evaluation instead of once at startup.
Note
libModSecurity v3 compiles patterns with PCRE2_DOTALL and PCRE2_MULTILINE instead, so ^ and $ also match at inner line boundaries. Rules that need line anchors should write (?m) explicitly to behave the same in both versions. In v3 a pattern that is invalid at load time rejects the rule, a pattern that becomes invalid after macro expansion does not match and sets MSC_PCRE_ERROR, and an empty pattern matches everything. SecPcreMatchLimit is honored since 3.0.10: when the limit is exceeded the operator does not match and MSC_PCRE_LIMITS_EXCEEDED and TX:MSC_PCRE_LIMITS_EXCEEDED are set to 1.
Note
This operator supports the “capture” action. ModSecurity v2 stores the whole match in TX:0 and up to nine subexpressions in TX:1 to TX:9; further subexpressions are not captured. libModSecurity v3 stores every subexpression of the pattern.
rxGlobal
Performs a global regular expression match of the pattern provided as parameter. This emulates standard regular expression ‘/g’ functionality, which means that, after a regular expression has been fully matched in a string, the operator will continue searching the string for additional matches of the pattern. This global matching is only useful if the additional captures are desired.
| ModSecurity v2 | not supported |
|---|---|
| libModSecurity v3 | since 3.0.5 |
Example:
This operator is more expensive than @rx. Users are advised to use @rxGlobal only when the full captures are needed and prefer @rx in other cases. @rxGlobal exists only in libModSecurity v3 (added in 3.0.5); ModSecurity v2 has no equivalent.
streq
Performs a string comparison and returns true if the parameter string is identical to the input string. Macro expansion is performed on the parameter string before comparison.
| ModSecurity v2 | since 2.5.0 |
|---|---|
| libModSecurity v3 | supported |
Example:
strmatch
Performs a string match of the provided word against the desired input value. In ModSecurity v2 the operator uses the pattern matching Boyer-Moore-Horspool algorithm, which means that it is a single pattern matching operator. This operator performs much better than a regular expression. In libModSecurity v3 the implementation is a plain substring search, comparable to the contains operator, with macro expansion performed on the parameter.
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
Example:
Note
Starting on ModSecurity v2.6.0 this operator supports a snort/suricata content style. ie: “@strmatch A|42|C|44|F”. libModSecurity v3 does not parse this notation for @strmatch (it does for @pm).
unconditionalMatch
Will force the rule to always return true. This is similar to SecAction however all actions that occur as a result of a rule matching will fire such as the setting of MATCHED_VAR. This can also be part a chained rule.
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
Example:
validateByteRange
Validates that the byte values used in input fall into the range specified by the operator parameter. This operator matches on an input value that contains bytes that are not in the specified range.
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
Example:
The validateByteRange is most useful when used to detect the presence of NUL bytes, which don’t have a legitimate use, but which are often used as an evasion technique.
Note
You can force requests to consist only of bytes from a certain byte range. This can be useful to avoid stack overflow attacks (since they usually contain “random” binary content). The parameter is mandatory: a comma-separated list of byte values and start-end ranges, each between 0 and 255; whitespace around the values is tolerated by atoi() and anything not listed is reported as outside the range. libModSecurity v3 (since 3.0.14) rejects the rule at configuration load when a value is outside 0 to 255 or a range start is greater than its end.
validateByteRange is similar to the ModSecurity 1.X SecFilterForceByteRange Directive however since it works in a rule context, it has the following differences:
- You can specify a different range for different variables.
- It has an “event” context (id, msg….)
- It is executed in the flow of rules rather than being a built in pre-check.
validateDTD
Validates the XML DOM tree against the supplied DTD. The DOM tree must have been built previously using the XML request body processor. This operator matches when the validation fails. libModSecurity v3 requires a build with libxml2 (otherwise the operator is accepted but always matches), resolves the DTD path at configuration load, and also matches when no XML tree was built or the document is not well formed.
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
Example:
NOTE: You must enable the SecXmlExternalEntity directive.
validateHash
Validates REQUEST_URI that contains data protected by the hash engine. Added in ModSecurity 2.7.0 as @validateEncryption and renamed to @validateHash in 2.7.1.
| ModSecurity v2 | since 2.7.1 |
|---|---|
| libModSecurity v3 | not supported (the parser rejects the rule with Operator: ValidateHash is not yet supported; the hash engine does not exist in v3) |
Example:
validateSchema
Validates the XML DOM tree against the supplied XML Schema. The DOM tree must have been built previously using the XML request body processor. This operator matches when the validation fails. libModSecurity v3 requires a build with libxml2 (otherwise the operator is accepted but always matches), resolves the schema path at configuration load, and also matches when no XML tree was built or the document is not well formed.
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
Example:
NOTE: You must enable the SecXmlExternalEntity directive.
validateUrlEncoding
Validates the URL-encoded characters in the provided input string.
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
Example:
ModSecurity will automatically decode the URL-encoded characters in request parameters, which means that there is little sense in applying the @validateUrlEncoding operator to them —that is, unless you know that some of the request parameters were URL-encoded more than once. Use this operator against raw input, or against the input that you know is URL-encoded. For example, some applications will URL-encode cookies, although that’s not in the standard. Because it is not in the standard, ModSecurity will neither validate nor decode such encodings.
validateUtf8Encoding
Check whether the input is a valid UTF-8 string.
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
Example:
The @validateUtf8Encoding operator detects the following problems:
Not enough bytes: ModSecurity accepts one- to four-byte encodings (RFC 3629; a lead byte announcing a five- or six-byte sequence is reported as an invalid character). ModSecurity will locate cases when one or more bytes is/are missing from a character.
Invalid characters: The two most significant bits in most characters should be fixed to 0x80. Some attack techniques use different values as an evasion technique.
Overlong characters: ASCII characters are mapped directly into UTF-8, which means that an ASCII character is one UTF-8 character at the same time. However, in UTF-8 many ASCII characters can also be encoded with two, three, four, five, and six bytes. This is no longer legal in the newer versions of Unicode, but many older implementations still support it. The use of overlong UTF-8 characters is common for evasion.
Restricted characters: code points above U+10FFFF (lead byte 0xF5 or higher) and the UTF-16 surrogate range U+D800 to U+DFFF.
Most, but not all applications use UTF-8. If you are dealing with an application that does, validating that all request parameters are valid UTF-8 strings is a great way to prevent a number of evasion techniques that use the assorted UTF-8 weaknesses. False positives are likely if you use this operator in an application that does not use UTF-8.
Many web servers will also allow UTF-8 in request URIs. If yours does, you can verify the request URI using @validateUtf8Encoding.
verifyCC
Detects credit card numbers in input. This operator will first use the supplied regular expression to perform an initial match, following up with the Luhn algorithm calculation to minimize false positives.
| ModSecurity v2 | supported |
|---|---|
| libModSecurity v3 | supported |
Example:
Note
This operator supports the “capture” action.
verifyCPF
Detects CPF numbers (Brazilian social number) in input. This operator will first use the supplied regular expression to perform an initial match, following up with an algorithm calculation to minimize false positives.
| ModSecurity v2 | since 2.6.0 |
|---|---|
| libModSecurity v3 | supported |
Example:
Note
This operator supports the “capture” action.
verifySSN
Detects US social security numbers (SSN) in input. This operator will first use the supplied regular expression to perform an initial match, following up with an SSN algorithm calculation to minimize false positives.
| ModSecurity v2 | since 2.6.0 |
|---|---|
| libModSecurity v3 | supported |
Example:
SSN Format:
A Social Security number is broken up into 3 sections:
- Area (3 digits)
- Group (2 digits)
- Serial (4 digits)
verifySSN checks:
- Must have 9 digits
- Cannot be a sequence number (ie,, 123456789, 012345678)
- Cannot be a repetition sequence number ( ie 11111111 , 222222222)
- Cannot have area and/or group and/or serial zeroed sequences
- Area code must be less than 740
- Area code must be different then 666
Note
This operator supports the “capture” action.
verifySVNR
Detects Austrian social insurance numbers (Sozialversicherungsnummer, SVNR) in input. This operator will first use the supplied regular expression to perform an initial match, following up with the SVNR check digit calculation to minimize false positives.
| ModSecurity v2 | not supported |
|---|---|
| libModSecurity v3 | since 3.0.4 |
Example:
verifySVNR checks:
- Must have 10 digits (a 4 digit serial number including the check digit, followed by the 6 digit date of birth DDMMYY); other characters are skipped
- Cannot be a sequence number (ie, 0123456789, 1234567890) or a repetition sequence number (ie 1111111111)
- The fourth digit must equal the weighted sum of the other digits modulo 11 (weights 3, 7, 9 for the serial number and 5, 8, 4, 2, 1, 6 for the date of birth; a result of 10 counts as 0)
This operator exists only in libModSecurity v3 (added in 3.0.4); ModSecurity v2 has no equivalent.
Note
This operator supports the “capture” action.
within
Returns true if the input value (the needle) is found anywhere within the @within parameter (the haystack). Macro expansion is performed on the parameter string before comparison.
| ModSecurity v2 | since 2.5.0 |
|---|---|
| libModSecurity v3 | supported |
Example:
Note
There are no delimiters for this operator, it is therefore often necessary to artificially impose some; this can be done using setvar. For instance in the example below, without the imposed delimiters (of ‘/’) this rule would also match on the ‘range’ header (along with many other combinations), since ‘range’ is within the provided parameter. With the imposed delimiters, the rule would check for ‘/range/’ when the range header is provided, and therefore would not match since ‘/range/ is not part of the @within parameter.