Understanding Conditions
Understanding Conditions
Infrastructure Services Web Application Firewall Web Application Firewall Policies All Pages
Updated 2024-02-20
Understanding Conditions
Understand and compose conditions for rules associated with WAF policies.
WAF uses the JMESPath language as a rule condition language. JMESPath is a query language for
JSON (see https://jmespath.org/specification.html ↪JMESPath selectors ↪) that you can use to write
JMESPath expressions, where each expression takes a JSON document as an input (the input
document) and returns a transformed or new JSON document (the output document).
In WAF, each rule accepts a JMESPath expression as the condition. HTTP requests or HTTP responses
(depending on the type of rule) trigger WAF rules. When evaluating a rule, the WAF service evaluates
the JMESPath expression (the condition) of the rule and provides an input JSON document, which
includes the details of the HTTP request or HTTP response that triggered the evaluation. Then, the
result of the evaluated JMESPath expression is used to determine whether or not to run the action
specified in the rule.
The return value of JMESPath conditions in WAF is converted to a boolean value. The following values
are converted to "false":
Empty list: []
Empty object: {}
All other values are converted to "true." True means that the action of a rule is run and false means
that the action isn't run.
You can create a JMESPath condition with up to 1,024 characters.
Example
# One of the HTTP request headers with the same name has a specific value
contains(http.request.headers."example-header", 'specific-value')
Multiple conditions
# HTTP request method is GET and URL path starts with /example/path
http.request.method == 'GET' && starts_with(http.request.url.path, '/example/path')
Example
Protocol: HTTP/1.1
The following JSON input document is generated and passed to JMESPath expressions:
{
"connection": {
"source": {
"address": "129.146.10.1",
"port": 49152,
"geo": {
"countryCode": "US"
},
"routing": {
"asn": 31898
}
},
"destination": {
"address": "205.147.88.0",
"port": 80
},
"protocol": "http"
},
"http": {
"request": {
"host": "www.example.com",
"method": "GET",
"version": "1.1",
"url": {
"path": "/test/path/img.jpg",
"query": "param1=a¶m2=b",
"queryParameters": {
"param1": ["a"],
"param2": ["b"]
},
"queryPrefix": "?"
},
"headers": {
"accept": ["*/*"],
"accept-encoding": ["gzip, deflate"],
"connection": ["keep-alive"],
"cookie": [
"cookie1=A; cookie2=B; cookie3=3C; cookie3=3D"
],
"host": ["www.example.com"],
"user-agent": ["HTTPie/2.4.0"]
},
"cookies": {
"cookie1": ["A"],
"cookie2": ["B"],
"cookie3": ["3C", "3D"]
}
}
}
}
Reference
connection.source.address
Category Value
Type string
Description A string containing the TCP source IP address. IPv6 addresses are represented in their canonical
form, according to RFC 5952 ↪.
connection.source.port
Category Value
Type number
Example 49152
values
connection.source.geo.countryCode
Category Value
Category Value
Description ISO 3166-1 alpha-2 country code of the country, which the source IP address belongs to. Can be
null when the country isn't known.
Example "US"
values
connection.source.routing.asn
Category Value
Description The ASN (autonomous system number) to which the source IP address belongs to. Can be null
when the IP address is private.
connection.destination.address
Category Value
Type string
Example "10.0.0.1"
values
connection.destination.port
Category Value
Type number
Example 80
values
connection.protocol
Category Value
Type string
Example "https"
values
http.request.host
Category Value
Type string
Description The value of the HTTP request "Host" header. The "Host" request header specifies the host and
port number of the server to which the request is being sent.
http.request.method
Category Value
Type string
http.request.version
Category Value
Type string
http.request.url.path
Category Value
Type string
Description The absolute path part of the HTTP request target. Doesn't include the query part. Always starts
with a "/".
http.request.url.query
Category Value
Type string
Description The query parameters of the HTTP request target, without the prefix.
http.request.url.queryParameters
Category Value
Category Value
Type object
Description The query part of the HTTP request target, parsed into an object structure, where:
Example
values Query part of the HTTP request target Parsed object structure
?param1=a¶m2=b¶m3=c
{
"param1": ["a"],
"param2": ["b"],
"param3": ["c"]
}
?
{
multi=one&multi=two&multi=3&encoded+key=two%20words
"multi": ["one","two", "
"encoded key": ["two wor
}
http.request.url.queryParameters
Category Value
Type string
Category Value
http.request.headers
Category Value
Type object
Description The HTTP request headers parsed into an object structure, where:
Example
values Raw HTTP request headers Parsed object structure
http.request.cookies
Category Value
Type object
Description The HTTP cookies that were passed using the "Cookie" HTTP request header, parsed into an
object structure, where:
Example
values Value of the HTTP request header "Cookie" Parsed object structure
http.response.code
Category Value
Type number
Example 200
values
http.response.headers
Category Value
Type object
Description The HTTP response headers parsed into an object structure, where:
Example
values Raw HTTP response headers Parsed object structure
Cache-Control: no-cache {
Cache-Control: must-revalidate "cache-control": ["no-cache", "must-rev
Connection: keep-alive "connection": ["keep-alive"],
Content-Encoding: gzip "content-encoding": ["gzip"],
Content-Type: text/html;charset=UTF-8 "content-type": ["text/html;charset=UT
}
i_equals
boolean i_equals(string $left, string $right)
Returns true if strings $left and $right are equal, when compared case-insensitively (both $left and
$right strings are converted to lower case, only English letters are converted to lower case). Otherwise,
returns false.
Given Expression Result
i_contains
boolean i_contains(array|string $subject, any $search)
If the provided $subject is a string, this function returns true if the string contains the provided
$search argument, when compared case-insensitively (both $left and $right strings are converted to
lower case, only English letters are converted to lower case). Otherwise, this function returns false.
If $subject is an array, this function returns true if at least one of the elements in the array is equal to
the provided $search value, otherwise it returns false.
If $search is a string - comparison is done using the same logic as in i_equals() function: case-
insensitive comparison (both the individual $subject array element and $search strings are converted
to lower case, only English letters are converted to lower case).
i_starts_with
boolean i_starts_with(string $subject, string $prefix)
Returns true if the $subject starts with the $prefix, when compared case-insensitively (both $left and
$right strings are converted to lower case, only English letters are converted to lower case). Otherwise,
this function returns false.
i_ends_with
boolean i_ends_with(string $subject, string $suffix)
Returns true if the $subject ends with the $suffix, when compared case-insensitively (both $left and
$right strings are converted to lower case, only English letters are converted to lower case). Otherwise,
this function returns false.
IP Address Matching
WAF adds support for multiple functions that can match an IP address against a list of CIDR ranges or
WAF Network Address List resources:
address_in
boolean address_in(string $ip_address, array[string] $cidr_subnets)
Returns true if the given $ip_address is contained in at least one of the CIDR subnets specified in
$cidr_subnets. Otherwise, returns false.
address_in_network_address_list
boolean address_in_network_address_list(string $ip_address, array[string] $nal_ids)
Returns true if the given $ip_address is contained in at least one of the provided Network Address
Lists (a WAF resource containing a list of CIDR subnets). Otherwise, returns false.
$nal_id arguments must be an array of strings, referencing WAF NetworkAddressList resources by ID.
All referenced NetworkAddressLists must be of type: "ADDRESSES".
Example 1
Item Details
Given input
{
"connection": {
"source": {
"address": "1.1.1.1"
}
}
}
Item Details
1.1.0.0/16
2.2.0.0/16
Expression address_in_network_address_list(connection.source.address,
['ocid1.webappfirewallnetworkaddresslist...a'])
Result true
Example 2
Item Details
Given input
{
"connection": {
"source": {
"address": "1.1.1.1"
}
}
}
1.1.0.0/16
2.2.0.0/16
ocid1.webappfirewallnetworkaddresslist...b:
3.3.0.0/16
Expression address_in_network_address_list(connection.source.address,
['ocid1.webappfirewallnetworkaddresslist...b'])
Result false
vcn_address_in_network_address_list
boolean vcn_address_in_network_address_list(string $ip_address, string $vcn_id, array[string
Returns true if the given $ip_address in VCN $vcn_id is contained in at least one of the provided
Network Address Lists (a WAF resource containing a list of CIDR subnets). Otherwise, returns false.
$nal_ids must be an array of strings, referencing WAF NetworkAddressList resources by ID. All
referenced NetworkAddressLists must be of type: "VCN_ADDRESSES".
Example 1
Item Details
Given input
{
"connection": {
"source": {
"address": "10.0.0.1"
}
},
"paResource": {
"vcnOcid": "ocid1.vcn...a"
}
}
10.0.0.0/16 in ocid1.vcn...a
10.1.0.0/16 in ocid1.vcn...b
Expression
vcn_address_in_network_address_list(
connection.source.address,
connection.paResource.vcnOcid,
['ocid1.webappfirewallnetworkaddresslist...a']
)
Item Details
Result true
Example 2
Item Details
Given input
{
"connection": {
"source": {
"address": "10.0.0.1"
}
},
"paResource": {
"vcnOcid": "ocid1.vcn...a"
}
}
10.0.0.0/16 in ocid1.vcn...c
Result false
Copyright © 2024, Oracle and/or its affiliates. About Oracle Contact Us Legal Notices Terms of Use & Privacy
Document Conventions Cookie Preferences