JSONThreatProtection 政策

本頁內容適用於 ApigeeApigee Hybrid

查看 Apigee Edge 說明文件。

政策圖示

結果

您可以針對各種 JSON 結構 (例如陣列和字串) 指定限制,盡量降低內容層級攻擊的風險。

這項政策是可擴充政策,使用這項政策可能會產生費用或影響用量,具體情況取決於您的 Apigee 授權。如要瞭解政策類型和使用方式的影響,請參閱「政策類型」。

影片:觀看短片,進一步瞭解 JSONThreatProtection 政策如何協助您防範內容層級的 API 攻擊。

影片:觀看這部短片,瞭解 Apigee 跨雲端 API 平台。

元素參考資料

元素參考資料說明 JSONThreatProtection 政策的元素和屬性。

<JSONThreatProtection async="false" continueOnError="false" enabled="true" name="JSON-Threat-Protection-1">
   <DisplayName>JSONThreatProtection 1</DisplayName>
   <ArrayElementCount>20</ArrayElementCount>
   <ContainerDepth>10</ContainerDepth>
   <ObjectEntryCount>15</ObjectEntryCount>
   <ObjectEntryNameLength>50</ObjectEntryNameLength>
   <Source>request</Source>
   <StringValueLength>500</StringValueLength>
</JSONThreatProtection>

<JSONThreatProtection> 屬性

<JSONThreatProtection async="false" continueOnError="false" enabled="true" name="JSON-Threat-Protection-1"> 

The following table describes attributes that are common to all policy parent elements:

Attribute Description Default Presence
name

The internal name of the policy. The value of the name attribute can contain letters, numbers, spaces, hyphens, underscores, and periods. This value cannot exceed 255 characters.

Optionally, use the <DisplayName> element to label the policy in the management UI proxy editor with a different, natural-language name.

N/A Required
continueOnError

Set to false to return an error when a policy fails. This is expected behavior for most policies.

Set to true to have flow execution continue even after a policy fails. See also:

false Optional
enabled

Set to true to enforce the policy.

Set to false to turn off the policy. The policy will not be enforced even if it remains attached to a flow.

true Optional
async

This attribute is deprecated.

false Deprecated

<DisplayName> element

Use in addition to the name attribute to label the policy in the management UI proxy editor with a different, natural-language name.

<DisplayName>Policy Display Name</DisplayName>
Default

N/A

If you omit this element, the value of the policy's name attribute is used.

Presence Optional
Type String

<ArrayElementCount> 元素

指定陣列中允許的元素數量上限。

<ArrayElementCount>20</ArrayElementCount>
預設值: 如未指定這個元素,或指定負整數,系統就不會強制執行限制。
外觀狀態: 選用
類型: 整數

<ContainerDepth> 元素

指定允許的最高容器深度,容器可以是物件或陣列。 舉例來說,如果陣列包含物件,而該物件又包含物件,則會產生 3 的包含深度。

<ContainerDepth>10</ContainerDepth>
預設值: 如未指定這個元素,或指定負整數,系統就不會強制執行任何限制。
外觀狀態: 選用
類型: 整數

<ObjectEntryCount> 元素

指定物件中允許的項目數量上限。

<ObjectEntryCount>15</ObjectEntryCount>
預設值: 如未指定這個元素,或指定負整數,系統就不會強制執行任何限制。
外觀狀態: 選用
類型: 整數

<ObjectEntryNameLength> 元素

指定物件中屬性名稱允許的字串長度上限。

<ObjectEntryNameLength>50</ObjectEntryNameLength>
預設值: 如未指定這個元素,或指定負整數,系統就不會強制執行限制。
外觀狀態: 選用
類型: 整數

<Source> 元素

要篩選 JSON 酬載攻擊的訊息。這項設定最常設為 request,因為您通常需要驗證來自用戶端應用程式的傳入要求。如果設為 message,這個元素會在附加至要求流程時自動評估要求訊息,並在附加至回應流程時評估回應訊息。

<Source>request</Source>
預設值: 要求
外觀狀態: 選用
類型:

字串。

有效值:要求、回應或訊息。

<StringValueLength> 元素

指定字串值的長度上限。

<StringValueLength>500</StringValueLength>
預設值: 如未指定這個元素,或指定負整數,系統就不會強制執行限制。
外觀狀態: 選用
類型: 整數

錯誤參考資料

This section describes the fault codes and error messages that are returned and fault variables that are set by Apigee when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.

Runtime errors

These errors can occur when the policy executes.

Fault code HTTP status Cause Fix
steps.jsonthreatprotection.ExecutionFailed 500 The JSONThreatProtection policy can throw many different types of ExecutionFailed errors. Most of these errors occur when a specific threshold set in the policy is exceeded. These types of errors include: object entry name length, object entry count, array element count, container depth, string string value length. This error also occurs when the payload contains an invalid JSON object.
steps.jsonthreatprotection.SourceUnavailable 500 This error occurs if the message variable specified in the <Source> element is either:
  • Out of scope (not available in the specific flow where the policy is being executed)
  • Is not one of the valid values request, response, or message
steps.jsonthreatprotection.NonMessageVariable 500 This error occurs if the <Source> element is set to a variable which is not of type message.

Deployment errors

None.

Fault variables

These variables are set when this policy triggers an error. For more information, see What you need to know about policy errors.

Variables Where Example
fault.name="fault_name" fault_name is the name of the fault, as listed in the Runtime errors table above. The fault name is the last part of the fault code. fault.name Matches "SourceUnavailable"
jsonattack.policy_name.failed policy_name is the user-specified name of the policy that threw the fault. jsonattack.JTP-SecureRequest.failed = true

Example error response

{
  "fault": {
    "faultstring": "JSONThreatProtection[JPT-SecureRequest]: Execution failed. reason: JSONThreatProtection[JTP-SecureRequest]: Exceeded object entry name length at line 2",
    "detail": {
      "errorcode": "steps.jsonthreatprotection.ExecutionFailed"
    }
  }
}

Example fault rule

<FaultRule name="JSONThreatProtection Policy Faults">
    <Step>
        <Name>AM-CustomErrorResponse</Name>
        <Condition>(fault.name Matches "ExecutionFailed") </Condition>
    </Step>
    <Condition>(jsonattack.JPT-SecureRequest.failed = true) </Condition>
</FaultRule>

結構定義

使用須知

與 XML 服務一樣,支援 JavaScript 物件表示法 (JSON) 的 API 也容易遭到內容層級攻擊。簡單的 JSON 攻擊會嘗試使用結構,讓 JSON 剖析器不堪負荷,導致服務當機,並引發應用程式層級的阻斷服務攻擊。所有設定都是選用項目,應根據服務需求調整,以防潛在的安全性漏洞。

相關主題

JSONtoXML 政策

XMLThreatProtection 政策

RegularExpressionProtection 政策