
Research
/Security News
jscrambler npm Package Compromised in Supply Chain Attack
A compromised jscrambler npm release added a malicious preinstall hook that runs hidden native binaries on Linux, macOS, and Windows.
proxy-extend
Advanced tools
Transparently extend any JS object, using ES6 Proxy.
Given some existing JS value, you may want to add some information to this value without actually modifying the original. The simplest way to do so is to create a wrapper around the value:
const someValue = getValue();
const someValueAnnotated = {
value: someValue,
status: 'ready',
};
One drawback of using a wrapper object, is that the newly annotated value now has a different interface from the original. That means that any consuming code will need to know about the wrapper and "unwrap" it to do anything with it.
Using ES6 Proxy, we can make the wrapper have the same interface as the original value, allowing us to pass the wrapped value to any consuming code without the consumer needing to know whether it has been proxied or not.
To import the library:
import extend from 'proxy-extend';
Basic usage:
const user = { name: 'John' }; // Some value to be extended
const userExtended = extend(user, { status: 'ready' });
// The extended value has the same interface as the original
userExtended.name; // 'John'
({ ...userExtended }); // { name: 'John' }
// But we can also access our annotation, if we know the key
userExtended.status; // 'ready'
To make sure that we do not conflict with any existing properties on the original value, it is useful to use a Symbol as the key of the annotation:
const user = { name: 'John' };
const meta = Symbol('meta'); // Private symbol
const userExtended = extend(user, { [meta]: 'some metadata' });
userExtended.name; // 'John'
userExtended[meta]; // 'some metadata'
Prototypes are conserved:
class User {
constructor(name) {
this.name = name;
}
}
const meta = Symbol('meta'); // Private symbol
const userExtended = extend(new User('John'), { [meta]: 'some metadata' });
userExtended instanceof User; // true
userExtended[meta]; // 'some metadata'
Can also proxy functions and constructors:
const fn = (a, b) => a + b;
extend(fn)(2, 3) === 5; // Works
class MyClass {}
new extend(MyClass); // Works
Reference equality
You cannot use == to check equality, the proxy is a different reference:
const value = { x: 42 };
const proxy = extend(value);
value !== proxy; // Reference equality does not hold
// For primitives as well:
const proxyString = extend('foo');
proxyString !== 'foo'; // Won't work
String(proxyString) === 'foo'; // Cast to string first instead
Primitives
Due to the nature of Proxy, we can only use an object as target value. This library supports any JS object, including plain objects, arrays, functions, and class constructors. We also support a few kinds of primitives by emulating them using objects:
null (using an empty object, with null prototype)String)Number)FAQs
Transparently extend a JS object with additional properties (using ES6 Proxy)
The npm package proxy-extend receives a total of 76 weekly downloads. As such, proxy-extend popularity was classified as not popular.
We found that proxy-extend 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
A compromised jscrambler npm release added a malicious preinstall hook that runs hidden native binaries on Linux, macOS, and Windows.

Research
/Security News
A malicious .NET package is typosquatting the Braintree SDK to steal live payment card data, merchant API keys, and host secrets from production apps.

Security News
/Research
Compromised Injective SDK npm version 1.20.21 exfiltrates wallet private keys and mnemonics through fake telemetry functionality.