Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
fetch-extended
Advanced tools
Wrapper of fetch, adding few extra features:
options.query
and done// To install es5 version of the package just
npm install fetch-extended
// To install es6/es2015 version of the package just
npm install fetch-extended@es6
// Each version > 1.0.0 is available as es5 and es6 version
npm instlal fetch-extended@1.0.0
// and
npm instlal fetch-extended@1.0.0-es6
fetch
Features:import fetch from 'fetch-extended';
// default GET method
fetch('https://www.google.com')
.then(response => handleResponse(response));
// change method to POST
fetch('https://www.google.com', { method: 'PUT' })
.then(response => handleResponse(response));
// and more...
For more parameters and configuration to go to Mozzila docs.
You can also use named export like this:
import { fetchx } from 'fetch-extended';
const response = await fetchx('https://www.google.com');
const postResponse = await fetchx('https://www.google.com', { method: 'PUT' });
// and more...
To simplify generating searchParams you can just pass query
object with options
.
import { fetchx } from 'fetch-extended';
const query = {
filter: 'cats',
sort: 'age',
};
await fetchx('https://www.google.com', { query })
// The command will call: `https://www.google.com?filter=cats&sort=age`
With timeout
key you can pass the number of milliseconds of timeout for the request. By default the timeout equals 60000 ms (60 s).
Setting timeout
as any not numerical value like undefined
or null
will turn off this feature and behaviour is the same as standard fetch
.
import fetch, { TimeoutError } from 'fetch-extended';
const timeout = 15000;
fetch('https://www.reject-after-15s.com', { timeout })
.then(response => handleResponse(response))
.catch(error => if(error instanceof TimeoutError) { console.log('Request timeoued out') });
With queryParser
option you can construct URL search parameter sting however you like. By default its string is build with URLSearchParms
class. queryParser
function accepts single parameter which is options.query
from the call and returns string that represent search params (those after ?
character).
import fetch from 'fetch-extended';
function queryParser(query) {
const searchParams = new URLSearchParams();
Object.keys(query)
.forEach(key => {
if(Array.isArray(query[key])) {
query[key].forEach(value => searchParams.append(key, value));
return
}
searchParams.append(key, query[key])
});
return searchParams.toString();
}
const query = {
foo: ['uno', 'dos']
};
fetch('http://localhost', { queryParser, query})
// http://localhost?foo=uno&foo=dos'
To overwrite or set your own default headers and options use getFetchx
.
import { getFetchx } from 'fetch-extended';
const defaultHeaders = {
'api-token': 'my-secret-api-token',
};
const defaultOptions = {
timeout: null,
method: 'POST',
headers: {
'api-token': 'secondary-token',
'sessions-id': 'session',
},
};
const fetchOne = getFetchx(defaultHeaders);
await fetchOne('http://google.com')
// equivalent of fetchx('http://google.com', { headers: defaultHeaders });
const fetchTwo = getFetchx({}, defaultOptions);
await fetchTwo('http://google.com')
// equivalent of fetchx('http://google.com', defaultOptions);
const fetchThree = getFetchx(defaultHeaders, defaultOptions);
await fetchThree('http://google.com')
/* equivalent of calling with options:
{
timeout: null,
method: 'POST',
headers: {
'api-token': 'my-secret-api-token',
'sessions-id': 'session',
},
}
*/
await fetchThree('http://google.com', { timeout: 10000, headers: { 'api-token': 'my-token' }})
/* equivalent of calling with options:
{
timeout: 10000,
method: 'POST',
headers: {
'api-token': 'my-token',
'sessions-id': 'session',
},
}
*/
FAQs
Wrapper of fetch, adding few extra features
We found that fetch-extended 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
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.