Hello agentzh
Further inputs:
With the following directive
replace_filter '12345' 'str1' g;
replace_filter '1234567' 'str2' g;
and the strings in the original response body
12345
12345678
the rewritten response is
str1 (i.e first directive was applied)
str1678 (i.e first directive was applied)
However, with the directive
replace_filter '2345' 'str1' g;
replace_filter '1234567' 'str2' g;
the rewritten response is
and the strings in the original response body
12345
12345678
1str1 (i.e first directive was applied)
str28 (i.e second directive was applied)
Instead of the second directive, the first directive could have been applied leading to
12345678 being rewitten to 1str1678 also
It looks like that the beginning of the string in response body is important i.e. once the scanner comes across the character 1 in the response body, it tests to see which one of the possible directives it should use. In this case, it starts using the second directive and continues with it. The alternative could have been to scan the entire response looking for possible tokens with directive 1 and then with directive 2. This would possibly be slower than the earlier alternative.
Please see if this analysis is correct.
On Monday, September 8, 2014 12:10:42 PM UTC+5:30, rvsw wrote:
Hello agentzh
Thanks for providing the replace_filter module in nginx. It has been very useful to me.
Can you please describe how the replace_filter works when similar strings are specified e.g.
when I do this
replace_filter 'str1:90' 'newstr1' g;
replace_filter 'str1:90/str2' 'newstr2' g;
and the string in the response body (only one occurrence) is
"str1:90/str2"
then after replacing, the string in response body is rewritten to "newstr1/str2"
However, if the directive is
replace_filter 'tr1:90' 'newstr1' g;
replace_filter 'str1:90/str2' 'newstr2' g;
and the string in the response body (only one occurrence) is
"str1:90/str2"
then after replacing, the string in response body is rewritten to "newstr2"
Another possibility would have been "snewstr1/str2" because the tr1:90 in str1:90 should be rewritten to newstr2.
How does replace_filter determine the order? I looked through the code but was not able to glean much. Thanks for any inputs