【发布时间】:2020-01-22 18:15:10
【问题描述】:
在我的网站上,只允许少数查询查询参数。有些参数的长度应该只有 1 个字符,即 A-Z 或 a-z 或 1-0,但是,一些扫描仪或黑客试图使用我的 php 应用程序不支持的冗长参数访问 url,我可以在 php 应用程序中阻止它们级别,通过验证 $_GET 参数,但我的服务器正在加载,所以如果参数无效,我想显示 403/404
正确的 UR:: 示例
http://example.com/books/index.php?cat=A
但得到
http://example.com/books/index.php?cat=response.write(9687913*9040912
http://example.com/books/index.php?cat=/.././.././.././.././.././.././.././../etc/./passwd%2500
http://example.com/books/index.php?cat=%22%2bconvert(int%2cCHAR(52)%2bCHAR(67)%2bCHAR(117)%2bCHAR(84)%2bCHAR(117)%2bCHAR(79)%2bCHAR(115)%2bCHAR(84)%2bCHAR(107)%2bCHAR(68)%2bCHAR(76))%2b%22
http://example.com/books/index.php?cat=))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
http://example.com/books/index.php?cat=CWS%07%0e000x%9c%3d%8d1N%c3%40%10E%df%ae%8d%bdI%08)%d3%40%1d%a0%a2%05%09%11%89HiP%22%05D%8bF%8e%0bG%26%1b%d9%8e%117%a0%a2%dc%82%8a%1br%04X;%21S%8c%fe%cc%9b%f9%ff%aa%cb7Jq%af%7f%ed%f2.%f8%01>%9e%18p%c9c%9al%8b%aczG%f2%dc%beM%ec%abdkj%1
是否可以在 .htaccess 中限制某些参数只接受 1 个字符,否则向用户显示 404
【问题讨论】:
-
当然可以……您可以通过
%{QUERY_STRING}访问查询字符串内容,因此您只需在 RewriteCond 中编写相应的条件即可。如果条件匹配,则以下 RewriteRule 可以拒绝访问。
标签: php .htaccess url-rewriting