From 591936e2a416a50b5d07708e0feebf97dc1f4b8c Mon Sep 17 00:00:00 2001 From: MrNanko Date: Sun, 8 Mar 2026 15:27:32 +0800 Subject: [PATCH] fix: validate cookie/url before setCookie to prevent tough-cookie [object Object] error --- Env.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Env.js b/Env.js index d2ed4cbfd..c7bb988c5 100644 --- a/Env.js +++ b/Env.js @@ -415,15 +415,25 @@ function Env(name, opts) { this.got(request) .on('redirect', (resp, nextOpts) => { try { - if (resp.headers['set-cookie']) { - const ck = resp.headers['set-cookie'] - .map(this.cktough.Cookie.parse) - .toString() - if (ck) { - this.ckjar.setCookieSync(ck, null) + const currentUrl = + resp.url || + resp.request?.requestUrl || + resp.request?.options?.url || + nextOpts.url + const setCookie = resp.headers?.['set-cookie'] + const cookieList = Array.isArray(setCookie) + ? setCookie + : [setCookie] + for (const ck of cookieList) { + try { + if (ck && currentUrl) { + this.ckjar.setCookieSync(ck, String(currentUrl)) + } + } catch (e) { + this.logErr(e) } - nextOpts.cookieJar = this.ckjar } + nextOpts.cookieJar = this.ckjar } catch (e) { this.logErr(e) }