XML对递归和超大有效载荷进行验证

问题描述 投票:0回答:1

OWASP网站发布了有关如何保护RESTful服务的步骤列表。一点是XML DoS保护。现在我不确定以下两个。

  1. 对递归有效负载的验证
  2. 针对超大有效载荷的验证

根据第一点,是否可以在我的XSD架构中应用xs:sequence来验证?

<xs:complexType name="addressType">
    <xs:sequence>
        <xs:element name="city" type="addressCity" />
        <xs:element name="number" type="addressNumber" />
        <xs:element name="street" type="addressStreet" />
        <xs:element name="zipCode" type="zipCodeMoreThan4Digits" />
    </xs:sequence>
    <xs:attribute name="id" type="unsignedInteger" use="required">
    </xs:attribute>
</xs:complexType>

现在是第二点。如果我像这样使用RegEx就足够了:

<xs:simpleType name="addressCity">
    <xs:restriction base="xs:string">
        <xs:pattern value="[a-zA-ZöäüÖÄÜß -]{2,32}" />
    </xs:restriction>
</xs:simpleType>
xml validation ddos payload
1个回答
1
投票

对递归有效负载的验证:

XML可以无限次嵌套。带有深层嵌套标签的XML仍然可以采用正确的格式,因此解析器将接受它。如果您的解析器是DOM解析器(很有可能),它将尝试在内存中构建整个树。如果您的Web服务接收到的XML是深层嵌套的,那么您的服务器将耗尽所有内存并崩溃,然后它才能意识到xml消息无效-> DoS成功。此处的解决方案是尝试在XML消息传输到Web服务服务器之前对其进行验证。您可以使用应用程序层网关来实现此目的,该网关将XML消息验证为XSD模式。该模式仅应允许所需的嵌套深度。您需要进行此验证而不建立DOM树,否则最终将遇到相同的问题。

针对超大有效载荷的验证:

这里我们有类似的攻击类型。XML的大小会影响DOM解析器的内存消耗。如果将多个元素放在一个序列中,或者只是使一个元素的文本太长,则可以使XML更大。

<?xml version=”1.0” encoding=”UTF-8”?> xmlsoap.org/soap/envelope/”> 
<soap:Envelope xmlns:soap=”http://schemas. xmlsoap.org/soap/envelope/”> 
  <soap:Body> 
    <oversize> 
      <item1>x</item1>
      <item1>x</item1>
      <item1>x</item1>
      <!-- The element <item1> may continue on, until the SOAP message reaches a size of megabytes or even gigabytes --> 
    </oversize> 
  </soap:Body> 
</soap:Envelope>

OR

<?xml version=”1.0” encoding=”UTF-8”?> xmlsoap.org/soap/envelope/”> 
<soap:Envelope xmlns:soap=”http://schemas. xmlsoap.org/soap/envelope/”> 
   <soap:Header> 
    <!-- Arbitrary function call -->
  </soap:Header>

  <soap:oversize> 
    <item1>x</item1>
    <item1>x</item1>
    <item1>x</item1>
    <!-- The element <item1> may continue on, until the SOAP message reaches a size of megabytes or even gigabytes --> 
  </soap:oversize> 

  <soap:Body> 
     <!-- Arbitrary function call -->
  </soap:Body> 
</soap:Envelope>

这里解决方案是使用例如在序列元素中使用maxOccurs =“ 1000”代替maxOccurs =“ unbounded”并限制标记内文本的长度。签出:http://clawslab.nds.rub.de/wiki/index.php/Oversize_payload_attack

希望这会有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.