npq 3.21.1 → 3.21.2

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.
@@ -14,45 +14,62 @@ class Marshall extends BaseMarshall {
14
14
  super(options)
15
15
  this.name = MARSHALL_NAME
16
16
  this.categoryId = marshallCategories.PackageHealth.id
17
+ this.dnsResolver = options.dnsResolver || dns
17
18
  }
18
19
 
19
20
  title() {
20
21
  return 'Detecting expired domains for authors account...'
21
22
  }
22
23
 
23
- validate(pkg) {
24
- return this.packageRepoUtils
25
- .getPackageInfo(pkg.packageName)
26
- .then((data) => {
27
- const lastVersionData =
28
- data.versions && data['dist-tags'] && data.versions[data['dist-tags'].latest]
29
-
30
- const maintainersAccounts = lastVersionData && lastVersionData.maintainers
31
-
32
- if (!Array.isArray(maintainersAccounts) || maintainersAccounts.length === 0) {
33
- throw new NotEvaluated('no maintainers information available for the package')
34
- }
35
-
36
- const testEmails = []
37
- for (const maintainerInfo of maintainersAccounts) {
38
- const maintainerEmail = maintainerInfo.email
39
- const emailDomain = maintainerEmail.split('@')[1]
40
- testEmails.push(dns.resolve(emailDomain, 'NS'))
41
- }
42
-
43
- return Promise.all(testEmails)
44
- })
45
- .catch((error) => {
46
- if (error instanceof NotEvaluated) {
47
- throw error
48
- }
49
-
50
- const emailHostname = error.hostname ? error.hostname : '<unknown>'
51
- this.debug('\nDetected error resolving domain for maintainer e-mail: %s', emailHostname)
52
- throw new Error(
53
- 'Detected expired domain can be abused for account takeover: ' + emailHostname
54
- )
55
- })
24
+ async validate(pkg) {
25
+ const data = await this.packageRepoUtils.getPackageInfo(pkg.packageName)
26
+ const lastVersionData =
27
+ data.versions && data['dist-tags'] && data.versions[data['dist-tags'].latest]
28
+
29
+ const maintainersAccounts = lastVersionData && lastVersionData.maintainers
30
+
31
+ if (!Array.isArray(maintainersAccounts) || maintainersAccounts.length === 0) {
32
+ throw new NotEvaluated('no maintainers information available for the package')
33
+ }
34
+
35
+ const emailDomains = []
36
+ let invalidMaintainers = 0
37
+ for (const maintainerInfo of maintainersAccounts) {
38
+ const maintainerEmail = maintainerInfo && maintainerInfo.email
39
+ const atIndex = typeof maintainerEmail === 'string' ? maintainerEmail.lastIndexOf('@') : -1
40
+ const emailDomain = atIndex > 0 ? maintainerEmail.slice(atIndex + 1).trim() : ''
41
+
42
+ if (!emailDomain || emailDomain.includes('@') || /\s/.test(emailDomain)) {
43
+ invalidMaintainers += 1
44
+ continue
45
+ }
46
+
47
+ emailDomains.push(emailDomain)
48
+ }
49
+
50
+ if (emailDomains.length === 0) {
51
+ throw new NotEvaluated('no valid maintainer email domains are available for the package')
52
+ }
53
+
54
+ let resolutionResults
55
+ try {
56
+ resolutionResults = await Promise.all(
57
+ emailDomains.map((emailDomain) => this.dnsResolver.resolve(emailDomain, 'NS'))
58
+ )
59
+ } catch (error) {
60
+ const emailHostname = error.hostname ? error.hostname : '<unknown>'
61
+ this.debug('\nDetected error resolving domain for maintainer e-mail: %s', emailHostname)
62
+ throw new Error(
63
+ 'Detected expired domain can be abused for account takeover: ' + emailHostname
64
+ )
65
+ }
66
+
67
+ if (invalidMaintainers > 0) {
68
+ const noun = invalidMaintainers === 1 ? 'address is' : 'addresses are'
69
+ throw new NotEvaluated(`${invalidMaintainers} maintainer email ${noun} missing or malformed`)
70
+ }
71
+
72
+ return resolutionResults
56
73
  }
57
74
  }
58
75
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npq",
3
- "version": "3.21.1",
3
+ "version": "3.21.2",
4
4
  "description": "marshall your npm/npm package installs with high quality and class 🎖",
5
5
  "bin": {
6
6
  "npq": "./bin/npq.js",