Comparing version 4.5.0 to 4.5.1
@@ -7,3 +7,3 @@ 'use strict'; | ||
const Joi = require('joi'); | ||
const packageData = require('../../package.json'); | ||
//const packageData = require('../../package.json'); | ||
const httpsSchema = Joi.string().uri({ | ||
@@ -13,9 +13,10 @@ scheme: ['https'] | ||
const https = require('https'); | ||
const http = require('http'); | ||
const FETCH_TIMEOUT = 5 * 1000; | ||
const { fetch: fetchCmd, Agent } = require('undici'); | ||
const fetchAgent = new Agent({ connect: { timeout: FETCH_TIMEOUT } }); | ||
const { vmc } = require('@postalsys/vmc'); | ||
const { validateSvg } = require('./validate-svg'); | ||
const HTTP_REQUEST_TIMEOUT = 15 * 1000; | ||
const lookup = async data => { | ||
@@ -182,3 +183,3 @@ let { dmarc, headers, resolver, bimiWithAlignedDkim } = data; | ||
const downloadPromise = (url, cachedFile) => { | ||
const downloadPromise = async (url, cachedFile) => { | ||
if (cachedFile) { | ||
@@ -192,72 +193,20 @@ return cachedFile; | ||
const parsedUrl = new URL(url); | ||
const options = { | ||
protocol: parsedUrl.protocol, | ||
host: parsedUrl.host, | ||
let res = await fetchCmd(url, { | ||
headers: { | ||
host: parsedUrl.host, | ||
'User-Agent': `mailauth/${packageData.version} (+${packageData.homepage}` | ||
// Comment: AKAMAI does some strange UA based filtering that messes up the request | ||
// 'User-Agent': `mailauth/${packageData.version} (+${packageData.homepage}` | ||
}, | ||
servername: parsedUrl.hostname, | ||
port: 443, | ||
path: parsedUrl.pathname, | ||
method: 'GET', | ||
rejectUnauthorized: true, | ||
dispatcher: fetchAgent | ||
}); | ||
timeout: HTTP_REQUEST_TIMEOUT | ||
}; | ||
if (!res.ok) { | ||
let error = new Error(`Request failed with status ${res.status}`); | ||
error.code = 'HTTP_REQUEST_FAILED'; | ||
throw error; | ||
} | ||
return new Promise((resolve, reject) => { | ||
let protoHandler; | ||
switch (parsedUrl.protocol) { | ||
case 'https:': | ||
protoHandler = https; | ||
break; | ||
case 'http:': | ||
protoHandler = http; | ||
break; | ||
default: | ||
reject(new Error(`Unknown protocol ${parsedUrl.protocol}`)); | ||
} | ||
const req = protoHandler.request(options, res => { | ||
let chunks = [], | ||
chunklen = 0; | ||
res.on('readable', () => { | ||
let chunk; | ||
while ((chunk = res.read()) !== null) { | ||
chunks.push(chunk); | ||
chunklen += chunk.length; | ||
} | ||
}); | ||
res.on('end', () => { | ||
let data = Buffer.concat(chunks, chunklen); | ||
if (!res.statusCode || res.statusCode < 200 || res.statusCode >= 300) { | ||
let err = new Error(`Invalid response code ${res.statusCode || '-'}`); | ||
err.code = 'http_status_' + (res.statusCode || 'na'); | ||
if (res.headers.location && res.statusCode >= 300 && res.statusCode < 400) { | ||
err.redirect = { | ||
code: res.statusCode, | ||
location: res.headers.location | ||
}; | ||
} | ||
return reject(err); | ||
} | ||
resolve(data); | ||
}); | ||
res.on('error', err => reject(err)); | ||
}); | ||
let ab = await res.arrayBuffer(); | ||
process.stdout.write(Buffer.from(ab)); | ||
req.on('timeout', () => { | ||
req.destroy(); // cancel request | ||
let error = new Error(`Request timeout for ${parsedUrl.href}`); | ||
error.code = 'HTTP_SOCKET_TIMEOUT'; | ||
reject(error); | ||
}); | ||
req.on('error', err => { | ||
reject(err); | ||
}); | ||
req.end(); | ||
}); | ||
return Buffer.from(ab); | ||
}; | ||
@@ -264,0 +213,0 @@ |
name license type link installed version author | ||
---- ------------ ---- ----------------- ------ | ||
@postalsys/vmc MIT https://registry.npmjs.org/@postalsys/vmc/-/vmc-1.0.6.tgz 1.0.6 Postal Systems OÜ | ||
fast-xml-parser MIT git+https://github.com/NaturalIntelligence/fast-xml-parser.git 4.2.6 Amit Gupta (https://amitguptagwl.github.io) | ||
fast-xml-parser MIT git+https://github.com/NaturalIntelligence/fast-xml-parser.git 4.2.7 Amit Gupta (https://amitguptagwl.github.io) | ||
ipaddr.js MIT git://github.com/whitequark/ipaddr.js.git 2.1.0 whitequark <whitequark@whitequark.org> | ||
@@ -6,0 +6,0 @@ joi BSD-3-Clause git://github.com/hapijs/joi.git 17.9.2 n/a |
{ | ||
"name": "mailauth", | ||
"version": "4.5.0", | ||
"version": "4.5.1", | ||
"description": "Email authentication library for Node.js", | ||
@@ -38,3 +38,3 @@ "main": "lib/mailauth.js", | ||
"eslint-config-nodemailer": "1.2.0", | ||
"eslint-config-prettier": "8.9.0", | ||
"eslint-config-prettier": "8.10.0", | ||
"js-yaml": "4.1.0", | ||
@@ -57,2 +57,3 @@ "license-report": "6.4.0", | ||
"punycode": "2.3.0", | ||
"undici": "5.23.0", | ||
"yargs": "17.7.2" | ||
@@ -59,0 +60,0 @@ }, |
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
16
271786
10
5265
+ Addedundici@5.23.0
+ Addedbusboy@1.6.0(transitive)
+ Addedstreamsearch@1.1.0(transitive)
+ Addedundici@5.23.0(transitive)