Skip to content

Latest commit

 

History

History
83 lines (57 loc) · 6.8 KB

xml-threat-protection.md

File metadata and controls

83 lines (57 loc) · 6.8 KB
description
This page provides the technical details of the XML Threat Protection policy

XML Threat Protection

Overview

You can use the xml-threat-protection policy to validate an XML request body by applying limits on XML structures such as elements, entities, attributes 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 xml-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:

{
        "name" : "XML Threat Protection",
        "enabled" : true,
        "policy" : "xml-threat-protection",
        "configuration" : {
          "maxDepth" : 90,
          "maxChildrenPerElement" : 90,
          "maxEntities" : 90,
          "maxAttributesPerElement" : 90,
          "allowExternalEntities" : false,
          "maxElements" : 900,
          "maxEntityDepth" : 90,
          "maxAttributeValueLength" : 90,
          "maxTextValueLength" : 90,
          "maxLength" : 900
        }
}

{% endtab %} {% endtabs %}

Configuration

Phases

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

v2 PhasesCompatible?v4 PhasesCompatible?
onRequestfalseonRequestfalse
onResponsefalseonResponsefalse
onRequestContenttrueonMessageRequestfalse
onResponseContentfalseonMessageResponsefalse

Options

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

PropertyRequiredDescriptionTypeDefault
maxElementsfalseMaximum number of elements allowed in an XML document. Example: <root><a>1</a>2<b></b></root> has 3 elements.integer (-1 to specify no limit)1000
maxDepthfalseMaximum depth of XML structure. Example: <root><a><b>1</b></a></root> has a depth of 2.integer (-1 to specify no limit)100
maxLengthfalseMaximum number of characters allowed for the whole XML document.integer (-1 to specify no limit)1000
maxAttributesPerElementfalseMaximum number of attributes allowed for single XML element.integer (-1 to specify no limit)100
maxAttributeValueLengthfalseMaximum length of individual attribute values.integer (-1 to specify no limit)100
maxChildrenPerElementfalseMaximum number of child elements for a given element. Example: <code><root><a><b>1</b><c>2</c></a></root></code> a element has 2 children.integer (-1 to specify no limit)100
maxTextValueLengthfalseMaximum length of individual text value.integer (-1 to specify no limit)100
maxEntitiesfalseMaximum number of entity expansions allowed. XML entities are a type of macro and vulnerable to entity expansion attacks (for more information on XML entity expansion attacks, see Billion laughs attack).integer (-1 to specify no limit)100
maxEntityDepthfalseMaximum depth of nested entity expansions allowed.integer (-1 to specify no limit)100
allowExternalEntitiesfalseWhether to allow inclusion of external entities. WARNING: Since XML can be vulnerable to XXE injection, only enable this feature if you can really trust your consumers.booleanfalse

Compatibility matrix

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

Plugin VersionSupported APIM versions
1.xAll

Errors

HTTP status codeMessage
400 Bad Request
  • Invalid xml structure
  • Maximum xml elements exceeded
  • Maximum xml depth exceeded
  • Maximum xml length exceeded
  • Maximum attributes per element exceeded
  • Maximum attribute value length exceeded
  • Maximum children per element exceeded
  • Maximum text value length exceeded
  • Maximum xml entities exceeded
  • Maximum xml entity depth exceeded
  • External entity is used when prohibited

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:

KeyParameters
XML_THREAT_DETECTED-
XML_THREAT_MAX_DEPTH-
XML_THREAT_MAX_LENGTH-
XML_THREAT_MAX_ATTRIBUTES-
XML_THREAT_MAX_ATTRIBUTE_VALUE_LENGTH-
XML_MAX_CHILD_ELEMENTS-
XML_THREAT_MAX_TEXT_VALUE_LENGTH-
XML_THREAT_MAX_ENTITIES-
XML_THREAT_MAX_ENTITY_DEPTH-
XML_THREAT_EXTERNAL_ENTITY_FORBIDDEN-

Changelogs

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