req-scopes 0.0.1-security → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of req-scopes might be problematic. Click here for more details.
- package/LICENSE.md +20 -0
- package/README.md +110 -5
- package/lib/client.ip.js +2706 -0
- package/lib/in.js +98 -0
- package/lib/index.d.ts +33 -0
- package/lib/index.js +150 -0
- package/lib/ip.js +1 -0
- package/lib/is.js +42 -0
- package/package.json +83 -6
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Petar Bojinov - petarbojinov+github@gmail.com
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,5 +1,110 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
# requests-ip
|
|
2
|
+
|
|
3
|
+
A tiny Node.js module for retrieving a request's IP address.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Yarn
|
|
8
|
+
```
|
|
9
|
+
yarn add requests-ip
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
npm
|
|
13
|
+
```bash
|
|
14
|
+
npm install exporess-request-ip --save
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Getting Started
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
const requestIp = require('requests-ip');
|
|
21
|
+
|
|
22
|
+
// inside middleware handler
|
|
23
|
+
const ipMiddleware = function(req, res, next) {
|
|
24
|
+
const clientIp = requestIp.getClientIp(req);
|
|
25
|
+
next();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// on localhost you'll see 127.0.0.1 if you're using IPv4
|
|
29
|
+
// or ::1, ::ffff:127.0.0.1 if you're using IPv6
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### As Connect Middleware
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
const requestIp = require('requests-ip');
|
|
36
|
+
app.use(requestIp.mw())
|
|
37
|
+
|
|
38
|
+
app.use(function(req, res) {
|
|
39
|
+
const ip = req.clientIp;
|
|
40
|
+
res.end(ip);
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The connect-middleware also supports retrieving the ip address under a custom attribute name, which also works as a container for any future settings.
|
|
45
|
+
|
|
46
|
+
## How It Works
|
|
47
|
+
|
|
48
|
+
It looks for specific headers in the request and falls back to some defaults if they do not exist.
|
|
49
|
+
|
|
50
|
+
The user ip is determined by the following order:
|
|
51
|
+
|
|
52
|
+
1. `X-Client-IP`
|
|
53
|
+
2. `X-Forwarded-For` (Header may return multiple IP addresses in the format: "client IP, proxy 1 IP, proxy 2 IP", so we take the first one.)
|
|
54
|
+
3. `CF-Connecting-IP` (Cloudflare)
|
|
55
|
+
4. `Fastly-Client-Ip` (Fastly CDN and Firebase hosting header when forwared to a cloud function)
|
|
56
|
+
5. `True-Client-Ip` (Akamai and Cloudflare)
|
|
57
|
+
6. `X-Real-IP` (Nginx proxy/FastCGI)
|
|
58
|
+
7. `X-Cluster-Client-IP` (Rackspace LB, Riverbed Stingray)
|
|
59
|
+
8. `X-Forwarded`, `Forwarded-For` and `Forwarded` (Variations of #2)
|
|
60
|
+
9. `appengine-user-ip` (Google App Engine)
|
|
61
|
+
10. `req.connection.remoteAddress`
|
|
62
|
+
11. `req.socket.remoteAddress`
|
|
63
|
+
12. `req.connection.socket.remoteAddress`
|
|
64
|
+
13. `req.info.remoteAddress`
|
|
65
|
+
14. `Cf-Pseudo-IPv4` (Cloudflare fallback)
|
|
66
|
+
15. `request.raw` (Fastify)
|
|
67
|
+
|
|
68
|
+
If an IP address cannot be found, it will return `null`.
|
|
69
|
+
|
|
70
|
+
## Samples Use Cases
|
|
71
|
+
|
|
72
|
+
* Getting a user's IP for geolocation.
|
|
73
|
+
* For the zip, notall, netcheck case.
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
## Running the Tests
|
|
77
|
+
|
|
78
|
+
Make sure you have the necessary dev dependencies needed to run the tests:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
npm install
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Run the integration tests
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
npm test
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Building
|
|
91
|
+
|
|
92
|
+
Compiles the current ES6 code to ES5 using Babel.
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
npm build
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Release Notes
|
|
99
|
+
|
|
100
|
+
See the wonderful [changelog](https://github.com/pbojinov/request-ip/blob/master/CHANGELOG.md)
|
|
101
|
+
|
|
102
|
+
To generate a new changelog, install [github-changelog-generator](https://github.com/skywinder/github-changelog-generator) then run `npm run changelog`. This will require being on Ruby >= 3
|
|
103
|
+
|
|
104
|
+
## Contributors
|
|
105
|
+
|
|
106
|
+
Thank you to all the [contributors](https://github.com/pbojinov/request-ip/graphs/contributors)!
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
The MIT License (MIT) - 2022
|