Skip to content

Latest commit

 

History

History
71 lines (48 loc) · 4.4 KB

json-threat-protection.md

File metadata and controls

71 lines (48 loc) · 4.4 KB
description
This page provides the technical details of the JSON Threat Protection policy

JSON Threat Protection

Overview

You can use the json-threat-protection policy to validate a JSON request body by specifying limits for various JSON structures (such as arrays, field names and string values). When an invalid request is detected (meaning the limit is reached), the request will be considered a threat and rejected with a 400 BAD REQUEST.

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

Examples

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

{% tabs %} {% tab title="Proxy API example" %} Sample policy configuration:

{
  "name" : "JSON Threat Protection",
  "enabled" : true,
  "policy" : "json-threat-protection",
  "configuration" : {
    "maxDepth" : 90,
    "maxNameLength" : 90,
    "maxValueLength" : 400,
    "maxEntries" : 90,
    "maxArraySize" : 90
  }
}

{% endtab %} {% endtabs %}

Configuration

Phases

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

v2 PhasesCompatible?v4 PhasesCompatible?
onRequestfalseonRequestfalse
onResponsefalseonResponsefalse
onRequestContenttrueonMessageRequestfalse
onResponseContentfalseonMessageResponsefalse

Options

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

PropertyRequiredDescriptionTypeDefault
maxEntriesfalseMaximum number of entries allowed for a JSON object. Example: In { "a":{ "b":1, "c":2, "d":3 }}, a has 3 entriesinteger (-1 to specify no limit)100
maxArraySizefalseMaximum number of elements allowed in an arrayinteger (-1 to specify no limit)100
maxDepthfalseMaximum depth of JSON structure. Example: { "a":{ "b":{ "c":true }}} has a depth of 3.integer (-1 to specify no limit)100
maxNameLengthfalseMaximum string length allowed for a JSON property nameinteger (-1 to specify no limit)100
maxValueLengthfalseMaximum string length allowed for a JSON property valueinteger (-1 to specify no limit)500

Errors

HTTP status codeMessage
400
  • Invalid JSON structure
  • Maximum depth exceeded
  • Maximum JSON entries exceeded
  • Maximum JSON array size exceeded
  • Maximum JSON field name length exceeded
  • Maximum JSON field value length exceeded

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

The error keys sent by this policy are as follows:

KeyParameters
JSON_THREAT_DETECTED-
JSON_THREAT_MAX_DEPTH-
JSON_THREAT_MAX_ENTRIES-
JSON_THREAT_MAX_NAME_LENGTH-
JSON_THREAT_MAX_VALUE_LENGTH-
JSON_MAX_ARRAY_SIZE-

Changelogs

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