javascript sandbox
用途
https://github.com/gf3/sandbox
- Can be used to execute untrusted code.
- Support for timeouts (e.g. prevent infinite loops)
- Support for memory errors (and memory errors)
- Handles errors gracefully
- Restricted code (cannot access node.js methods)
- Supports
console.logand- Supports interprocess messaging with the sandboxed code
例子
https://github.com/gf3/sandbox/blob/master/example/example.js
var Sandbox = require("../lib/sandbox")
, s = new Sandbox()// Example 1 - Standard JS
s.run( "1 + 1", function( output ) {
console.log( "Example 1: " + output.result + "\n" )
})
通信
箱内和向外相互通信。
Sandboxed code:
onmessage = function(message){
if (message === 'hello from outside') {
postMessage('hello from inside');
}
};
Sandbox:
var sandbox = new Sandbox();
sandbox.run(sandboxed_code);
sandbox.on('message', function(message){
// Handle message sent from the inside
// In this example message will be 'hello from inside'
});
sandbox.postMessage('hello from outside');
// Example 11 - IPC Messaging
s.run( "onmessage = function(message){ if (message === 'hello from outside') { postMessage('hello from inside'); };", function(output){ })
s.on('message', function(message){
console.log("Example 11: received message sent from inside the sandbox '" + message + "'\n")
});
var test_message = "hello from outside";
console.log("Example 11: sending message into the sandbox '" + test_message + "'");
s.postMessage(test_message);
javascript sandbox的更多相关文章
- JavaScript SandBox沙箱设计模式
沙箱模式常见于YUI3 core,它是一种采用同一构造器(Constructor)生成彼此独立且互不干扰(self-contained)的实例对象,而从避免污染全局对象的方法. 命名空间 JavaSc ...
- 初涉JavaScript模式 (12) : 沙箱模式
引子 上一篇说了模块模式,而对于其中的命名空间模式其实也是有着一些问题,比如每添加一个模块或则深入叠加都会导致长命名,并且对于多个库的不同版本同时运行,一不小心就会污染全局标识,而这两天也发现了JSe ...
- web应用安全防御100技 好书再次阅读, 变的只是表象,被概念迷惑的时候还是静下心来回顾本质
如何进行web应用安全防御,是每个web安全从业者都会被问到的问题,非常不好回答,容易过于肤浅或流于理论,要阐明清楚,答案就是一本书的长度.而本文要介绍一本能很好回答这个问题的优秀书籍——<we ...
- What technical details should a programmer of a web application consider before making the site public?
What things should a programmer implementing the technical details of a web application consider bef ...
- Cheatsheet: 2016 05.01 ~ 05.31
Other Awesome Go - A curated list of awesome Go frameworks, libraries and software Visual Studio Cod ...
- JS中跨域和沙箱的解析
先来直接分析源码,如下: <!DOCTYPE HTML><html><head> <meta charset="UTF-8"/> & ...
- Cucumber
http://www.ibm.com/developerworks/library/a-automating-ria/ Cucumber is a testing framework that hel ...
- 做BS开发,你应该知道的一些东西
界面和用户体验(Interface and User Experience) 知道各大浏览器执行Web标准的情况,保证你的站点在主要浏览器上都能正常运行.你至少要测试以下引擎:Gecko(用于Fire ...
- selenium docs
Note to the Reader - Docs Being Revised for Selenium 2.0! Introduction Test Automation for Web Appli ...
随机推荐
- Can't find PHP headers in /usr/include/php
解决办法: yum install php-devel
- IOC装配Bean(XML方式)
Spring框架Bean实例化的方式 提供了三种方式实例化Bean 构造方法实例化(默认无参数,用的最多) 静态工厂实例化 实例工厂实例化 无参数构造方法的实例化 <!-- 默认情况下使用的就是 ...
- Page-encoding specified in XML prolog (UTF-8) is different from that specified in page directive (utf-8)
org.apache.jasper.JasperException:xxx.jsp(1,1) Page-encoding specified in XML prolog (UTF-8) is diff ...
- iOS typedef NS_ENUM 与 NSString
//在头文件中声明 typedef NS_ENUM(NSUInteger, TransactionState) { TransactionOpened, TransactionPending, Tra ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 《Invert》开发日志05:终止
今天终于看了久闻大名的<独立游戏大电影>,然后我就做了一个坑爹的决定:终止“Invert”项目的开发.没错,在还没正式开工之前,我就决定停掉这个项目,而且是永久终止.做这个决定并不是因为觉 ...
- springboot+dubbo之多端口注入服务
前面介绍了,springboot+dubbo基础整合,这篇介绍多端口注入服务. springboot使用@Bean注入dubbo服务,当你是单一的ProviderConfig实例,dubbo的@Ser ...
- mysql数据库安装及使用
前言:本文为在ubuntu系统下使用mysql数据库,mysql 版本为:Ver 14.14 Distrib 5.5.43 (mysql版本可在命令行中输入mysql --version显示) 一.m ...
- 后台发送POST,DELETE,GET,PUT请求
public static HttpWebResponse CreatePostHttpResponse(string url, IDictionary<string, int> para ...
- Android中AsyncTask使用
一.AsyncTask的作用: 代替Thread+Handler的组合,使创建异步任务变得简单. AsyncTask执行后台操作,并在用户界面上发布结果,而不必处理线程. 二.AsyncTask的定义 ...