清理代码博客的输入

发布于 2024-08-07 01:08:35 字数 303 浏览 10 评论 0原文

我有一个代码博客,其中有一个用于提交的用户输入表单。以该形式出现的任何内容都会出现在其中一页上。现在这是一个编码博客,所以我不想从输入中删除任何 HTML 标签或 javascript 代码,但我不希望它在任何时候执行。使任何输入无害的最佳方法是什么?将 < 替换为 &lt; 并将 > 替换为 &gt; 就足够了吗?

(作为信息,服务器将是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情域 2024-08-14 01:08:35

是的,替换 <和>应该足够了

Yes, replacing < and > should be enough

月亮坠入山谷 2024-08-14 01:08:35

最好的选择是简单地在后端转义这些值,以便安全地输入到存储引擎中,并使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文