Hi Ochal, I’d be glad to try to help out.
First, can you clarify for me what you are testing ? You wrote “we try to check all attributes we use next pattern which for unknown reason does not work”, but you did not explain what you mean by “does not work”. What are you seeing, and what are you expecting to see?
I conducted some tests here, and for my simple tests, the XPath Expression with a wildcard for the attribute name, is working correctly.
When using the RegularExpressionProtection policy on an XML payload, there are two interesting things you can specify: The regular expression itself, and the XPath specifying what to check. In this case, we are not interested in varying the regex, so I used a simple pattern of “bad” for all cases. The idea is that if any attribute value matching the XPath I specify has the word “bad” in it, then the policy should detect a threat. Does this make sense?
I have two RegularExpressionProtection policies. The one that looks at wildcard attributes looks like this:
<RegularExpressionProtection name="REP-XML-Wildcard-Attrs">
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<Source>contrivedMessage</Source>
<XMLPayload>
<Namespaces/>
<XPath>
<!-- check content of any attribute on any element -->
<Expression>//*/@*</Expression>
<Type>string</Type>
<Pattern>bad</Pattern>
</XPath>
</XMLPayload>
</RegularExpressionProtection>
The one that looks for a SPECIFIC attribute looks like this:
<RegularExpressionProtection name="REP-XML-Specific-Attr">
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<Source>contrivedMessage</Source>
<XMLPayload>
<Namespaces/>
<XPath>
<!-- check for a specific attribute on any element -->
<Expression>//*/@value</Expression>
<Type>string</Type>
<Pattern>bad</Pattern>
</XPath>
</XMLPayload>
</RegularExpressionProtection>
I tested these scenarios:
| case # |
actual XML |
Expression |
Observed Result |
As expected? |
| 1 |
<br><child attr1='acceptable content'>123</child><br>
|
<br>//*/@*<br>
|
no fault |
Y |
| 2 |
<br><child attr1='acceptable content'>123</child><br>
|
<br>//*/@value<br>
|
no fault |
Y |
| 3 |
<br><child value='acceptable content'>123</child><br>
|
<br>//*/@*<br>
|
no fault |
Y |
| 4 |
<br><child value='acceptable content'>123</child><br>
|
<br>//*/@value<br>
|
no fault |
Y |
| 5 |
<br><child attr1='bad content'>123</child><br>
|
<br>//*/@*<br>
|
FAULT |
Y |
| 6 |
<br><child attr1='bad content'>123</child><br>
|
<br>//*/@value<br>
|
no fault |
Y |
| 7 |
<br><child value='bad content'>123</child><br>
|
<br>//*/@*<br>
|
FAULT |
Y |
| 8 |
<br><child value='bad content'>123</child><br>
|
<br>//*/@value<br>
|
FAULT |
Y |
Attached please find the API proxy I used to test this. To invoke it,
curl -i $endpoint/regexprotection-4/t1
curl -i $endpoint/regexprotection-4/t2
...
curl -i $endpoint/regexprotection-4/t8