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.
abortcontroller-deadline
Advanced tools
Create an AbortController which aborts after a set number of milliseconds pass (a deadline). Optionally connects to other AbortSignals.
AbortController
which aborts after a set number of milliseconds (a deadline)Works with browsers, NodeJS (16+), and spec-compliant polyfills.
import { createDeadline } from "abortcontroller-deadline";
// create an AbortController which aborts after 500 ms
const controller = createDeadline(500);
// use the controller! in this case, it ensures the fetch takes no longer than 500ms
try {
const response = await fetch("https://example.com", {
signal: controller.signal,
});
const data = await response.json();
} catch (error) {
if (error instanceof fetch.AbortError) {
console.log("Deadline exceeded");
}
}
You can chain the output of other AbortSignals into the deadline: if any of the signals aborts before the deadline, the deadline controller will be aborted too:
const parentController = new AbortController();
const anotherController = new AbortController();
// if either parentController or anotherController abort, deadlineController
// will also abort, even if 500ms haven't passed
const deadlineController = createDeadline(
500,
parentController.signal,
anotherController.signal
);
Internally, the deadline is triggered by a timeout (from setTimeout()
). While not required, it is a good practice to clean up any unused timeouts.
createDeadline()
manages this by adding a clearDeadline()
to any returned controller:
import { createDeadline } from "abortcontroller-deadline";
const controller = createDeadline(500);
try {
const response = await fetch("https://example.com", {
signal: controller.signal,
});
/* ... */
} catch (error) {
/* ... */
} finally {
// clean up; this works whether or not the deadline occured
controller.clearDeadline();
}
FAQs
Create an AbortController which aborts after a set number of milliseconds pass (a deadline). Optionally connects to other AbortSignals.
We found that abortcontroller-deadline 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.