> ## Documentation Index
> Fetch the complete documentation index at: https://ngrok.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# OWASP CRS Request Action

> Block common web attacks with the `owasp-crs-request` action in Traffic Policy.

The `owasp-crs-request` action enables rule processing on incoming HTTP requests to your endpoint.
To use rule processing to block malicious HTTP *responses*, enable the [OWASP CRS Response action](https://ngrok.com/docs/gateway/traffic-policy/actions/owasp-crs-response.md).

> [!TIP]
>
> **Use both OWASP CRS actions for comprehensive protection.**
>
> The Request action protects against malicious client requests (such as SQL injection and XSS attacks).
> The Response action protects against data leaks or vulnerabilities in your upstream service's responses (such as exposed SQL error messages and sensitive data).
>
> Together, they provide defense-in-depth security for both incoming and outgoing traffic.

[OWASP](https://owasp.org/) stands for the Open Web Application Security Project, an online community that, among other things, maintains annual lists of the most critical web application security risks.
The [OWASP Core Rule Set](https://owasp.org/www-project-modsecurity-core-rule-set/) (CRS) is a set of attack detection rules that you can use in your Traffic Policies.
It includes protections against attacks like SQL Injection, Cross Site Scripting, Local File Inclusion, and many others.

[Block web attacks with ngrok's OWASP CRS Request](https://www.youtube.com/embed/HHxj5VGFTEA)

## Configuration reference

This is the [Traffic Policy](https://ngrok.com/docs/gateway/traffic-policy.md) configuration reference for this action.

### Supported phases

`on_http_request`

### Type

`owasp-crs-request`

### Configuration fields

​

on\_error

string

Required

Behavior if there is an error processing rules.
Must be one of either `"continue"` or `"halt"` (default `"halt"`).For more information, see the [Managing fallback behavior](#managing-fallback-behavior-on-error) section.

​

process\_body

bool

If `true`, the action evaluates rules for the request body.
Default is `false`.See [Body processing](#body-processing) for details and limitations.

​

exclude\_rule\_ids

array of integers

List of OWASP CRS rule IDs to exclude from evaluation.The minimum value is `900000` and the maximum value is `999999`.

## Behavior

This action evaluates rules for request headers and body (when `process_body` is enabled), and each matching rule adds to the overall score of a request.
If the score exceeds the set score threshold, the action blocks the request.

The tallying process is called Anomaly Scoring, and [the CRS website](https://coreruleset.org/docs/2-how-crs-works/2-1-anomaly_scoring/) describes it in detail.

This action costs **10 [Traffic Policy Units (TPUs)](https://ngrok.com/docs/pricing-limits/traffic-policy-unit-pricing.md)** per request evaluated.

### Default behavior

The default behavior for this action is based on the following [Coraza](https://coraza.io/) directives and rules from v4.14.0 of the CRS:

* [coraza.conf-recommended](https://github.com/corazawaf/coraza/blob/main/coraza.conf-recommended)
* [crs-setup.conf.example](https://github.com/corazawaf/coraza-coreruleset/blob/main/rules/%40crs-setup.conf.example)
* [@owasp\_crs/\*.conf](https://github.com/corazawaf/coraza-coreruleset/tree/main/rules/%40owasp_crs)

Included in these rules is an inbound anomaly score threshold of 5 and a [paranoia level](https://coreruleset.org/docs/2-how-crs-works/2-2-paranoia_levels/) of 1.

### Managing fallback behavior (`on_error`)

If `on_error` is set to `halt` (default) and the action encounters an error while evaluating rules, the Traffic Policy chain halts and no further actions run.
For example, if you have a `log` action after the `owasp-crs-request` action, the `log` action doesn't run and ngrok returns the error.

However, if `on_error` is set to `continue`, actions that appear after the `owasp-crs-request` action still run even if the `owasp-crs-request` action encounters an error.

### Body processing

When `process_body` is enabled, ngrok buffers and evaluates rules against the first 4KB of the body.
If the body is larger than 4KB, ngrok ignores the portion after the first 4KB.

> [!NOTE]
>
> Enabling `process_body` buffers the request body in memory, which may increase latency for large payloads.

### Rule exclusion

When `exclude_rule_ids` is configured, ngrok skips evaluation of the specified rule IDs.
This allows you to disable specific OWASP CRS rules that may be causing false positives in your environment.

### Inbound anomaly score threshold exceeded

If the anomaly score accumulated from matching rules exceeds the threshold, ngrok blocks the request with a `HTTP 403` response.
The request doesn't make it to your upstream.

### Failure to process the body successfully

If ngrok can't read the request body successfully, ngrok blocks the request with a `HTTP 500` response.
The request doesn't make it to your upstream.

### Non-terminating action

This is a **Non-terminating action**. It does not return a response, and will allow Traffic Policy processing to continue to the next Action in the chain. All **Cloud Endpoint** Traffic Policies must end with a terminating action. This requirement does not apply to **Agent Endpoints**.

## Examples

### Running in block mode

The following configuration demonstrates how to run the `owasp-crs-request` action in block mode.

#### Example Traffic Policy document

```yaml policy.yml {5} theme={null}
on_http_request:
  - actions:
      - type: owasp-crs-request
        config:
          on_error: halt
```

```json policy.json {8} theme={null}
{
  "on_http_request": [
    {
      "actions": [
        {
          "type": "owasp-crs-request",
          "config": {
            "on_error": "halt"
          }
        }
      ]
    }
  ]
}
```

### Example request that ngrok would block

In this example, a `curl` command attempts to connect to `example.ngrok.app`, and ngrok blocks the request and returns [ERR\_NGROK\_3700](https://ngrok.com/docs/errors/err_ngrok_3700/).

```curl theme={null}
$ curl --http1.1 -X POST https://example.ngrok.app/\
  -H "User-Agent: Mozilla/5.0" \
  -H "Content-Type: application/json" \
  -d '{"q": "<script>alert(1)</script>"}'
```

```html theme={null}
<!DOCTYPE html>
<html class="h-full" lang="en-US" dir="ltr">
  <head>
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/euclid-square/EuclidSquare-Regular-WebS.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/euclid-square/EuclidSquare-RegularItalic-WebS.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/euclid-square/EuclidSquare-Medium-WebS.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/euclid-square/EuclidSquare-Semibold-WebS.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/euclid-square/EuclidSquare-MediumItalic-WebS.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/ibm-plex-mono/IBMPlexMono-Text.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/ibm-plex-mono/IBMPlexMono-TextItalic.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/ibm-plex-mono/IBMPlexMono-SemiBold.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <link rel="preload" href="https://cdn.ngrok.com/static/fonts/ibm-plex-mono/IBMPlexMono-SemiBoldItalic.woff" as="font" type="font/woff" crossorigin="anonymous" />
    <meta charset="utf-8">
    <meta name="author" content="ngrok">
    <meta name="description" content="ngrok is the fastest way to put anything on the internet with a single command.">
    <meta name="robots" content="noindex, nofollow">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link id="style" rel="stylesheet" href="https://cdn.dev-ngrok.com/static/css/error.css">
    <noscript>The request was blocked by the WAF. (ERR_NGROK_3700)</noscript>
    <script id="script" src="https://cdn.dev-ngrok.com/static/js/error.js" type="text/javascript"></script>
  </head>
  <body class="h-full" id="ngrok">
    <div id="root" data-payload="eyJjZG5CYXNlIjoiaHR0cHM6Ly9jZG4uZGV2LW5ncm9rLmNvbS8iLCJjb2RlIjoiMzcwMCIsIm1lc3NhZ2UiOiJUaGUgcmVxdWVzdCB3YXMgYmxvY2tlZCBieSB0aGUgV0FGLiIsInRpdGxlIjoiRm9yYmlkZGVuIn0="></div>
  </body>
</html>
```

### Running in test mode

The following configuration demonstrates how to run the `owasp-crs-request` action in test mode, where the action evaluates rules but doesn't enforce blocks.

#### Example Traffic Policy document

```yaml policy.yml {5} theme={null}
on_http_request:
  - actions:
      - type: owasp-crs-request
        config:
          on_error: continue
      - type: log
        config:
          metadata:
            message: OWASP CRS request action would be ${actions.ngrok.owasp_crs_request.decision} for ${req.url}
            error_code: ${actions.ngrok.owasp_crs_request.error.code}
            error_message: ${actions.ngrok.owasp_crs_request.error.message}
            matched_rules_first_id: ${actions.ngrok.owasp_crs_request.matched_rules[0].id}
            matched_rules_first_message: ${actions.ngrok.owasp_crs_request.matched_rules[0].message}
            matched_rules_first_data: ${actions.ngrok.owasp_crs_request.matched_rules[0].data}
```

```json policy.json {8} theme={null}
{
  "on_http_request": [
    {
      "actions": [
        {
          "type": "owasp-crs-request",
          "config": {
            "on_error": "continue"
          }
        },
        {
          "type": "log",
          "config": {
            "metadata": {
              "message": "OWASP CRS request action would be ${actions.ngrok.owasp_crs_request.decision} for ${req.url}",
              "error_code": "${actions.ngrok.owasp_crs_request.error.code}",
              "error_message": "${actions.ngrok.owasp_crs_request.error.message}",
              "matched_rules_first_id": "${actions.ngrok.owasp_crs_request.matched_rules[0].id}",
              "matched_rules_first_message": "${actions.ngrok.owasp_crs_request.matched_rules[0].message}",
              "matched_rules_first_data": "${actions.ngrok.owasp_crs_request.matched_rules[0].data}"
            }
          }
        }
      ]
    }
  ]
}
```

## Action result variables

The following variables are made available for use in subsequent expressions and
CEL interpolations after the action has run. Variable values will only apply
to the last action execution, results are not concatenated.

​

actions.ngrok.owasp\_crs\_request.decision

string

The action taken for this request.

**Possible values**

`allow` - If the request was permitted.`deny` - If the request was denied.

​

actions.ngrok.owasp\_crs\_request.anomaly\_score

int

The total anomaly score for the request.
If it equals or exceeds the set threshold, the action blocks the request.

​

actions.ngrok.owasp\_crs\_request.anomaly\_score\_threshold

int

The total anomaly score threshold for the request.
The default is 5.

​

actions.ngrok.owasp\_crs\_request.matched\_rules

array of objects

The list of all rules matched by this request that have a non-zero score.

> [accordion] Show Child Properties
>
> ​
>
> matched\_rules\[i].id
>
> int
>
> The ID of the rule.
>
> ​
>
> matched\_rules\[i].message
>
> string
>
> The text message describing the rule.
>
> ​
>
> matched\_rules\[i].severity
>
> string
>
> The [severity](https://coraza.io/docs/seclang/actions/#severity) of the matched rule.
>
> ​
>
> matched\_rules\[i].data
>
> string
>
> Any extra data about the rule and how it matched the request.

​

actions.ngrok.owasp\_crs\_request.error.code

string

A machine-readable code describing an error that occurred during the action's execution.

​

actions.ngrok.owasp\_crs\_request.error.message

string

A human-readable message providing details about an error that occurred during the action's execution.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.