mirror of
https://github.com/ONLYOFFICE/server.git
synced 2026-02-10 18:05:07 +08:00
[bug] Fix crash in getJwtHsKey; Uses validation approach from jsonwebtoken library
This commit is contained in:
@ -1108,13 +1108,18 @@ const jwtKeyCache = Object.create(null);
|
|||||||
/**
|
/**
|
||||||
* Gets or creates a cached symmetric key for JWT verification (HS256/HS384/HS512).
|
* Gets or creates a cached symmetric key for JWT verification (HS256/HS384/HS512).
|
||||||
* Caches crypto.KeyObject to avoid expensive key creation on every request.
|
* Caches crypto.KeyObject to avoid expensive key creation on every request.
|
||||||
* @param {string} secret - JWT symmetric secret
|
* Uses the same validation approach as jsonwebtoken library.
|
||||||
* @returns {crypto.KeyObject} Cached secret key object
|
* @param {string|Buffer} secret - JWT symmetric secret
|
||||||
|
* @returns {crypto.KeyObject|undefined} Cached secret key object, or undefined when secret is missing/invalid
|
||||||
*/
|
*/
|
||||||
function getJwtHsKey(secret) {
|
function getJwtHsKey(secret) {
|
||||||
let res = jwtKeyCache[secret];
|
let res = jwtKeyCache[secret];
|
||||||
if (!res) {
|
if (!res && secret != null) {
|
||||||
res = jwtKeyCache[secret] = crypto.createSecretKey(Buffer.from(secret, 'utf8'));
|
try {
|
||||||
|
res = jwtKeyCache[secret] = crypto.createSecretKey(typeof secret === 'string' ? Buffer.from(secret, 'utf8') : secret);
|
||||||
|
} catch {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user