403 Forbidden if input contains “script”

痞子三分冷 提交于 2019-12-08 05:09:57

问题


I am facing one kinda odd problem and I'd appreciate any help. I am looking to have a page submit a Google Adsense code and then save it to the database (I have a input field to accept GA code and a submit button, very simple form) The thing is, I always get 403 forbidden when submiting a form, if input field contain "<script>" as a value. If I try to submit anything else it works fine, but I can't figure out why text must not contain "<script>".

Note: it's not a problem with mysql escape or something similar, it happens even if I comment out complete PHP code. It just seems like POST won't accept this.

Another thing to mention, this problem DOES NOT occurs in localhost (xampp), but only when uploaded to Namecheap hosting.

Any ideas why this happens and how to make a workaround?


回答1:


Namecheap has probably configured mod_security rules on their servers so to block posts which contain tags as these tags being allowed to be posted back to a webpage opens the door to very serious client side scripting vulnerabilities if the web app doesn't handle this correctly. If the post can even make it to php (which in your case it can't) you should be able to call htmlspecialchars or htmlentities on it to filter these out. If Namecheap is doing this for you and this is a problem then there's not much you can do other than changing hosts as shared hosting doesn't allow you any say over server configuration.




回答2:


I had this problem, I needed to use tags in the form I was submitting in the admin system (embedding a google adsense ad).

To fix I edited the .htaccess file and added the line SecFilterEngine Off

I only needed to do this temporarily to get the job done & turn it back on when I'm done.



来源:https://stackoverflow.com/questions/24986949/403-forbidden-if-input-contains-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!