Installations
npm install @supercharge/request-ip
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
14.17.1
NPM Version
8.5.1
Score
99.2
Supply Chain
100
Quality
79.4
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (58.19%)
JavaScript (41.81%)
Developer
supercharge
Download Statistics
Total Downloads
5,065,773
Last Day
6,896
Last Week
32,838
Last Month
153,138
Last Year
2,023,851
GitHub Statistics
66 Stars
52 Commits
5 Forks
3 Watching
2 Branches
3 Contributors
Package Meta Information
Latest Version
1.2.0
Package Id
@supercharge/request-ip@1.2.0
Unpacked Size
22.75 kB
Size
5.36 kB
File Count
9
NPM Version
8.5.1
Node Version
14.17.1
Total Downloads
Cumulative downloads
Total Downloads
5,065,773
Last day
-19.8%
6,896
Compared to previous day
Last week
-20.7%
32,838
Compared to previous week
Last month
1.5%
153,138
Compared to previous month
Last year
22.2%
2,023,851
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Request IP
Retrieve a request’s IP address
Installation · Usage · Detecting the IP Address
Follow @marcuspoehls and @superchargejs for updates!
Introduction
The @supercharge/request-ip
package provides a function to retrieve a request’s IP address.
Installation
npm i @supercharge/request-ip
Usage
1const RequestIp = require('@supercharge/request-ip') 2 3const ip = RequestIp.getClientIp(request) 4 5// for example '213.211.254.97' as an IP v4 address 6// or '2001:0db8:85a3:0000:0000:8a2e:0370:7334' as an IP v6 address 7// or 'undefined' if no IP address is available on the given request
Depending on your used web framework, you may use it in a middleware or route handler:
simple Express example
1const { getClientIp } = require('@supercharge/request-ip') 2 3const expressMiddleware = function (req, res, next) { 4 req.ip = getClientIp(req) 5 6 next() 7}
simple hapi route handler example:
1const Hapi = require('@hapi/hapi') 2const { getClientIp } = require('@supercharge/request-ip') 3 4const server = new Hapi.Server({ 5 host: 'localhost' 6}) 7 8server.route({ 9 method: 'GET', 10 path: '/login', 11 handler: (request, h) => { 12 const ip = getClientIp(request) 13 14 return h.response(ip) 15 } 16})
Detecting the IP Address
The client’s IP address may be stored in different locations of the request instance varying between services.
Here’s the order of locations in which the packages searches for the requesting IP address:
- Checks HTTP request headers
x-forwarded-for
: this header may contain multiple IP address for (client/proxies/hops). This package extracts and returns the first IP address.x-forwarded
,forwarded
,forwarded-for
as variants fromx-forwarded-for
possibly configured by proxiesx-client-ip
possibly configured by nginxx-real-ip
possibly configured in nginxcf-connecting-ip
from Cloudflarefastly-client-ip
from Fastly and Firebasetrue-client-ip
from Akamai and Cloudflarex-cluster-client-ip
from Rackspace
- Checks the HTTP connection in
request.connection
andrequest.connection.socket
- Checks the HTTP socket in
request.socket
- Checks the HTTP info in
request.info
- Checks the raw HTTP request instance in
request.raw
- Checks the request context used by AWS API Gateway/Lambda in
request.requestContext
Credits
A huge thank you to Petar Bojinov for his request-ip package. I was using Petar’s package for two years in my hapi-rate-limitor plugin. It seems Petar is busy with other work and I felt the need to create my own package providing the functionality to retrieve a request’s IP address.
Contributing
Do you miss a way to find the request’s IP? We very much appreciate your contribution! Please send in a pull request 😊
- Create a fork
- Create your feature branch:
git checkout -b my-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request 🚀
License
MIT © Supercharge
superchargejs.com · GitHub @supercharge · Twitter @superchargejs
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/29 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/publish-in-github-package-registry.yml:1
- Warn: no topLevel permission defined: .github/workflows/run-tests.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-in-github-package-registry.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/supercharge/request-ip/publish-in-github-package-registry.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-in-github-package-registry.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/supercharge/request-ip/publish-in-github-package-registry.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-in-github-package-registry.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/supercharge/request-ip/publish-in-github-package-registry.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-in-github-package-registry.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/supercharge/request-ip/publish-in-github-package-registry.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-in-github-package-registry.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/supercharge/request-ip/publish-in-github-package-registry.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/run-tests.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/supercharge/request-ip/run-tests.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/run-tests.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/supercharge/request-ip/run-tests.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/publish-in-github-package-registry.yml:17
- Warn: npmCommand not pinned by hash: .github/workflows/publish-in-github-package-registry.yml:33
- Warn: npmCommand not pinned by hash: .github/workflows/run-tests.yml:25
- Info: 0 out of 7 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 3 npmCommand 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 'main'
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Score
3.4
/10
Last Scanned on 2025-01-27
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 More