
Security News
minimatch Patches 3 High-Severity ReDoS Vulnerabilities
minimatch patched three high-severity ReDoS vulnerabilities that can stall the Node.js event loop, and Socket has released free certified patches.
@checle/zones
Advanced tools
by Filip Dalüge
For a primer on zones in Dart, take a look at the Dart article. Find the complete API here.
Install using NPM:
npm install --save web-zones
Import zones:
import * as zones from 'web-zones'
Object.assign(global, zones) // Optionally, shim the host API (overrides setTimeout, Promise etc.)
Wait for operations spawned by a function
await zone.exec(initAppFunction)
Listen to state
zone.addEventListener('error', listener)
Cancel pending operations
zone.cancel()
Bind function
func = zone.bind(func)
Number of scheduled tasks
zone.tasks.size
Create a zone object and listen for status events.
var zone = new Zone('custom-zone')
zone.addEventListener('finish', () => console.log('Zone has terminated'))
zone.addEventListener('error', error => console.log('Error occurred'))
function application () {
setTimeout(() => null, 1000)
}
zone.run(application)
Run an application that reads a file making use of asynchronous JS APIs. The result is then awaited, and its content printed.
import * as fs from 'fs'
// Application with unknown asynchronous operations
function application() {
// Waits for a second
setTimeout(readFile, 1000)
function readFile () {
// Read asynchronously
fs.readFile('data.txt', data => {
global.fileContent = data
})
}
}
try {
// Call and wait for spawned tasks to terminate
await global.zone.exec(application)
console.log('This file content has been read: ' + global.fileContent)
} catch (error) {
console.log('Either setTimeout or fs.readFile threw an uncatched error')
}
Run three processes using Promise.all and wait for them to finish. Cancel any other zones if one zone throws an error.
try {
await Promise.all([
zone.exec(app1),
zone.exec(app2),
zone.exec(app3),
])
console.log('All tasks have concluded successfully')
} catch (error) {
console.log('One zone errored:', error.zone.name)
// Cancel all remaining zones
zone.cancel()
}
Add custom properties to Zone.current by inheritance.
class CustomEnvironment extends Zone {
constructor () {
super('custom-environment')
this.created = Date.now()
}
}
function routine () {
if (Zone.current instanceof CustomEnvironment) {
console.log('My environment was created at ' + this.created)
} else {
console.log("I think I've been running forever")
}
}
global.zone.run(routine) // "I think I've been running forever"
new CustomEnvironment().run(routine) // Prints the creation date
You can hook into zone operations overriding run().
class MozillaZone extends Zone {
run (func) {
let previousDomain = global.domain
try {
global.domain = 'mozilla.org' // Switch global domain during run()
return super.run(func)
} finally {
global.domain = previousDomain // Restore global domain
}
}
}
global.domain = 'example.com'
new MozillaZone().run(() => console.log(global.domain)) // "mozilla.org"
global.zone.run(() => console.log(global.domain)) // "example.com"
Run code in a sandbox using NodeJS' vm module and print the result.
const vm = require('vm')
// Create sandbox
let sandbox = {
setTimeout,
setInterval,
setImmediate,
print: console.log
}
let applicationCode = `
if (typeof console !== 'undefined') {
console.log("I'm not that secure, it seems.")
} else {
print('Oh yes, I am.')
}
`
try {
// Use exec with vm to run a program in an isolated environment
let result = await zone.exec(() => vm.runInNewContext(applicationCode, sandbox))
console.log('Terminated successfully with result', result)
} catch (error) {
console.log('An error occurred')
)
zone: Zone // Gets the current zone
interface Task extends Event {
cancel?: Function
}
interface Zone extends EventTarget, Node {
name: string
root: Zone
onerror?: Function
onfinish?: Function
readonly tasks: Map<any, Task>
readonly children: Zone[]
readonly root: Zone
constructor (nameOrSpec?: any)
addTask (task: Task): number
setTask (id: any, task: Task): this
getTask (id: any): Task
hasTask (id: any): boolean
removeTask (id: any): boolean
cancelTask (id: any): Promise<void>
run (entry: Function, thisArg?: any, ...args: any[]): any
bind (fn: Function): Function
// Cancels all tasks and child zones by default
cancel (): Promise<void>
// Spawns a new child zone, runs `entry` in it and resolves when all new tasks have been worked off
exec (entry: Function, thisArg?: any, ...args: any[]): Promise<any>
addEventListener (type: 'finish' | 'error', listener: Function, options: any): void
appendChild (node: Zone): this
}
function setTimeout (handler, timeout, ...args)
function setInterval (handler, timeout, ...args)
function clearTimeout (id)
function clearInterval (id)
function Promise (executor)
MIT © 2016 Filip Dalüge (license)
FAQs
Simplistic, promise-based zones
The npm package @checle/zones receives a total of 6 weekly downloads. As such, @checle/zones popularity was classified as not popular.
We found that @checle/zones 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.

Security News
minimatch patched three high-severity ReDoS vulnerabilities that can stall the Node.js event loop, and Socket has released free certified patches.

Research
/Security News
Socket uncovered 26 malicious npm packages tied to North Korea's Contagious Interview campaign, retrieving a live 9-module infostealer and RAT from the adversary's C2.

Research
An impersonated golang.org/x/crypto clone exfiltrates passwords, executes a remote shell stager, and delivers a Rekoobe backdoor on Linux.