@hackthedev/dsync-ipsec 1.0.0 → 1.0.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.
- package/README.md +153 -1
- package/index.mjs +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,2 +1,154 @@
|
|
|
1
1
|
# dSyncIPSec
|
|
2
|
-
|
|
2
|
+
This library comes with features meant to prevent abuse in form of spam and other malicious activities and comes with the following detections and features:
|
|
3
|
+
|
|
4
|
+
- Block known abusers, bogon IPs, datacenters, crawlers, proxies, satelites, Tor IPs and VPNs.
|
|
5
|
+
- Possibility to block traffic from entire Countries
|
|
6
|
+
- Whitelist and Blacklist feature based on IP address and Company Domains
|
|
7
|
+
|
|
8
|
+
The library was designed for usage with `express` and filtering abusive and (potentially) malicious traffic based on the IP address.
|
|
9
|
+
|
|
10
|
+
------
|
|
11
|
+
|
|
12
|
+
## Setup
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
import dSyncIPSec from "@hackthedev/dsync-ipsec"
|
|
16
|
+
|
|
17
|
+
// will use default settings
|
|
18
|
+
export let ipsec = new dSyncIPSec();
|
|
19
|
+
|
|
20
|
+
// alternatively, with settings already specified.
|
|
21
|
+
// settings shown here are the default settings.
|
|
22
|
+
export let ipsec = new dSyncIPSec({
|
|
23
|
+
blockBogon: true,
|
|
24
|
+
blockDatacenter: true,
|
|
25
|
+
blockSatelite: true,
|
|
26
|
+
blockCrawler: true,
|
|
27
|
+
blockProxy: true,
|
|
28
|
+
blockVPN: true,
|
|
29
|
+
blockTor: true,
|
|
30
|
+
blockAbuser: true,
|
|
31
|
+
// some arrays
|
|
32
|
+
whitelistedUrls: [],
|
|
33
|
+
whitelistedIps: [],
|
|
34
|
+
blockedCountryCodes: [],
|
|
35
|
+
whitelistedCompanyDomains: [],
|
|
36
|
+
blacklistedIps = [
|
|
37
|
+
"::1",
|
|
38
|
+
"127.0.0.1",
|
|
39
|
+
"localhost"
|
|
40
|
+
]
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
------
|
|
45
|
+
|
|
46
|
+
## Updating settings
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
// you can only specify the keys that you actually want to update
|
|
50
|
+
ipsec.updateRule({
|
|
51
|
+
blockBogon: true,
|
|
52
|
+
blockSatelite: true,
|
|
53
|
+
blockCrawler: true,
|
|
54
|
+
blockProxy: true,
|
|
55
|
+
blockVPN: true,
|
|
56
|
+
blockTor: true,
|
|
57
|
+
blockAbuser: true,
|
|
58
|
+
|
|
59
|
+
whitelistedUrls: [],
|
|
60
|
+
whitelistedIps: [],
|
|
61
|
+
blacklistedIps: [],
|
|
62
|
+
companyDomainWhitelist: [],
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
------
|
|
67
|
+
|
|
68
|
+
## Filtering express traffic
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
await ipsec.filterExpressTraffic(app)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
------
|
|
75
|
+
|
|
76
|
+
## Manually getting IP Info
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
await lookupIP("1.1.1.1")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Example response object:
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"ip": "1.1.1.1",
|
|
87
|
+
"rir": "APNIC",
|
|
88
|
+
"is_bogon": false,
|
|
89
|
+
"is_mobile": false,
|
|
90
|
+
"is_satellite": false,
|
|
91
|
+
"is_crawler": false,
|
|
92
|
+
"is_datacenter": true,
|
|
93
|
+
"is_tor": false,
|
|
94
|
+
"is_proxy": false,
|
|
95
|
+
"is_vpn": false,
|
|
96
|
+
"is_abuser": true,
|
|
97
|
+
"datacenter": {
|
|
98
|
+
"datacenter": "kamatera.com",
|
|
99
|
+
"network": "1.1.1.1/24",
|
|
100
|
+
"country": "HK",
|
|
101
|
+
"city": "Hong Kong",
|
|
102
|
+
"postal": "0"
|
|
103
|
+
},
|
|
104
|
+
"company": {
|
|
105
|
+
"name": "APNIC Research and Development",
|
|
106
|
+
"abuser_score": "0.0156 (Elevated)",
|
|
107
|
+
"domain": "apnic.net",
|
|
108
|
+
"type": "business",
|
|
109
|
+
"network": "1.1.1.0 - 1.1.1.255",
|
|
110
|
+
"whois": "https://api.ipapi.is/?whois=1.1.1.0"
|
|
111
|
+
},
|
|
112
|
+
"abuse": {
|
|
113
|
+
"name": "APNIC Research and Development",
|
|
114
|
+
"address": "6 Cordelia St",
|
|
115
|
+
"email": "helpdesk@apnic.net",
|
|
116
|
+
"phone": "+61-7-38583100"
|
|
117
|
+
},
|
|
118
|
+
"asn": {
|
|
119
|
+
"asn": 13335,
|
|
120
|
+
"abuser_score": "0.0267 (Elevated)",
|
|
121
|
+
"route": "1.1.1.0/24",
|
|
122
|
+
"descr": "CLOUDFLARENET, US",
|
|
123
|
+
"country": "us",
|
|
124
|
+
"active": true,
|
|
125
|
+
"org": "Cloudflare, Inc.",
|
|
126
|
+
"domain": "cloudflare.com",
|
|
127
|
+
"abuse": "abuse@cloudflare.com",
|
|
128
|
+
"type": "hosting",
|
|
129
|
+
"created": "2010-07-14",
|
|
130
|
+
"updated": "2017-02-17",
|
|
131
|
+
"rir": "ARIN",
|
|
132
|
+
"whois": "https://api.ipapi.is/?whois=AS13335"
|
|
133
|
+
},
|
|
134
|
+
"location": {
|
|
135
|
+
"is_eu_member": false,
|
|
136
|
+
"calling_code": "61",
|
|
137
|
+
"currency_code": "AUD",
|
|
138
|
+
"continent": "OC",
|
|
139
|
+
"country": "Australia",
|
|
140
|
+
"country_code": "AU",
|
|
141
|
+
"state": "New South Wales",
|
|
142
|
+
"city": "Sydney",
|
|
143
|
+
"latitude": -33.86785,
|
|
144
|
+
"longitude": 151.20732,
|
|
145
|
+
"zip": "1001",
|
|
146
|
+
"timezone": "Australia/Sydney",
|
|
147
|
+
"local_time": "2026-01-16T15:26:18+11:00",
|
|
148
|
+
"local_time_unix": 1768537578,
|
|
149
|
+
"is_dst": true
|
|
150
|
+
},
|
|
151
|
+
"elapsed_ms": 0.16
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
package/index.mjs
CHANGED
|
@@ -48,6 +48,12 @@ export default class dSyncIPSec {
|
|
|
48
48
|
blockVPN = null,
|
|
49
49
|
blockTor = null,
|
|
50
50
|
blockAbuser = null,
|
|
51
|
+
|
|
52
|
+
whitelistedUrls = null,
|
|
53
|
+
whitelistedIps = null,
|
|
54
|
+
blockedCountryCodes = null,
|
|
55
|
+
whitelistedCompanyDomains = null,
|
|
56
|
+
blacklistedIps = null,
|
|
51
57
|
}){
|
|
52
58
|
|
|
53
59
|
if(blockBogon !== null) this.blockBogon = blockBogon
|
|
@@ -58,8 +64,14 @@ export default class dSyncIPSec {
|
|
|
58
64
|
if(blockVPN !== null) this.blockVPN = blockVPN
|
|
59
65
|
if(blockTor !== null) this.blockTor = blockTor
|
|
60
66
|
if(blockAbuser !== null) this.blockAbuser = blockAbuser
|
|
67
|
+
|
|
68
|
+
if(whitelistedUrls !== null) this.urlWhitelist = new ArrayTools(whitelistedUrls)
|
|
69
|
+
if(whitelistedIps !== null) this.ipWhitelist = new ArrayTools(whitelistedIps)
|
|
70
|
+
if(blacklistedIps !== null) this.ipBlacklist = new ArrayTools(blacklistedIps)
|
|
71
|
+
if(blockedCountryCodes !== null) this.blockedCountriesByCode = new ArrayTools(blockedCountryCodes)
|
|
61
72
|
}
|
|
62
73
|
|
|
74
|
+
|
|
63
75
|
whitelistIP(ip, allowDuplicates = false){
|
|
64
76
|
if(!ip) throw new Error("Unable to whitelist ip as no ip was provided.");
|
|
65
77
|
if(!this.ipWhitelist.matches(ip) && !allowDuplicates) this.ipWhitelist.addEntry(ip);
|