@hackthedev/dsync-ipsec 1.0.6 → 1.0.7

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.
Files changed (2) hide show
  1. package/index.mjs +8 -2
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -105,8 +105,14 @@ export default class dSyncIPSec {
105
105
  }
106
106
 
107
107
  async checkRequest(req) {
108
- const ipInfo = await this.lookupIP(this.getClientIp(req));
108
+ let clientIP = this.getClientIp(req);
109
+
110
+ // remove localhost ips
111
+ if(clientIP === "::1" || clientIP === "127.0.0.1") return { allow: true }
112
+
113
+ const ipInfo = await this.lookupIP(clientIP);
109
114
  if (!ipInfo) return { allow: true };
115
+ if (ipInfo?.blocked === true) return { allow: false };
110
116
 
111
117
  const reqPath = req.path;
112
118
  if (!reqPath) return { allow: true };
@@ -164,7 +170,7 @@ export default class dSyncIPSec {
164
170
  if (!ip) throw new Error("Unable to lookup ip as it wasnt provided.")
165
171
 
166
172
  // if an ip is blacklisted we return with an error "reponse"
167
- if (this.isBlacklistedIp(ip)) return {error: `IP ${ip} was blacklisted.`};
173
+ if (this.isBlacklistedIp(ip)) return {error: `IP ${ip} was blacklisted.`, blocked: true};
168
174
 
169
175
  // if we use cache we can skip the fetch
170
176
  if (this.checkCache && typeof this.checkCache === "function") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hackthedev/dsync-ipsec",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "IP Based Security Library against Abuse",
5
5
  "license": "ISC",
6
6
  "author": "",