npq 3.21.3 → 3.21.4

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 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
149
+ | expired domains | Normalizes and checks complete maintainer email hosts, warning only when a simple two-label domain does not resolve but its public top-level domain does | Multipart and otherwise inconclusive DNS failures are reported as not evaluated; non-resolution is not proof that a 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
@@ -0,0 +1,77 @@
1
+ 'use strict'
2
+
3
+ const { isIP } = require('node:net')
4
+ const { domainToASCII } = require('node:url')
5
+
6
+ const SPECIAL_USE_SUFFIXES = new Set([
7
+ 'alt',
8
+ 'corp',
9
+ 'example',
10
+ 'home',
11
+ 'internal',
12
+ 'invalid',
13
+ 'local',
14
+ 'localhost',
15
+ 'mail',
16
+ 'onion',
17
+ 'test'
18
+ ])
19
+ const RESERVED_HOSTS = new Set([
20
+ 'example.com',
21
+ 'example.net',
22
+ 'example.org',
23
+ 'home.arpa',
24
+ 'in-addr.arpa',
25
+ 'ip6.arpa'
26
+ ])
27
+
28
+ function hasReservedSuffix(hostname, suffixes) {
29
+ return [...suffixes].some((suffix) => hostname === suffix || hostname.endsWith(`.${suffix}`))
30
+ }
31
+
32
+ function normalizeMaintainerDomain(maintainerEmail) {
33
+ const atIndex = typeof maintainerEmail === 'string' ? maintainerEmail.lastIndexOf('@') : -1
34
+ const hasOneAtSign = atIndex > 0 && maintainerEmail.indexOf('@') === atIndex
35
+ const emailDomain = atIndex > 0 ? maintainerEmail.slice(atIndex + 1).trim() : ''
36
+
37
+ if (!hasOneAtSign || !emailDomain || /\s/.test(emailDomain)) {
38
+ return null
39
+ }
40
+
41
+ const hostname = emailDomain.replace(/\.$/, '').toLowerCase()
42
+ const bracketedIp = hostname.match(/^\[(.*)\]$/)
43
+ if (isIP(bracketedIp ? bracketedIp[1] : hostname)) {
44
+ return null
45
+ }
46
+
47
+ const asciiHostname = domainToASCII(hostname).toLowerCase()
48
+ const labels = asciiHostname.split('.')
49
+ const labelsAreValid = labels.every(
50
+ (label) =>
51
+ label.length > 0 &&
52
+ label.length <= 63 &&
53
+ /^[a-z0-9-]+$/.test(label) &&
54
+ !label.startsWith('-') &&
55
+ !label.endsWith('-')
56
+ )
57
+
58
+ if (
59
+ !asciiHostname ||
60
+ isIP(asciiHostname) ||
61
+ asciiHostname.length > 253 ||
62
+ labels.length < 2 ||
63
+ !labelsAreValid ||
64
+ hasReservedSuffix(asciiHostname, SPECIAL_USE_SUFFIXES) ||
65
+ hasReservedSuffix(asciiHostname, RESERVED_HOSTS)
66
+ ) {
67
+ return null
68
+ }
69
+
70
+ return asciiHostname
71
+ }
72
+
73
+ function isSimpleMaintainerDomain(domain) {
74
+ return domain.split('.').length === 2
75
+ }
76
+
77
+ module.exports = { isSimpleMaintainerDomain, normalizeMaintainerDomain }
@@ -4,6 +4,10 @@ const BaseMarshall = require('./baseMarshall')
4
4
  const { marshallCategories } = require('./constants')
5
5
  const NotEvaluated = require('../helpers/notEvaluated')
6
6
  const Warning = require('../helpers/warning')
7
+ const {
8
+ isSimpleMaintainerDomain,
9
+ normalizeMaintainerDomain
10
+ } = require('../helpers/maintainerDomain')
7
11
  const { Resolver } = require('dns/promises')
8
12
 
9
13
  const dns = new Resolver()
@@ -36,17 +40,9 @@ class Marshall extends BaseMarshall {
36
40
  const emailDomains = new Map()
37
41
  let invalidMaintainers = 0
38
42
  for (const maintainerInfo of maintainersAccounts) {
39
- const maintainerEmail = maintainerInfo && maintainerInfo.email
40
- const atIndex = typeof maintainerEmail === 'string' ? maintainerEmail.lastIndexOf('@') : -1
41
- const emailDomain =
42
- atIndex > 0
43
- ? maintainerEmail
44
- .slice(atIndex + 1)
45
- .trim()
46
- .toLowerCase()
47
- : ''
48
-
49
- if (!emailDomain || emailDomain.includes('@') || /\s/.test(emailDomain)) {
43
+ const emailDomain = normalizeMaintainerDomain(maintainerInfo && maintainerInfo.email)
44
+
45
+ if (!emailDomain) {
50
46
  invalidMaintainers += 1
51
47
  continue
52
48
  }
@@ -62,7 +58,7 @@ class Marshall extends BaseMarshall {
62
58
  const resolutionResults = await Promise.allSettled(
63
59
  domains.map((emailDomain) => this.dnsResolver.resolve(emailDomain, 'NS'))
64
60
  )
65
- const suspectedDomains = []
61
+ const simpleMissingDomains = []
66
62
  const incompleteDomains = []
67
63
 
68
64
  resolutionResults.forEach((result, index) => {
@@ -78,13 +74,43 @@ class Marshall extends BaseMarshall {
78
74
  errorCode || '<unknown>'
79
75
  )
80
76
 
81
- if (errorCode === 'ENOTFOUND') {
82
- suspectedDomains.push(domain)
77
+ if (errorCode === 'ENOTFOUND' && isSimpleMaintainerDomain(domain)) {
78
+ simpleMissingDomains.push(domain)
83
79
  } else {
84
80
  incompleteDomains.push(domain)
85
81
  }
86
82
  })
87
83
 
84
+ const topLevelDomains = [
85
+ ...new Set(simpleMissingDomains.map((domain) => domain.split('.')[1]))
86
+ ].sort()
87
+ const topLevelResults = await Promise.allSettled(
88
+ topLevelDomains.map((domain) => this.dnsResolver.resolve(domain, 'NS'))
89
+ )
90
+ const publicTopLevelDomains = new Set()
91
+
92
+ topLevelResults.forEach((result, index) => {
93
+ const domain = topLevelDomains[index]
94
+ if (result.status === 'fulfilled') {
95
+ publicTopLevelDomains.add(domain)
96
+ return
97
+ }
98
+
99
+ this.debug(
100
+ '\nUnable to verify public top-level domain %s with code %s',
101
+ domain,
102
+ (result.reason && result.reason.code) || '<unknown>'
103
+ )
104
+ })
105
+
106
+ const suspectedDomains = simpleMissingDomains.filter((domain) => {
107
+ const isPublic = publicTopLevelDomains.has(domain.split('.')[1])
108
+ if (!isPublic) {
109
+ incompleteDomains.push(domain)
110
+ }
111
+ return isPublic
112
+ })
113
+
88
114
  const incompleteCount =
89
115
  invalidMaintainers +
90
116
  incompleteDomains.reduce((count, domain) => count + emailDomains.get(domain), 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "npq",
3
- "version": "3.21.3",
3
+ "version": "3.21.4",
4
4
  "description": "marshall your npm/npm package installs with high quality and class 🎖",
5
5
  "bin": {
6
6
  "npq": "./bin/npq.js",