保护 HTML 表单免受 Javascript/攻击
我有一个表单,现在您可以输入任何您想要的 javascript 等。任何 XSS 等。
我如何创建白名单,以便您只能发布字符。
在某些时候,我希望以 http://
开头的任何内容都转换为
谢谢
这有效吗? http://htmlpurifier.org/
I have a form and as of right now, you can type any javascript, etc. you want. Any XSS, etc.
How do I go about creating a whitelist so you can only post characters.
At some point I would like anything that starts with http://
to be converted to
<a href="http://..."></a>
Thanks
Is this efficient?
http://htmlpurifier.org/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,不,你不能这样做,你明白吗?因为即使您使用 javascript“清理”数据,也没有人可以阻止任何人
换句话说,您必须执行验证/清理服务器端。 JavaScript 验证可以增强用户的体验(例如,通过对无效输入提供即时反馈)。
Well, no, you can't do that, you see? Because even if you 'sanitize' your data using javascript, noone's stopping anyone from
In other words, you have to perform the validation/sanitization on the server side. Javascript validation is there to enhance the experience of your users (by providing instant feedback on invalid input, for example).
但是,在许多高负载应用程序中,开发人员部分使用客户端验证(但所有输入都必须准备好写入数据库)。
由于您将使用 PHP,我建议您使用 htmlspecialchars()、mysql_real_escape_string() 等解析 $_POST 值。
您必须使用正则表达式将任何以“http://”开头的内容转换为链接(当然,您也可以使用explode('.', $_POST['yourInput']),这对您来说更容易)。
But still, in many high-load applications developers use partially client-side verifications (but all inputs have to be prepared for writing to db).
As you will be using PHP, i suggest you to parse your $_POST values with htmlspecialchars(), mysql_real_escape_string() and so on.
You will have to use regular expression to convert anything that starts with "http://" to links (well, you can also use explode('.', $_POST['yourInput']) which can be easier for you).