npq 3.21.2 → 3.21.3

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
@@ -146,7 +146,7 @@ Note: `npq` by default will offload all commands and their arguments to the `npm
146
146
  | scripts | Will show a warning if a package has a pre/post install script which could potentially be malicious
147
147
  | snyk | Will show a warning if a package has been found with vulnerabilities in Snyk's database | For Snyk to work you need to either have the `snyk` npm package installed with a valid API token, or make the token available in the `SNYK_TOKEN` environment variable, and npq will use it
148
148
  | license | Will show a warning if a package has been found without a license field | Checks the latest version for a license
149
- | expired domains | Will show a warning if a package has been found with one of its maintainers having an email address that includes an expired domain | Checks a dependency version for a maintainer with an expired domain
149
+ | expired domains | Will warn when a maintainer email domain does not resolve in public DNS; inconclusive DNS failures are reported as not evaluated | DNS non-resolution is a risk signal, not proof that the domain is expired or available
150
150
  | signatures | Will compare the package's signature as it shows on the registry's packument with signing keys published by the selected registry | Reports `not evaluated` if the selected registry does not expose signing keys
151
151
  | provenance | Will verify the package's attestations of provenance metadata for the published package, and **error** on [provenance regression](docs/feature/provenance.md) (an older semver had registry provenance metadata but the version you install does not) | Reports `not evaluated` if the selected registry does not expose signing keys or attestations
152
152
  | version-maturity | Will show a warning if the specific version being installed was published less than 7 days ago | Helps identify recently published versions that may not have been reviewed by the community yet
@@ -3,6 +3,7 @@
3
3
  const BaseMarshall = require('./baseMarshall')
4
4
  const { marshallCategories } = require('./constants')
5
5
  const NotEvaluated = require('../helpers/notEvaluated')
6
+ const Warning = require('../helpers/warning')
6
7
  const { Resolver } = require('dns/promises')
7
8
 
8
9
  const dns = new Resolver()
@@ -32,44 +33,82 @@ class Marshall extends BaseMarshall {
32
33
  throw new NotEvaluated('no maintainers information available for the package')
33
34
  }
34
35
 
35
- const emailDomains = []
36
+ const emailDomains = new Map()
36
37
  let invalidMaintainers = 0
37
38
  for (const maintainerInfo of maintainersAccounts) {
38
39
  const maintainerEmail = maintainerInfo && maintainerInfo.email
39
40
  const atIndex = typeof maintainerEmail === 'string' ? maintainerEmail.lastIndexOf('@') : -1
40
- const emailDomain = atIndex > 0 ? maintainerEmail.slice(atIndex + 1).trim() : ''
41
+ const emailDomain =
42
+ atIndex > 0
43
+ ? maintainerEmail
44
+ .slice(atIndex + 1)
45
+ .trim()
46
+ .toLowerCase()
47
+ : ''
41
48
 
42
49
  if (!emailDomain || emailDomain.includes('@') || /\s/.test(emailDomain)) {
43
50
  invalidMaintainers += 1
44
51
  continue
45
52
  }
46
53
 
47
- emailDomains.push(emailDomain)
54
+ emailDomains.set(emailDomain, (emailDomains.get(emailDomain) || 0) + 1)
48
55
  }
49
56
 
50
- if (emailDomains.length === 0) {
57
+ if (emailDomains.size === 0) {
51
58
  throw new NotEvaluated('no valid maintainer email domains are available for the package')
52
59
  }
53
60
 
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
61
+ const domains = [...emailDomains.keys()].sort()
62
+ const resolutionResults = await Promise.allSettled(
63
+ domains.map((emailDomain) => this.dnsResolver.resolve(emailDomain, 'NS'))
64
+ )
65
+ const suspectedDomains = []
66
+ const incompleteDomains = []
67
+
68
+ resolutionResults.forEach((result, index) => {
69
+ if (result.status === 'fulfilled') {
70
+ return
71
+ }
72
+
73
+ const domain = domains[index]
74
+ const errorCode = result.reason && result.reason.code
75
+ this.debug(
76
+ '\nUnable to resolve maintainer email domain %s with code %s',
77
+ domain,
78
+ errorCode || '<unknown>'
64
79
  )
80
+
81
+ if (errorCode === 'ENOTFOUND') {
82
+ suspectedDomains.push(domain)
83
+ } else {
84
+ incompleteDomains.push(domain)
85
+ }
86
+ })
87
+
88
+ const incompleteCount =
89
+ invalidMaintainers +
90
+ incompleteDomains.reduce((count, domain) => count + emailDomains.get(domain), 0)
91
+ if (suspectedDomains.length > 0) {
92
+ const domainNoun = suspectedDomains.length === 1 ? 'domain' : 'domains'
93
+ const resolveVerb = suspectedDomains.length === 1 ? 'does' : 'do'
94
+ let message = `Maintainer ${domainNoun} ${suspectedDomains.join(', ')} ${resolveVerb} not resolve in public DNS and may warrant investigation.`
95
+
96
+ if (incompleteCount > 0) {
97
+ const recordNoun = incompleteCount === 1 ? 'record' : 'records'
98
+ message += ` ${incompleteCount} other maintainer ${recordNoun} could not be evaluated.`
99
+ }
100
+
101
+ throw new Warning(message)
65
102
  }
66
103
 
67
- if (invalidMaintainers > 0) {
68
- const noun = invalidMaintainers === 1 ? 'address is' : 'addresses are'
69
- throw new NotEvaluated(`${invalidMaintainers} maintainer email ${noun} missing or malformed`)
104
+ if (incompleteCount > 0) {
105
+ const recordNoun = incompleteCount === 1 ? 'record' : 'records'
106
+ throw new NotEvaluated(
107
+ `${incompleteCount} maintainer ${recordNoun} could not be evaluated because DNS or email data was incomplete`
108
+ )
70
109
  }
71
110
 
72
- return resolutionResults
111
+ return resolutionResults.map((result) => result.value)
73
112
  }
74
113
  }
75
114
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npq",
3
- "version": "3.21.2",
3
+ "version": "3.21.3",
4
4
  "description": "marshall your npm/npm package installs with high quality and class 🎖",
5
5
  "bin": {
6
6
  "npq": "./bin/npq.js",