欢迎加入站点基地设计开发交流群:30720409
详细内容
ModSecurity for Apache2[六十二]
发布日期:2010-09-19     点击:3008     字体:[ ]
XML
可以单独使用(作为validateDTD和validateSchema的目标)或和一个XPath表达式参数(这使得它成为有效的目标对于任何函数接受纯文本)。例如使用XPath:


SecDefaultAction log,deny,status:403,phase:2
SecRule REQUEST_HEADERS:Content-Type ^text/xml$ \
    phase:1,t:lowercase,nolog,pass,ctl:requestBodyProcessor=XML
SecRule REQBODY_PROCESSOR "!^XML$" skipAfter:12345
SecRule XML:/employees/employee/name/text() Fred
SecRule XML:/xq:employees/employee/name/text() Fred \
    id:12345,xmlns:xq=http://www.example.com/employees
 

第一个XPath表达式不使用名称空间。这将匹配像下面这样的加载:

 
<employees>
    <employee>
        <name>Fred Jones</name>
        <address location="home">
            <street>900 Aurora Ave.</street>
            <city>Seattle</city>
            <state>WA</state>
            <zip>98115</zip>
        </address>
        <address location="work">
            <street>2011 152nd Avenue NE</street>
            <city>Redmond</city>
            <state>WA</state>
            <zip>98052</zip>
        </address>
        <phone location="work">(425)555-5665</phone>
        <phone location="home">(206)555-5555</phone>
        <phone location="mobile">(206)555-4321</phone>
    </employee>
</employees>
 

第二个XPath表达式使用名称空间。这将匹配下面这样的加载:


<xq:employees xmlns:xq="http://www.example.com/employees">
    <employee>
        <name>Fred Jones</name>
        <address location="home">
            <street>900 Aurora Ave.</street>
            <city>Seattle</city>
            <state>WA</state>
            <zip>98115</zip>
        </address>
        <address location="work">
            <street>2011 152nd Avenue NE</street>
            <city>Redmond</city>
            <state>WA</state>
            <zip>98052</zip>
        </address>
        <phone location="work">(425)555-5665</phone>
        <phone location="home">(206)555-5555</phone>
        <phone location="mobile">(206)555-4321</phone>
    </employee>
</xq:employees>
 
 
 
请注意第二个例子使用不同的命名空间。

要了解更多有关XPath我们建议参考以下资源:

XPath的标准 http://www.w3.org/TR/xpath

XPath教程  http://www.zvon.org/xxl/XPathTutorial/General/examples.html

用户评论
昵称 
内容  *
验证码   
   
Copyright © 2010 zdbase.com All Rights Reserved. 苏ICP备15039389号-1 可人软件设计