使用Javascript编辑和保存用户HTML - 它有多安全? [英] Editing and Saving user HTML with Javascript - how safe is it?

查看:60
本文介绍了使用Javascript编辑和保存用户HTML - 它有多安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有一个基于Javascript的表单创建工具。您使用链接添加元素的html块(如输入字段)和TinyMCE来编辑文本。这些是通过自动保存功能保存的,该功能在特定事件的后台进行AJAX调用。

For example I have a Javascript-powered form creation tool. You use links to add html blocks of elements (like input fields) and TinyMCE to edit the text. These are saved via an autosave function that does an AJAX call in the background on specific events.

被调用的保存函数可以保护数据库,但我想知道是否用户可以操纵DOM来添加他想要的任何内容(例如自定义HTML或不需要的脚本)。

The save function being called does the database protection, but I'm wondering if a user can manipulate the DOM to add anything he wants(like custom HTML, or an unwanted script).

这个的安全性,如果什么?

How safe is this, if at all?

首先想到的是我应该从收到的HTML代码中搜索并删除任何内联javascript。

使用PHP,JQuery,Ajax。

Using PHP, JQuery, Ajax.

推荐答案

根本不安全。您可以永远不信任客户。即使是初学者也很容易在客户端修改DOM(例如,只安装Firebug for Firefox)。

Not safe at all. You can never trust the client. It's easy even for a novice to modify DOM on the client side (just install Firebug for Firefox, for example).

虽然可以从客户端接受HTML,但是确保在服务器端使用PHP正确验证并清理它。

While it's fine to accept HTML from the client, make sure you validate and sanitize it properly with PHP on the server side.

这篇关于使用Javascript编辑和保存用户HTML - 它有多安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆