Esta página aplica-se ao Apigee e ao Apigee Hybrid.
Veja a documentação do
Apigee Edge.
As APIs que aceitam payloads JSON são vulneráveis a ataques maliciosos concebidos para sobrecarregar o analisador JSON. Estes ataques podem incluir payloads com elementos de matriz excessivos, estruturas profundamente aninhadas ou strings incrivelmente longas, que podem falhar o serviço ou consumir memória excessiva.
A política JSONThreatProtection minimiza este risco ao analisar os pedidos recebidos de payloads que violam os limites definidos em estruturas como matrizes e strings, protegendo eficazmente os seus serviços de back-end contra estes ataques de negação de serviço ou de análise sintática.
Esta política é uma política extensível e a utilização desta política pode ter implicações de custo ou utilização, consoante a sua licença do Apigee. Para ver informações sobre os tipos de políticas e as implicações de utilização, consulte Tipos de políticas.
Referência do elemento
A referência de elementos descreve os elementos e os atributos da política 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>
Atributos <JSONThreatProtection>
<JSONThreatProtection async="false" continueOnError="false" enabled="true" name="JSON-Threat-Protection-1">
A tabela seguinte descreve os atributos comuns a todos os elementos principais de políticas:
| Atributo | Descrição | Predefinição | Presença |
|---|---|---|---|
name |
O nome interno da política. O valor do atributo Opcionalmente, use o elemento |
N/A | Obrigatória |
continueOnError |
Definido como Definido como |
falso | Opcional |
enabled |
Defina como Defina como |
verdadeiro | Opcional |
async |
Este atributo foi descontinuado. |
falso | Descontinuado |
Elemento <DisplayName>
Use em conjunto com o atributo name para etiquetar a política no editor de proxy da IU de gestão com um nome diferente em linguagem natural.
<DisplayName>Policy Display Name</DisplayName>
| Predefinição |
N/A Se omitir este elemento, é usado o valor do atributo |
|---|---|
| Presença | Opcional |
| Tipo | String |
Elemento <ArrayElementCount>
Especifica o número máximo de elementos permitidos numa matriz.
<ArrayElementCount>20</ArrayElementCount>
| Predefinição: | Se não especificar este elemento ou se especificar um número inteiro negativo, o sistema não aplica um limite. |
| Presença: | Opcional |
| Tipo: | Número inteiro |
Elemento <ContainerDepth>
Especifica a profundidade de contenção máxima permitida, em que os contentores são objetos ou matrizes. Por exemplo, uma matriz que contenha um objeto que contenha um objeto resultaria numa profundidade de contenção de 3.
<ContainerDepth>10</ContainerDepth>
| Predefinição: | Se não especificar este elemento ou se especificar um número inteiro negativo, o sistema não aplica nenhum limite. |
| Presença: | Opcional |
| Tipo: | Número inteiro |
Elemento <ObjectEntryCount>
Especifica o número máximo de entradas permitidas num objeto.
<ObjectEntryCount>15</ObjectEntryCount>
| Predefinição: | Se não especificar este elemento ou se especificar um número inteiro negativo, o sistema não aplica nenhum limite. |
| Presença: | Opcional |
| Tipo: | Número inteiro |
Elemento <ObjectEntryNameLength>
Especifica o comprimento máximo da string permitido para um nome de propriedade num objeto.
<ObjectEntryNameLength>50</ObjectEntryNameLength>
| Predefinição: | Se não especificar este elemento ou se especificar um número inteiro negativo, o sistema não aplica um limite. |
| Presença: | Opcional |
| Tipo: | Número inteiro |
Elemento <Source>
Mensagem a ser analisada quanto a ataques de payload JSON. Normalmente, esta opção está definida como request, uma vez que, normalmente, tem de validar os pedidos recebidos de apps de cliente.
Quando definido como message, este elemento avalia automaticamente a mensagem de pedido quando anexada ao fluxo de pedidos e a mensagem de resposta quando anexada ao fluxo de respostas.
<Source>request</Source>
| Predefinição: | pedido |
| Presença: | Opcional |
| Tipo: |
String. Valores válidos: pedido, resposta ou mensagem. |
Elemento <StringValueLength>
Especifica o comprimento máximo permitido para um valor de string.
<StringValueLength>500</StringValueLength>
| Predefinição: | Se não especificar este elemento ou se especificar um número inteiro negativo, o sistema não aplica um limite. |
| Presença: | Opcional |
| Tipo: | Número inteiro |
Referência de erro
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.
|
build |
steps.jsonthreatprotection.SourceUnavailable |
500 |
This error occurs if the message
variable specified in the <Source> element is either:
|
build |
steps.jsonthreatprotection.NonMessageVariable |
500 |
This error occurs if the <Source> element is set to a variable which
is not of type
message.
|
build |
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>
Esquemas
Notas de utilização
Tal como os serviços baseados em XML, as APIs que suportam a notação de objetos JavaScript (JSON) são vulneráveis a ataques ao nível do conteúdo. Os ataques JSON simples tentam usar estruturas que sobrecarregam os analisadores JSON para bloquear um serviço e induzir ataques de negação de serviço ao nível da aplicação. Todas as definições são opcionais e devem ser ajustadas para otimizar os requisitos do seu serviço em função de potenciais vulnerabilidades.
Tópicos relacionados
Política RegularExpressionProtection