Skip to content

Commit e264ca3

Browse files
pedrosousathomasgauvin
authored andcommitted
[Ruleset Engine] Add remove_query_args() function (#23799)
1 parent c11f355 commit e264ca3

File tree

1 file changed

+46
-15
lines changed

1 file changed

+46
-15
lines changed

src/content/docs/ruleset-engine/rules-language/functions.mdx

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Examples:
7373
- If `ip.src` is `113.10.0.2`, `cidr(ip.src, 24, 24)` will return `113.10.0.0`.
7474
- If `ip.src` is `2001:0000:130F:0000:0000:09C0:876A:130B`, `cidr(ip.src, 24, 24)` will return `2001:0000:0000:0000:0000:0000:0000:0000`.
7575

76-
:::caution
76+
:::note
7777
You can only use the `cidr()` function in [custom rules](/waf/custom-rules/) and [rate limiting rules](/waf/rate-limiting-rules/).
7878
:::
7979

@@ -95,7 +95,7 @@ Examples:
9595
- If `ip.src` is `2001:0000:130F:0000:0000:09C0:876A:130B`, `cidr6(ip.src, 24)` will return `2001:0000:0000:0000:0000:0000:0000:0000`.
9696
- If `ip.src` is `113.10.0.2`, `cidr6(ip.src, 24)` will return `113.10.0.2` (unchanged).
9797

98-
:::caution
98+
:::note
9999
You can only use the `cidr6()` function in [custom rules](/waf/custom-rules/) and [rate limiting rules](/waf/rate-limiting-rules/).
100100
:::
101101

@@ -104,7 +104,7 @@ You can only use the `cidr6()` function in [custom rules](/waf/custom-rules/) an
104104
{/* prettier-ignore */}
105105
<code>concat(<Type text="String | Bytes | Array" />)</code>: <Type text="String | Array" />
106106

107-
Takes a comma-separated list of values. Concatenates the argument values into a single String or array.
107+
Takes a comma-separated list of values. Concatenates the argument values into a single String or array.
108108

109109
The return type depends on the type of input arguments. For example, if you concatenate arrays, the function will return an array.
110110

@@ -121,7 +121,7 @@ Decodes a Base64-encoded String specified in `source`.
121121

122122
For example, with the following HTTP request header: `client_id: MTIzYWJj`, `(any(decode_base64(http.request.headers["client_id"][*])[*] eq "123abc"))` would return `true`.
123123

124-
:::caution
124+
:::note
125125
You can only use the `decode_base64()` function in [header transform rules](/rules/transform/), [custom rules](/waf/custom-rules/), and [rate limiting rules](/waf/rate-limiting-rules/).
126126
:::
127127

@@ -249,7 +249,7 @@ Examples:
249249

250250
Create capture groups by putting part of the regular expression in parentheses. Then, reference a capture group using `${<NUMBER>}` in the replacement string, where `<NUMBER>` is the number of the capture group.
251251

252-
:::caution
252+
:::note
253253
You can only use the `regex_replace()` function in rewrite expressions of [Transform Rules](/rules/transform/) and target URL expressions of [dynamic URL redirects](/rules/url-forwarding/single-redirects/).
254254
:::
255255

@@ -262,6 +262,43 @@ Returns a new byte array with all the occurrences of the given bytes removed.
262262

263263
For example, if `http.host` is `"www.cloudflare.com"`, then `remove_bytes(http.host, "\x2e\x77")` will return `"cloudflarecom"`.
264264

265+
### `remove_query_args`
266+
267+
{/* prettier-ignore */}
268+
<code>remove_query_args(field <Type text="String" />, query_param1 <Type text="String" />, query_param2 <Type text="String" />, ...)</code>: <Type text="String" />
269+
270+
Removes one or more query string parameters from a URI query string. Returns a string without the specified parameters.
271+
272+
The `field` must be one of the following:
273+
274+
- `http.request.uri.query`
275+
- `raw.http.request.uri.query`
276+
277+
The `field` cannot be a literal value such as `"search=foo&order=asc"`.
278+
279+
The `remove_query_args()` function will remove all specified parameters (as `query_param1`, `query_param2`, etc.) , including repeated occurrences of the same parameter.
280+
281+
The ordering of unaffected query parameters will be preserved.
282+
283+
Examples:
284+
285+
```txt
286+
// If http.request.uri.query is "order=asc&country=GB":
287+
288+
remove_query_args(http.request.uri.query, "country") will return "order=asc"
289+
remove_query_args(http.request.uri.query, "order") will return "country=GB"
290+
remove_query_args(http.request.uri.query, "search") will return "order=asc&country=GB" (unchanged)
291+
292+
// If http.request.uri.query is "category=Foo&order=desc&category=Bar":
293+
294+
remove_query_args(http.request.uri.query, "order") will return "category=Foo&category=Bar"
295+
remove_query_args(http.request.uri.query, "category") will return "order=desc"
296+
```
297+
298+
:::note
299+
You can only use the `remove_query_args()` function in [rewrite expressions of Transform Rules](/rules/transform/).
300+
:::
301+
265302
### `starts_with`
266303

267304
{/* prettier-ignore */}
@@ -308,7 +345,7 @@ to_string(cf.bot_management.score) will return "5"
308345
to_string(ssl) will return "true"
309346
```
310347

311-
:::caution
348+
:::note
312349
You can only use the `to_string()` function in rewrite expressions of [Transform Rules](/rules/transform/) and target URL expressions of [dynamic URL redirects](/rules/url-forwarding/single-redirects/).
313350
:::
314351

@@ -363,7 +400,7 @@ Generates a random UUIDv4 (Universally Unique Identifier, version 4) based on th
363400

364401
For example, `uuidv4(cf.random_seed)` will return a UUIDv4 similar to `49887398-6bcf-485f-8899-f15dbef4d1d5`.
365402

366-
:::caution
403+
:::note
367404
You can only use the `uuidv4()` function in [rewrite expressions of Transform Rules](/rules/transform/).
368405
:::
369406

@@ -408,7 +445,7 @@ Examples:
408445

409446
For more examples of wildcard matching, refer to [Wildcard matching](/ruleset-engine/rules-language/operators/#wildcard-matching).
410447

411-
:::caution
448+
:::note
412449
Currently, you can only use the `wildcard_replace()` function in rewrite expressions of [URL rewrites](/rules/transform/url-rewrite/) and target URL expressions of [dynamic URL redirects](/rules/url-forwarding/single-redirects/).
413450
:::
414451

@@ -453,27 +490,21 @@ is_timed_hmac_valid_v0(
453490
The `is_timed_hmac_valid_v0()` function has these parameter definitions:
454491

455492
- `Key` <Type text="String literal" />
456-
457493
- Specifies the secret cryptographic key for validating the HMAC.
458494

459495
- `MessageMAC` <Type text="String" />
460-
461496
- Contains a concatenation of these HMAC elements: `message`, `separator`, `timestamp`, `mac`. For a definition and an example, refer to [MessageMAC](#messagemac).
462497

463498
- `ttl` <Type text="Integer literal" />
464-
465499
- Defines the time-to-live for the HMAC token, expressed in seconds. Determines how long the token is valid, relative to the time it was issued.
466500

467501
- `currentTimeStamp` <Type text="Integer" />
468-
469502
- Represents the UNIX timestamp when Cloudflare received the request, expressed in seconds. Pass the `http.request.timestamp.sec` field as an approximate value to this argument.
470503

471504
- `lengthOfSeparator` <Type text="Integer literal" /> <MetaInfo text='optional' />
472-
473505
- Specifies the length of the `separator` between the `timestamp` and the `message` in the `MessageMAC`. Expressed in bytes, with a default value of `0`.
474506

475507
- `flags` <Type text="String literal" /> <MetaInfo text='optional' />
476-
477508
- When you set this optional argument to `'s'`, the function expects the value of the Base64-encoded `mac` in the `MessageMAC` argument to use the URL-safe character set with no padding.
478509

479510
- When you do **not** set the value of `flags` to `'s'`, you must URL encode the Base64 value for `mac` in the `MessageMAC` argument.
@@ -512,7 +543,7 @@ For details on generating a MessageMAC, refer to [HMAC token generation](/waf/cu
512543

513544
## HMAC validation examples
514545

515-
:::caution[Important]
546+
:::note
516547

517548
When you do not use the optional `flags` argument for `is_timed_hmac_valid_v0()`, you must URL-encode the Base64 value for `mac` in the `MessageMAC` argument.
518549

0 commit comments

Comments
 (0)