Hi everyone (and @dchiesa1 )!
I tried to make a Regular Expression Protection policy that will reject any special symbols in the XML payload, but for some reason, it works as expected with values inside tags (like some-value). However the same regex does not trigger with attributes, or, to be more precise, it ignores all attributes except the first one (in alphabetical order).
Here’s my configuration of policy:
<RegularExpressionProtection async="false" continueOnError="false" enabled="true" name="rep_CheckForXPathVulnerabilities">
<DisplayName>rep_CheckForXPathVulnerabilities</DisplayName>
<Properties/>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<Source>request</Source>
<XMLPayload>
<XPath>
<Pattern ignoreCase="true">[\'\"/@=\[\]\(\)]</Pattern>
<Expression>//*/@*</Expression>
<Type>string</Type>
</XPath>
<XPath>
<Pattern ignoreCase="false">[\'\"/@=\[\]\(\)]</Pattern>
<Expression>//*</Expression>
<Type>string</Type>
</XPath>
</XMLPayload>
</RegularExpressionProtection>
When I try to execute a request with this content:
<root action="***" class="***" msgtime="***" ltq="***" exactmatch="***" name="***" orderby="***" page="***" la="some@inacceptable@text" >Inacceptable@text</root>
REP policy throws an error because of “Inacceptable@text”. But if I remove “@” from that text, request works fine (although I have the same character inside attribute “la”). Also, if I change the name of attribute “la” to “aala” (so it’ll be the first one in alphabetical order), the policy will trigger on “@” in its value (as expected).
Does anybody know what I’m doing wrong? Any help will be appreciated!
P.S. And a general question: we have quite a lot of different rules we need to cover to handle our security demands (currently we’re working on JSONPath and XPath Injection protection); Due to Apigee best practices how should we implement this: by using this Regex Protection policy or using custom logic within separate JS files? (Cause this REP policy has quite limited functionality).