Installations
npm install request-filtering-agent
Score
95.5
Supply Chain
100
Quality
75.9
Maintenance
100
Vulnerability
100
License
Developer
azu
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
Yes
Node Version
18.16.0
NPM Version
9.2.0
Statistics
21 Stars
98 Commits
7 Forks
4 Watching
2 Branches
4 Contributors
Updated on 19 Oct 2023
Bundle Size
16.02 kB
Minified
4.71 kB
Minified + Gzipped
Languages
TypeScript (99.8%)
Shell (0.2%)
Total Downloads
Cumulative downloads
Total Downloads
4,490,781
Last day
15.9%
14,705
Compared to previous day
Last week
-3%
74,158
Compared to previous week
Last month
16.1%
327,279
Compared to previous month
Last year
318.7%
2,559,006
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
request-filtering-agent
An http(s).Agent class block the request to Private IP addresses and Reserved IP addresses.
It helps to prevent server-side request forgery (SSRF) attack.
This library depends on ipaddr.js definitions. This library blocks the request to these IP addresses by default.
So, This library block the request to non-unicast
IP addresses.
:warning: Node.js's built-in fetch
does not support http.Agent
.
Support http.Agent
libraries
This library provides Node.js's http.Agent implementation. http.Agent is supported by popular library.
- Node.js's built-in
http
andhttps
- node-fetch
- node-http-proxy
- axios
- got
- @cypress/request
request-filtering-agent
works with these libraries!
Install
Install with npm:
npm install request-filtering-agent
Support Node.js version
Version | Node.js 12 | Node.js 14 | Node.js 16 | Node.js 18 | Node.js 20 |
---|---|---|---|---|---|
v1.x.x | Support | Support | Support | Support | Not Support |
v2.0.0 | No Support | No Support | No Support | Support | Support |
Usage
useAgent(url, options)
return an agent for the url.
The agent blocks the request to Private network and Reserved IP addresses by default.
1const fetch = require("node-fetch"); 2const { useAgent } = require("request-filtering-agent"); 3const url = 'http://127.0.0.1:8080/'; 4fetch(url, { 5 // use http or https agent for url 6 agent: useAgent(url) 7}).catch(err => { 8 console.err(err); // DNS lookup 127.0.0.1(family:4, host:127.0.0.1.nip.io) is not allowed. Because, It is private IP address. 9});
request-filtering-agent
support loopback domain like nip.io.
This library detects the IP address that is dns lookup-ed.
$ dig 127.0.0.1.nip.io
;127.0.0.1.nip.io. IN A
;; ANSWER SECTION:
127.0.0.1.nip.io. 300 IN A 127.0.0.1
Example code:
1const fetch = require("node-fetch"); 2const { useAgent } = require("request-filtering-agent"); 3const url = 'http://127.0.0.1.nip.io:8080/'; 4fetch(url, { 5 agent: useAgent(url) // use http or https agent for url 6}).catch(err => { 7 console.err(err); // DNS lookup 127.0.0.1(family:4, host:127.0.0.1.nip.io) is not allowed. Because, It is private IP address. 8});
It will prevent DNS rebinding
API
1export interface RequestFilteringAgentOptions { 2 // Allow to connect private IP address 3 // This includes Private IP addresses and Reserved IP addresses. 4 // https://en.wikipedia.org/wiki/Private_network 5 // https://en.wikipedia.org/wiki/Reserved_IP_addresses 6 // Example, http://127.0.0.1/, http://localhost/, https://169.254.169.254/ 7 // Default: false 8 allowPrivateIPAddress?: boolean; 9 // Allow to connect meta address 0.0.0.0 10 // 0.0.0.0 (IPv4) and :: (IPv6) a meta address that routing another address 11 // https://en.wikipedia.org/wiki/Reserved_IP_addresses 12 // https://tools.ietf.org/html/rfc6890 13 // Default: false 14 allowMetaIPAddress?: boolean; 15 // Allow address list 16 // This values are preferred than denyAddressList 17 // Default: [] 18 allowIPAddressList?: string[]; 19 // Deny address list 20 // Default: [] 21 denyIPAddressList?: string[]; 22} 23/** 24 * A subclass of http.Agent with request filtering 25 */ 26export declare class RequestFilteringHttpAgent extends http.Agent { 27 constructor(options?: http.AgentOptions & RequestFilteringAgentOptions); 28} 29/** 30 * A subclass of https.Agent with request filtering 31 */ 32export declare class RequestFilteringHttpsAgent extends https.Agent { 33 constructor(options?: https.AgentOptions & RequestFilteringAgentOptions); 34} 35export declare const globalHttpAgent: RequestFilteringHttpAgent; 36export declare const globalHttpsAgent: RequestFilteringHttpsAgent; 37/** 38 * Get an agent for the url 39 * return http or https agent 40 * @param url 41 */ 42export declare const useAgent: (url: string, options?: https.AgentOptions & RequestFilteringAgentOptions) => RequestFilteringHttpAgent | RequestFilteringHttpsAgent;
Example: Create an Agent with options
An agent that allow requesting 127.0.0.1
, but it disallows other Private IP.
1const fetch = require("node-fetch"); 2const { RequestFilteringHttpAgent } = require("request-filtering-agent"); 3 4// Create http agent that allow 127.0.0.1, but it disallow other private ip 5const agent = new RequestFilteringHttpAgent({ 6 allowIPAddressList: ["127.0.0.1"], // it is preferred than allowPrivateIPAddress option 7 allowPrivateIPAddress: false, // Default: false 8}); 9// 127.0.0.1 is private ip address, but it is allowed 10const url = 'http://127.0.0.1:8080/'; 11fetch(url, { 12 agent: agent 13}).then(res => { 14 console.log(res); // OK 15});
Related
- welefen/ssrf-agent: make http(s) request to prevent SSRF
- It provides only high level wrapper
- It only handles Private IP address that is definition in node-ip
- Missing Meta IP Address like
0.0.0.0
- Missing Meta IP Address like
Changelog
See Releases page.
Running tests
Install devDependencies and Run yarn test
:
yarn test
:memo: This testing require IPv6 supports:
- Travis CI: NG
- GitHub Actions: OK
Contributing
Pull requests and stars are always welcome.
For bugs and feature requests, please create an issue.
For security issue, please see SECURITY.md
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
Author
License
MIT © azu
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
GitHub workflow tokens follow principle of least privilege
Details
- Info: topLevel 'contents' permission set to 'read': .github/workflows/ci.yml:5
- Info: no jobLevel write permissions found
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Info: Found linked content: SECURITY.md:1
- Warn: One or no descriptive hints of disclosure, vulnerability, and/or timelines in security policy
- Info: Found text in security policy: SECURITY.md:1
Reason
6 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
Reason
Found 4/29 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/azu/request-filtering-agent/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/azu/request-filtering-agent/ci.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 9 are checked with a SAST tool
Score
4.5
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to request-filtering-agent
agent-base
Turn a function into an `http.Agent` instance
tunnel-agent
HTTP proxy tunneling agent. Formerly part of mikeal/request, now a standalone module.
forever-agent
HTTP Agent that keeps socket connections alive between keep-alive requests. Formerly part of mikeal/request, now a standalone module.
http-proxy-agent
An HTTP(s) proxy `http.Agent` implementation for HTTP