From 9a16c897145e81c6a2e9cad22b426effdf0ce4f6 Mon Sep 17 00:00:00 2001 From: cmachsocket Date: Mon, 14 Sep 2026 21:13:16 +0800 Subject: [PATCH 1/2] compatibility fix of rumtime and legacy node --- util/crypto.js | 5 +++-- util/request.js | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/util/crypto.js b/util/crypto.js index 6838fe1..0fa1695 100644 --- a/util/crypto.js +++ b/util/crypto.js @@ -151,7 +151,8 @@ const decrypt = (cipher) => { } const aesEcbEncrypt = (key, plaintext) => { - const cipher = crypto.createCipheriv(`aes-${key.length * 8}-ecb`, key, null) + // 某些运行时不允许使用 null 作为 IV,因此使用 Buffer.alloc(0) ,同时与上下文deriveX25519AesKey等函数保持一致 + const cipher = crypto.createCipheriv(`aes-${key.length * 8}-ecb`, key, Buffer.alloc(0)) return Buffer.concat([cipher.update(Buffer.from(plaintext)), cipher.final()]) } @@ -159,7 +160,7 @@ const aesEcbDecrypt = (key, ciphertext) => { const decipher = crypto.createDecipheriv( `aes-${key.length * 8}-ecb`, key, - null, + Buffer.alloc(0), ) return Buffer.concat([decipher.update(ciphertext), decipher.final()]) } diff --git a/util/request.js b/util/request.js index 55b6d2b..b6c9481 100644 --- a/util/request.js +++ b/util/request.js @@ -440,7 +440,11 @@ const createRequest = async (uri, data, options) => { !cookie.NMTID ) { NMTID_RETRIES_LEFT-- - answer.cookie = setCookies.map((x) => { + answer.cookie = ( + typeof res.headers['set-cookie'] === 'string' // node 20 版本以前,可能解析为String + ? [res.headers['set-cookie']] + : res.headers['set-cookie'] || [] + ).map((x) => { const cleaned = cleanCookie(x) const match = x.match(/(?:^|;\s*)NMTID=([^;]+)/) if (match) { From 77a9269828a3266efe49a300aeed236b05efb31a Mon Sep 17 00:00:00 2001 From: cmachsocket Date: Sat, 19 Sep 2026 21:31:39 +0800 Subject: [PATCH 2/2] fix lint --- util/crypto.js | 6 +++++- util/request.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/util/crypto.js b/util/crypto.js index 0fa1695..39f5feb 100644 --- a/util/crypto.js +++ b/util/crypto.js @@ -152,7 +152,11 @@ const decrypt = (cipher) => { const aesEcbEncrypt = (key, plaintext) => { // 某些运行时不允许使用 null 作为 IV,因此使用 Buffer.alloc(0) ,同时与上下文deriveX25519AesKey等函数保持一致 - const cipher = crypto.createCipheriv(`aes-${key.length * 8}-ecb`, key, Buffer.alloc(0)) + const cipher = crypto.createCipheriv( + `aes-${key.length * 8}-ecb`, + key, + Buffer.alloc(0), + ) return Buffer.concat([cipher.update(Buffer.from(plaintext)), cipher.final()]) } diff --git a/util/request.js b/util/request.js index b6c9481..11960ed 100644 --- a/util/request.js +++ b/util/request.js @@ -441,7 +441,7 @@ const createRequest = async (uri, data, options) => { ) { NMTID_RETRIES_LEFT-- answer.cookie = ( - typeof res.headers['set-cookie'] === 'string' // node 20 版本以前,可能解析为String + typeof res.headers['set-cookie'] === 'string' ? [res.headers['set-cookie']] : res.headers['set-cookie'] || [] ).map((x) => {