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.
clone-response
Advanced tools
The clone-response npm package is designed to clone HTTP response streams. This is particularly useful when you need to consume a response stream multiple times, for example, when you want to cache a response object for later use while still processing it immediately. It allows for the duplication of response objects in a way that each clone can be treated as an independent response.
Cloning HTTP Response Streams
This feature allows you to clone an HTTP response stream. In the provided code sample, an HTTP GET request is made, and the response is cloned using clone-response. Both the original and the cloned response can then be consumed independently, demonstrated by piping them to the standard output.
"use strict";
const http = require('http');
const cloneResponse = require('clone-response');
http.get('http://example.com', res => {
const clonedResponse = cloneResponse(res);
// Now you can consume `res` and `clonedResponse` independently.
res.pipe(process.stdout);
clonedResponse.pipe(process.stdout);
});
While not a direct clone utility, http-response-object offers a way to create and manipulate HTTP response objects in Node.js. It can be used in conjunction with other tools to achieve similar outcomes as clone-response, especially in scenarios where responses need to be reconstructed rather than cloned.
Clone a Node.js HTTP response stream
Returns a new stream and copies over all properties and methods from the original response giving you a complete duplicate.
This is useful in situations where you need to consume the response stream but also want to pass an unconsumed stream somewhere else to be consumed later.
npm install clone-response
import http from 'node:http';
import cloneResponse from 'clone-response';
http.get('http://example.com', response => {
const clonedResponse = cloneResponse(response);
response.pipe(process.stdout);
setImmediate(() => {
// The response stream has already been consumed by the time this executes,
// however the cloned response stream is still available.
doSomethingWithResponse(clonedResponse);
});
});
Please bear in mind that the process of cloning a stream consumes it. However, you can consume a stream multiple times in the same tick, therefore allowing you to create multiple clones. For example:
const clone1 = cloneResponse(response);
const clone2 = cloneResponse(response);
// The response can still be consumed in this tick but cannot be consumed if passed
// into any async callbacks. clone1 and clone2 can be passed around and be
// consumed in the future.
Returns a clone of the passed in response stream.
Type: Stream
A Node.js HTTP response stream to clone.
FAQs
Clone a Node.js HTTP response stream
We found that clone-response demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.