Forum Moderators: phranque
RewriteCond %{QUERY_STRING} (?:[;<>'")]|%(?:0A|0D|22|27|3C|3E|00)).*(?:/\*|union|select|insert|drop|delete|update|cast|create|char|convert|alter|declare|order|script|set|md5|benchmark|encode) [NC]
RewriteRule ^ - [F]
# adding in breaks in an attempt to make the condition more readable
(?:
[;<>'")] |
%(?:0A|0D|22|27|3C|3E|00)
)
.*
(?:
/\* |
union |
select |
insert |
drop |
delete |
update |
cast |
create |
char |
convert |
alter |
declare |
order |
script |
set |
md5 |
benchmark |
encode
)
(?:^|&;)[^=&]*{first-part-here}[^=&]*{second-part-here}
the way that it's written blocks a query string likeDo you mean that it blocks the query although you don't want it to, or that it's intended to block this query but doesn't? Either way, the rule is looking at the value of the parameter when you presumably only want it to look at its name.
[edited by: not2easy at 2:58 am (utc) on Nov 3, 2020]
[edit reason] typo correction requested [/edit]
Do you mean that it blocks the query although you don't want it to, or that it's intended to block this query but doesn't?
(?:[;<>'")]|%(?:0A|0D|22|27|3C|3E|00)).*(?:/\*|union|select|insert|drop|delete|update|cast|create|char|convert|alter|declare|order|script|set|md5|benchmark|encode) /blah.php?var1=js(foo)&var2=selectbar (?:[;<>'")]|%(?:0A|0D|22|27|3C|3E|00))[^&]*(?:/\*|union|select|insert|drop|delete|update|cast|create|char|convert|alter|declare|order|script|set|md5|benchmark|encode)it will no longer match, because “js(foo)” and “selectbar” are values of different parameters. (?:^|&)[^&=]*{first-part-here}[^&=]*{second-part-here}
Yes, that illustrates two entirely different uses of ^ in RegEx: “beginning of string” and “group other than”. at least I assume that's the intention, though the lists aren't identical
The ?: wherever they occur aren't functionally necessary, but may save your server a pico-thingy of work, and could become relevant if you needed to capture.