Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
context-loader
Advanced tools
Load scripts and run them in a context. For both browsers and node, sync and async.
Create execution contexts, load JavaScript files, compile scripts without running them, run them as many times as you want in as many contexts as you want. Do it in Node or in the browser, with either asynchronous or synchronous loading.
The main difference between usage in browsers and Node is in initially loading.
// Node
var contextLoader = require('context-loader');
// Browser
<script src="context-loader.js"></script>
<script>var contextLoader = exports['context-loader']</script>
The global object also works
var context = contextLoader.createContext('myContext');
Script loading can be done in three ways.
// asynchronous
contextLoader.loadScript('path/filename.js', function callback(error, compiledScript){
if (compiledScript) { /*...*/ }
});
// synchronous
var compiledScript = contextLoader.loadScript('path/filename.js');
if (compiledScript) { /*...*/ }
// raw code
var compiledScript = contextLoader.wrap('(function(){ return "I am compiled code" })()');
if (compiledScript) { /*...*/ }
If loaded synchronously any errors will be passed back as the result
Once you have the compiled script you can then run it in contexts. State isn't shared inside the script itself so it can be used multiple times in the same or different contexts. In Node, a context is either the global object or a Context object created using the vm module. In the browser a context is either the global object or some other window object like an iframe contentWindow.
// run using the current global context
compiledScript.runInContext();
// run scripts and code in various ways
var executionOutcome = compiledScript.runInContext(context);
var executionOutcome = context.run(compiledScript);
var executionOutcome = context.run('x = {}');
Execution outcome is one of:
// using script.runInContext(context)
{ context: [object ExecutionContext], // either the provided or newly initialized wrapped context
result: returnValue } // completion value of the executed code, if any
// using context.run(scriptOrCode)
{ script: [object CompiledScript], // either the provided CompiledScript or newly created script wrapper if code was passed
result: returnValue } // completion value of the executed code, if any
Every time a script is run there is a record created on both the script and the context. Each piece of code is wrapped in a CompiledScript object with a history record, and every context is wrapped in an ExecutionContext object also with a history.
The history allows you to easily replay a series of code executions in the same order, or to cross-reference which contexts have had what code run in them.
// "clone" a context organically by replaying all the code run in it in a new context
var newContext = contextLoader.createContext();
existingContext.history.forEach(function(outcome){
newContext.run(outcome.script);
});
FAQs
Load scripts and run them in a context. For both browsers and node, sync and async.
The npm package context-loader receives a total of 0 weekly downloads. As such, context-loader popularity was classified as not popular.
We found that context-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.