New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@fullerstack/nax-ipware

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fullerstack/nax-ipware - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4-dev-70e97f0b5c

8

package.json
{
"version": "0.0.3",
"version": "0.0.4-dev-70e97f0b5c",
"name": "@fullerstack/nax-ipware",

@@ -25,4 +25,4 @@ "license": "MIT",

"dependencies": {
"tslib": "^2.0.0",
"ts-essentials": "^7.0.2"
"ts-essentials": "^7.0.2",
"tslib": "^2.0.0"
},

@@ -39,2 +39,2 @@ "main": "./src/index.js",

}
}
}

@@ -33,7 +33,7 @@ # NAX IPware (A Node Application Agnostic Library)

app.use(function(req, res, next) {
const clientIp = ipware.getClientIP(req)
console.log(clientIp);
// { ip: '177.139.100.100'', isPublic: true, isRouteTrusted: false }
// do something with the ip address (e.g. pass it within the request)
// note: ip address doesn't change often, so better cache it for performance
req.ipInfo = ipware.getClientIP(req)
// { ip: '177.139.100.100', isPublic: true, isRouteTrusted: false }
// do something with the ip address (e.g. pass it down through the request)
// note: ip address doesn't change often, so better cache it for performance,
// you should have distinct session ID for public and anonymous users to cache the ip address
next();

@@ -49,2 +49,14 @@ });

| Flags ⇩ | ⇩ Description |
| -------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `count` ⇨ | : Total number of expected proxies (pattern: `client, proxy1, ..., proxy2`)<br>: if `count = 0` then `client`<br>: if `count = 1` then `client, proxy1`<br>: if `count = 2` then `client, proxy1, proxy2` <br>: if `count = 3` then `client, proxy1, proxy2 proxy3` |
| `proxyList` ⇨ | : List of trusted proxies (pattern: `client, proxy1, ..., proxy2`)<br>: if `proxyList = ['10.1.']` then `client, 10.1.1.1` OR `client, proxy1, 10.1.1.1`<br>: if `proxyList = ['10.1', '10.2.']` then `client, 10.1.1.1` OR `client, proxy1, 10.2.2.2`<br>: if `proxyList = ['10.1', '10.2.']` then `client, 10.1.1.1 10.2.2.2` OR `client, 10.1.1.1 10.2.2.2` |
| `publicOnly` ⇨ | : Returns only public and internet routable IP or null |
| Output Field ⇩ | ⇩ Description |
| -----------------: | :------------------------------------------------------------------------------- |
| `ip` ⇨ | : IP address of the client |
| `isPublic` ⇨ | : If `ip` is public and internet routable, `true`, else `false` |
| `isRouteTrusted` ⇨ | : If proxy `count` and/or `proxyList` provided and matched, `true`, else `false` |
### Precedence Order

@@ -82,7 +94,7 @@

ipware.getClientIP(request, {
requestHeadersOrder: ['X_FORWARDED_FOR'], // server deployed on providers that ONLY use `X_FORWARDED_FOR`.
requestHeadersOrder: ['X_FORWARDED_FOR'],
});
ipware.getClientIP(request, {
requestHeadersOrder: ['X_FORWARDED_FOR', 'HTTP_X_FORWARDED_FOR'], // servers(s) deployed on multiple providers
requestHeadersOrder: ['X_FORWARDED_FOR', 'HTTP_X_FORWARDED_FOR'],
});

@@ -95,5 +107,7 @@

A default list that holds the private address prefixes is called `IPWARE_PRIVATE_IP_PREFIX`.
A default list that holds the private IP prefixes is called `IPWARE_PRIVATE_IP_PREFIX`.
This list is used to determine if an IP address is `public` or `private`.
It is recommended that you send us any `private` IP addresses that we have missed, to be included in the default list.
```typescript

@@ -165,7 +179,7 @@ export const IPWARE_PRIVATE_IP_PREFIX: string[] = [

// For proxy by ip address, count will be ignored
// For proxy by ip address and count
const ipInfo = ipware.getClientIP(request, {
proxy: {
proxyList: ['177.139.', '177.140'],
proxyCount: 2 // will be ignored
count: 2
},

@@ -208,7 +222,7 @@ });

// For proxy by count, proxy prefixes will be ignored
// For proxy by count, and proxy list
const ipInfo = ipware.getClientIP(request, {
proxy: {
count: 1
proxyList: ['177.139.233.'] // will be ignored
proxyList: ['177.139.233.']
},

@@ -215,0 +229,0 @@ });

@@ -14,3 +14,5 @@ /**

/**
* Given a string, it returns an object of IpwareIpInfo.
* Returns the IP address of the request headers ip attribute
* @param {ip} string containing an ip address
* @returns an object of type IpwareIpInfo if ip address is valid, else undefined
*/

@@ -42,3 +44,3 @@ private getInfo;

*/
getClientIP(request: any, callOptions?: IpwareCallOptions): IpwareIpInfo;
getClientIP(request: any, callOptions?: IpwareCallOptions): IpwareIpInfo | null;
}

@@ -21,3 +21,5 @@ "use strict";

/**
* Given a string, it returns an object of IpwareIpInfo.
* Returns the IP address of the request headers ip attribute
* @param {ip} string containing an ip address
* @returns an object of type IpwareIpInfo if ip address is valid, else undefined
*/

@@ -30,3 +32,3 @@ getInfo(ip) {

}
return ipware_default_1.IPWARE_DEFAULT_IP_INFO;
return undefined;
}

@@ -108,3 +110,3 @@ /**

ipInfo = this.getInfo(clientIp);
if (ipInfo.ip) {
if (ipInfo === null || ipInfo === void 0 ? void 0 : ipInfo.ip) {
ipInfo.isRouteTrusted = true;

@@ -122,3 +124,3 @@ // configuration is strictly looking for a public ip address only, or none at all, continue processing ...

ipInfo = this.getInfo(clientIp);
if (ipInfo.ip) {
if (ipInfo === null || ipInfo === void 0 ? void 0 : ipInfo.ip) {
// configuration is strictly looking for a public ip address only, or none at all

@@ -137,3 +139,3 @@ if (options.publicOnly && !ipInfo.isPublic) {

if (options.proxy.strict && (options.proxy.proxyList.length > 0 || options.proxy.count > 0)) {
return ipware_default_1.IPWARE_DEFAULT_IP_INFO;
return null;
}

@@ -143,3 +145,3 @@ // no ip address from headers, let's fallback to the request itself

ipInfo = this.getInfo(reqIp);
if (ipInfo.ip) {
if (ipInfo === null || ipInfo === void 0 ? void 0 : ipInfo.ip) {
// configuration is strictly looking for a public ip address only, or none at all

@@ -155,3 +157,3 @@ if (options.publicOnly && ipInfo.isPublic) {

if (options.publicOnly) {
return ipware_default_1.IPWARE_DEFAULT_IP_INFO;
return null;
}

@@ -167,3 +169,3 @@ // the best private ip address is the first one in the list

// unable to find any ip, return empty and let the caller decide what to do
return ipware_default_1.IPWARE_DEFAULT_IP_INFO;
return null;
}

@@ -170,0 +172,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc