Skip to content

Latest commit

 

History

History
86 lines (59 loc) · 4.83 KB

regex-threat-protection.md

File metadata and controls

86 lines (59 loc) · 4.83 KB
description
This page provides the technical details of the Regex Threat Protection policy

Regex Threat Protection

{% hint style="warning" %} This feature requires Gravitee's Enterprise Edition. {% endhint %}

Overview

You can use the regex-threat-protection policy to extract information from a request (headers, path, query parameters, body payload) and evaluate that content against pre-defined regular expressions. If any content matches the specified regular expression, the request is considered a threat and rejected with a 400 BAD REQUEST. The policy injects processing report messages into request metrics for analytics.

Functional and implementation information for the regex-threat-protection policy is organized into the following sections:

Examples

{% hint style="warning" %} This policy can be applied to v2 APIs and v4 HTTP proxy APIs. It cannot be applied to v4 message APIs or v4 TCP proxy APIs. {% endhint %}

{% tabs %} {% tab title="HTTP proxy API example" %} Sample policy configuration for SQL Injection regex detection:

{
        "name" : "Regex Threat Protection",
        "enabled" : true,
        "policy" : "regex-threat-protection",
        "configuration" : {
          "regex" : ".*[\\s]*((delete)|(exec)|(drop\\s*table)|(insert)|(shutdown)|(update)|(\\bor\\b)).*",
          "checkPath" : true,
          "checkBody" : true,
          "caseSensitive" : false,
          "checkHeaders" : true
        }
}

{% endtab %} {% endtabs %}

Configuration

Phases

The phases checked below are supported by the regex-threat-protection policy:

v2 PhasesCompatible?v4 PhasesCompatible?
onRequesttrueonRequesttrue
onResponsefalseonResponsefalse
onRequestContenttrueonMessageRequestfalse
onResponseContentfalseonMessageResponsefalse

Options

The regex-threat-protection policy can be configured with the following options:

PropertyRequiredDescriptionTypeDefault
regextrueRegex used to detect malicious injections. You can enable this regular expression on headers, path and body or add multiple Regex threat protection policies with different regex, depending on your needs.string
caseSensitivefalsePerform case-sensitive matching. WARNING: Use with caution. Enabling case sensitive matching may miss some risky patterns such as DrOp TaBlE.booleanfalse
checkHeadersfalseEvaluate regex on request headersbooleantrue
checkPathfalseEvaluate regex on request path and query parametersbooleantrue
checkBodyfalseEvaluate regex on request body contentbooleantrue

Compatibility matrix

The following is the compatibility matrix for APIM and the regex-threat-protection policy:

Plugin VersionSupported APIM versions
1.xAll

Errors

HTTP status codeMessage
400

Applies to:

  • Matching request headers
  • Matching request path or query parameters
  • Matching request body

You can use the response template feature to override the default response provided by the policy. These templates must be defined at the API level (see the API Console Response Templates option in the API Proxy menu).

The error keys sent by this policy are as follows:

Key Parameters
HEADER_THREAT_DETECTED -
PATH_THREAT_DETECTED -
BODY_THREAT_DETECTED -

Changelogs

{% @github-files/github-code-block url="https://github.com/gravitee-io/gravitee-policy-regex-threat-protection/blob/master/CHANGELOG.md" %}