简体   繁体   English

textarea设置iframe的内容-CodeMirror的安全性

[英]textarea sets content of iframe - security with CodeMirror

I'm using CodeMirror to make a project similar to JSFiddle. 我正在使用CodeMirror来制作类似于JSFiddle的项目。 Referencing this example file from CodeMirror, I'm rendering full HTML content from a textarea (including script tags from external javascript files). 从CodeMirror引用此示例文件 ,我正在从文本区域渲染完整的HTML内容(包括来自外部javascript文件的脚本标签)。

It's all working well locally, but before deploying, isn't there a security threat to rendering a full HTML page from user-defined input? 在本地运行都很好,但是在部署之前,从用户定义的输入呈现完整的HTML页面是否存在安全威胁? How is the example above not a security threat? 上面的示例如何不会带来安全威胁?

It can be a security issue if you execute user-defined input inside on your application domain. 如果您在应用程序域内执行用户定义的输入,则可能是一个安全问题。

For example, 1) JS Bin executes user code on a different domain. 例如,1)JS Bin在另一个域上执行用户代码。 The given code will make it clear. 给定的代码将使其清楚。 alert(document.URL) https://jsbin.com/xezusur/edit?html,js,output alert(document.URL) https://jsbin.com/xezusur/edit?html,js,输出

2) Even, JS Fiddle executes code in an iframe on a different URL https://jsfiddle.net/djadmin/zrks3reg/ 2)即使是JS Fiddle,也可以在不同网址的iframe中执行代码https://jsfiddle.net/djadmin/zrks3reg/

As you can see in both the examples given above, the user code is executed on a different domain. 正如您在以上两个示例中看到的那样,用户代码在不同的域上执行。 Thus, it prevents user input from accessing resources on different domain due to Same Origin Policy. 因此,由于相同来源策略,它防止了用户输入访问不同域上的资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM