问题:
我想创建一个重写条件来验证QUERY_STRING以防止XSS。
项目如下所示:
/ItemPage.jsp?itemId=item_12345_12
其中item_12345是必需的,{VERSIONNUMBER}在查询字符串中是可选的。
例如:
RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]
RewriteCond %{QUERY_STRING} script [NC,OR]
RewriteCond %{QUERY_STRING} img [NC,OR]
RewriteCond %{QUERY_STRING} svg [NC,OR]
...
RewriteRule ^/ItemPage.jsp?$ /StartPage.jsp [L,R=301]
当我发现在使用许多可能的新字符串进行过滤之后,列表越来越多。
RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]
RewriteCond %{QUERY_STRING} ^((?!itemId=[w]).)* [NC,OR]
RewriteRule ^/ItemPage.jsp?$ /StartPage.jsp [L,R=301]
在Apache2.4中是否可以过滤XSS代码?
答案1:
我认为你想要的是
RewriteCond %{QUERY_STRING} !^(ItemId=[[:alpha:]]+_d+(_d+)?)?$ [NC]
RewriteRule ^/ItemPage.jsp$ /StartPage.jsp [L,R=301]