Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@braintree/extended-promise
Advanced tools
Promises are great! But, could they be even better?
npm install @braintree/extended-promise
This library was developed to make working with APIs that are not easily wrapped in promises, such as kicking off a promise that resolves within a callback for an event listener.
Before we wrote this lib, we were saving references to the underlying promise, and references to the resolve
/reject
functions in order to resolve and reject it later:
// without this lib
class MyCustomObject {
constructor () {
this._promise = new Promise((resolve, reject) => {
this._resolveFunction = resolve;
this._rejectFunction = reject;
});
}
asyncProcess() {
// do something very async that's not easily wrapped in a promise
if (success) {
this._resolveFunction(data);
} else {
this._rejectFunction(new Error('fail'));
}
}
methodRelyingOnResultOfPromise() {
return this._promise;
}
}
Instead, we can save a reference to just the promise, and then resolve or reject it directly:
// with this lib
class MyCustomObject {
constructor () {
this._promise = new ExtendedPromise();
}
asyncProcess() {
// do something very async that's not easily wrapped in a promise
if (success) {
this._promise.resolve(data);
} else {
this._promise.reject(new Error('fail'));
}
}
methodRelyingOnResultOfPromise() {
return this._promise;
}
}
The object also supplies an onResolve
and onReject
hook that can be passed in on instantiation:
var promise = new ExtendedPromise({
onResolve(data) {
return someFunctionToTransformData(data);
},
onReject(error) {
// decide if you want to catch the error
return someFallbackDataInstead;
// or if you want to continue through with the rejection
return Promise.reject(error);
}
});
If your environment does not support Promises, you can set the Promise object to be used directly on the Object.
const PromisePolyfill = require('promise-polyfill');
ExtendedPromise.setPromise(PromisePolyfill);
Run tests:
npm test
FAQs
Promises are great! But, could they be even better?
We found that @braintree/extended-promise 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.