清理代码博客的输入
我有一个代码博客,其中有一个用于提交的用户输入表单。以该形式出现的任何内容都会出现在其中一页上。现在这是一个编码博客,所以我不想从输入中删除任何 HTML 标签或 javascript 代码,但我不希望它在任何时候执行。使任何输入无害的最佳方法是什么?将 <
替换为 <
并将 >
替换为 >
就足够了吗?
(作为信息,服务器将是 GAE,输入将在 python 变量中传递(但从未评估),并存储在 TextProperty 中)
I have a code blog in which I have a user input form for submissions. Whatever goes in that form will appear on one of the pages. Now this is a coding blog, so I don't want to strip any HTML tags or javascript code from the input, but I don't want it to executed at any point. What is the best way to render any input harmless? Is replacing <
by <
and >
by >
enough?
(for info, the sever will be GAE, the input will be passed around (but never evaluated) in python variables, and stored in a TextProperty)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,替换 <和>应该足够了
Yes, replacing < and > should be enough
最好的选择是简单地在后端转义这些值,以便安全地输入到存储引擎中,并使用 HTML 实体输出它们,以便它们显示为代码。
The best bet would be to simply escape those values on the back-end for safe input into your storage engine and output them using HTML entities so that they are displayed as code.