From c8275d890dde0cff2afdaecc6c73a4c74dc4abc7 Mon Sep 17 00:00:00 2001 From: "Bao, Huang-Huang" Date: Thu, 4 Feb 2021 10:50:26 +0800 Subject: [PATCH] fix: add custom certificate validation to pixiv-got (#6830) Fixes #6584 --- lib/routes/pixiv/pixiv-got.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/routes/pixiv/pixiv-got.js b/lib/routes/pixiv/pixiv-got.js index b74345884..0fd73f9e9 100644 --- a/lib/routes/pixiv/pixiv-got.js +++ b/lib/routes/pixiv/pixiv-got.js @@ -1,3 +1,4 @@ +const tls = require('tls'); const ipRegex = require('ip-regex'); const got = require('@/utils/got'); const logger = require('@/utils/logger'); @@ -20,7 +21,7 @@ async function dohResolve(name, jsonDohEndpoint) { return response.data.Answer.map((item) => item.data); } } catch (e) { - logger.error(`Failed to resolve ${pixivConfig.bypassCdnHostname}`); + logger.error(`Failed to resolve ${name}`); logger.debug(e); } return []; @@ -46,11 +47,15 @@ const pixivGot = got.extend({ } } if (hostname) { + const actualHost = options.url.host; options.headers = { ...options.headers, - host: options.url.host, + host: actualHost, }; options.url.hostname = hostname; + options.checkServerIdentity = function (host, certificate) { + return tls.checkServerIdentity(actualHost, certificate); + }; } }, ],