JSONThreatProtection 政策

查看 Apigee Edge 說明文件。
前往 Apigee X說明文件
資訊

結果

指定各種限制,將內容層級攻擊所造成的風險降至最低 JSON 結構,例如陣列和字串。

影片:觀看短片,進一步瞭解 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>

&lt;JSONThreatProtection&gt;屬性

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

下表說明所有政策父項元素的共同屬性:

屬性 說明 預設 存在必要性
name

政策的內部名稱。name 屬性的值可以 包含英文字母、數字、空格、連字號、底線和半形句號。此值不能 超過 255 個半形字元

視需要使用 <DisplayName> 元素,為政策加上標籤: 管理使用者介面 Proxy 編輯器,使用不同的自然語言名稱。

不適用 必填
continueOnError

如果設為「false」,系統會在政策失敗時傳回錯誤。這是可預期的情況 大多數政策的行為

如果設為 true,即使政策已發生,流程執行作業仍會繼續執行 失敗。

false 選用
enabled

如要強制執行政策,請設為 true

設為 false 即可停用政策。這項政策不會 仍會強制執行 政策。

true 選用
async

此屬性已淘汰。

false 已淘汰

&lt;DisplayName&gt;元素

name 屬性外,一併使用 管理 UI Proxy 編輯器,使用不同的自然語言名稱。

<DisplayName>Policy Display Name</DisplayName>
預設

不適用

如果省略這個元素,政策的 name 屬性值會是

存在必要性 選用
類型 字串

&lt;ArrayElementCount&gt;元素

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

<ArrayElementCount>20</ArrayElementCount>
預設: 如未指定此元素,或指定負整數,系統會 並未強制執行限制
所在地: 選用
類型: 整數

&lt;ContainerDepth&gt;元素

指定允許的遏制深度上限,其中容器為物件或陣列。 例如,如果陣列包含包含 物件的物件,將導致 深度為 3

<ContainerDepth>10</ContainerDepth>
預設: 如未指定此元素,或指定負整數,系統會 不強制執行任何限制
所在地: 選用
類型: 整數

&lt;ObjectEntryCount&gt;元素

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

<ObjectEntryCount>15</ObjectEntryCount>
預設: 如未指定此元素,或指定負整數,系統會 不強制執行任何限制
所在地: 選用
類型: 整數

&lt;ObjectEntryNameLength&gt;元素

指定物件內屬性名稱可以使用的字串長度上限。

<ObjectEntryNameLength>50</ObjectEntryNameLength>
預設: 如未指定此元素,或指定負整數,系統會 並未強制執行限制
所在地: 選用
類型: 整數

&lt;Source&gt;元素

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

<Source>request</Source>
預設: 申請。
所在地: 選用
類型:

字串。

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

&lt;StringValueLength&gt;元素

指定字串值允許的長度上限。

<StringValueLength>500</StringValueLength>
預設: 如未指定此元素,或指定負整數,系統會 並未強制執行限制
所在地: 選用
類型: 整數

錯誤參考資料

This section describes the fault codes and error messages that are returned and fault variables that are set by Edge 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 政策