This is a Node.js package with a customized HTTP and HTTPS agents to prevent SSRF with hosts validations with a possibility to use a custom DNS to prevent DNS rebinding. Another use of this package is creating a http-agent changing the DNS in some specifics requests in module or function level.
Inspired by ssrf-agent.
Minimum Node version required: >=12.*
//TODO: deploy the package in npm official repository
In order to install the package from Github Registry, you need to setup your npm to use the Github Registry.
$ npm login --scope=@egermano --registry=https://npm.pkg.github.com
> Username: USERNAME
> Password: TOKEN
> Email: PUBLIC-EMAIL-ADDRESS
For more information, please visit Working with Github Packages Registry
Install the package:
npm add @egermano/http-agent-dns
const httpAgent = require('http-agent');
const axios - require('axios');
const url = 'https://egermano.com';
const response = await axios.get(url, {
httpAgent: httpAgent(url),
httpsAgent: httpAgent(url),
});
With custom DNS
const httpAgent = require('http-agent');
const axios - require('axios');
const url = 'https://egermano.com';
const options = {
dnsServers: ['8.8.8.8', '1.1.1.1'],
};
const response = await axios.get(url, {
httpAgent: httpAgent(url, options),
httpsAgent: httpAgent(url, options),
});
warning: request package was deprecated, but this example works.
const httpAgent = require('http-agent');
const request - require('request');
const url = 'https://egermano.com';
request.get({
url,
agent: httpAgent(url),
(error, response) => {
// do something
}
});
With custom DNS
const httpAgent = require('http-agent');
const request - require('request');
const url = 'https://egermano.com';
const options = {
dnsServers: ['8.8.8.8', '1.1.1.1'],
};
request.get({
url,
agent: httpAgent(url, options),
(error, response) => {
// do something
}
});