fakefilter 0.1.401 → 0.1.403

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 CHANGED
@@ -31,6 +31,10 @@ You may use one of these formats to have access to the information flow in your
31
31
  [Json](json/data.json)
32
32
  This format supports firstseen,lastseen,randomSubdomain properties
33
33
 
34
+ [Json v2](json/data_version2.json)
35
+ A fakedomain might belong to multiple providers, in this format we list their PSL (Public Suffix List) based domain and all known hostnames belonging to this PSL domain. Ths version also supports IDN domains, all domains are punycode.
36
+
37
+
34
38
  [Txt](txt/data.txt)
35
39
 
36
40
  ## Whitelist
package/index.js CHANGED
@@ -6,8 +6,12 @@
6
6
 
7
7
  */
8
8
  const assert = require('assert');
9
- const static_json = require('./json/data.json')
9
+ const static_json_v1 = require('./json/data.json')
10
10
  const https = require('https')
11
+ const http = require('http')
12
+ const apiserver = "https://fakefilter.net"
13
+ // const apiserver = "http://127.0.0.1:5520" -- local tests
14
+ const scheme = apiserver.search(/^https/) === 0 ? "https" : "http"
11
15
 
12
16
  function hostnameFromEmailAddress(email) {
13
17
  if (email && typeof email === 'string' && email.search(/@/) > 0)
@@ -16,7 +20,7 @@ function hostnameFromEmailAddress(email) {
16
20
  }
17
21
 
18
22
  function isFakeDomain(domain, json = false) {
19
- if (!json) json = static_json
23
+ if (!json) json = static_json_v1
20
24
  for (let dom of Object.keys(json.domains)) {
21
25
  // exact match
22
26
  if (dom === domain.toLowerCase().trim()) return dom
@@ -26,10 +30,13 @@ function isFakeDomain(domain, json = false) {
26
30
  return false
27
31
  }
28
32
 
29
- function fetch(url, timeout = 5000,json=true) {
33
+ function fetch(url, timeout = 5000, json = true) {
30
34
  return new Promise(async function (resolve, reject) {
31
35
  try {
32
- let request = https.get(url, (res) => {
36
+ let proto = apiserver.search(/^https/) === 0 ? https : http
37
+
38
+
39
+ let request = proto.get(url, (res) => {
33
40
  if (res.statusCode !== 200) {
34
41
  res.resume()
35
42
  return reject('STATUSCODE')
@@ -40,7 +47,7 @@ function fetch(url, timeout = 5000,json=true) {
40
47
  if (json) {
41
48
  try {
42
49
  return resolve(JSON.parse(data))
43
- }catch(err) {
50
+ } catch (err) {
44
51
  return resolve(false)
45
52
  }
46
53
  }
@@ -67,20 +74,20 @@ function isFakeEmail(email, json = false) {
67
74
  return isFakeDomain(hostnameFromEmailAddress(email), json)
68
75
  }
69
76
 
70
- function isFakeEmailOnline(email, timeout=5000) {
77
+ function isFakeEmailOnline(email, timeout = 5000) {
71
78
  return isFakeDomainOnline(hostnameFromEmailAddress(email), timeout)
72
79
  }
73
80
 
74
81
 
75
- function isFakeDomainOnline(domain,timeout=5000) {
82
+ function isFakeDomainOnline(domain, timeout = 5000) {
76
83
  // we intentionally do not reject because we do not want to hold
77
84
  // the process too long, null indicates error
78
85
  return new Promise(async function (resolve, reject) {
79
86
  try {
80
- let answer = await fetch(`https://fakefilter.net/api/is/fakedomain/${domain}`,timeout,true)
81
- if (answer && answer.hasOwnProperty('retcode') && answer.retcode===200)
87
+ let answer = await fetch(`${apiserver}/api/is/fakedomain/${domain}`, timeout, true)
88
+ if (answer && answer.hasOwnProperty('retcode') && answer.retcode === 200)
82
89
  return resolve(answer)
83
- }catch(err) {
90
+ } catch (err) {
84
91
  // error returns null
85
92
  return resolve(null)
86
93
  }
@@ -92,7 +99,7 @@ async function runTests() {
92
99
 
93
100
  // not existing domain
94
101
  try {
95
- await fetch(`https://nonexisting${Date.now()}.com`)
102
+ await fetch(`${scheme}://nonexisting${Date.now()}.com`)
96
103
  assert.equal(false, true) // we should never reach this position
97
104
  } catch (err) {
98
105
  assert.equal(err.code, 'ENOTFOUND')
@@ -100,7 +107,7 @@ async function runTests() {
100
107
 
101
108
  // not existing url on existing domain
102
109
  try {
103
- await fetch(`https://fakefilter.net/notexisting`)
110
+ await fetch(`${apiserver}/notexisting`)
104
111
  assert.equal(false, true) // we should never reach this position
105
112
  } catch (err) {
106
113
  assert.equal(err, 'STATUSCODE')
@@ -125,19 +132,19 @@ async function runTests() {
125
132
 
126
133
  // 404
127
134
  try {
128
- await fetch(`https://fakefilter.net/api/is/fakedomain/`)
135
+ await fetch(`${apiserver}/api/is/fakedomain/`)
129
136
  assert.equal(false, true) // we should never reach this position
130
137
  } catch (err) {
131
138
  assert.equal(err, 'STATUSCODE')
132
139
  }
133
140
 
134
141
  // non FakeDomain
135
- assert.equal((await fetch(`https://fakefilter.net/api/is/fakedomain/fakefilter.net`)).retcode,200)
142
+ assert.equal((await fetch(`${apiserver}/api/is/fakedomain/fakefilter.net`)).retcode, 200)
136
143
  // FakeDomain
137
- assert.equal((await fetch(`https://fakefilter.net/api/is/fakedomain/fakefilte r.net`)).retcode,-50)
144
+ assert.equal((await fetch(`${apiserver}/api/is/fakedomain/fakefilte r.net`)).retcode, -50)
138
145
 
139
146
 
140
- let json = static_json
147
+ let json = static_json_v1
141
148
  console.log(`Running tests`)
142
149
  let all_domains = Object.keys(json.domains)
143
150
 
@@ -163,9 +170,9 @@ async function runTests() {
163
170
  assert.notEqual(isFakeEmail(`any@sub.${domain}`), false)
164
171
 
165
172
  // RESTFul API query
166
- assert.equal((await isFakeDomainOnline(domain)).isFakeDomain,domain)
173
+ assert.equal((await isFakeDomainOnline(domain)).isFakeDomain, domain)
167
174
  assert.equal((await isFakeEmailOnline(`any@${domain}`)).isFakeDomain, domain)
168
- assert.equal((await isFakeEmailOnline(`any@sub${domain}`)).isFakeDomain, false)
175
+ assert.equal((await isFakeEmailOnline(`any@sub.${domain}`)).isFakeDomain, "sub." + domain)
169
176
  }
170
177
  console.log(`OK`)
171
178
  process.exit(0)
@@ -183,3 +190,4 @@ module.exports = {
183
190
  isFakeDomainOnline,
184
191
  isFakeEmailOnline
185
192
  }
193
+