mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
crypto: match algorithm names as ASCII
Reject non-ASCII equivalents of registered Web Crypto algorithm names. Skip the character scan when the input already uses the canonical name. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex PR-URL: https://github.com/nodejs/node/pull/66237 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh>
This commit is contained in:
1 parent
ab9a3f2b01
commit
78374c8af0
2 files changed
+34
No files matched your search
@@ -22,6 +22,7 @@ const {
|
||||
PromiseWithResolvers,
|
||||
SafeMap,
|
||||
SafeSet,
|
||||
StringPrototypeCharCodeAt,
|
||||
StringPrototypeToUpperCase,
|
||||
Symbol,
|
||||
TypedArrayPrototypeGetBuffer,
|
||||
@@ -794,6 +795,15 @@ function normalizeAlgorithm(algorithm, op) {
|
||||
if (canonicalName === undefined)
|
||||
throw lazyDOMException('Unrecognized algorithm name', 'NotSupportedError');
|
||||
|
||||
// Registered names are ASCII. Only check characters when case folding was
|
||||
// needed, so Unicode characters such as U+017F cannot match ASCII names.
|
||||
if (algName !== canonicalName) {
|
||||
for (let i = 0; i < algName.length; i++) {
|
||||
if (StringPrototypeCharCodeAt(algName, i) > 0x7f)
|
||||
throw lazyDOMException('Unrecognized algorithm name', 'NotSupportedError');
|
||||
}
|
||||
}
|
||||
|
||||
algName = canonicalName;
|
||||
const desiredType = registeredAlgorithms[algName];
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
|
||||
const assert = require('assert');
|
||||
const { subtle } = globalThis.crypto;
|
||||
|
||||
(async () => {
|
||||
const data = new Uint8Array(0);
|
||||
assert.deepStrictEqual(await subtle.digest('sha-256', data),
|
||||
await subtle.digest('SHA-256', data));
|
||||
for (const name of ['\u017fha-256', 'SHA-256\u0131']) {
|
||||
await assert.rejects(subtle.digest(name, data), { name: 'NotSupportedError' });
|
||||
assert.strictEqual(SubtleCrypto.supports('digest', name), false);
|
||||
}
|
||||
await assert.rejects(subtle.generateKey({ name: 'AE\u017f-GCM', length: 128 },
|
||||
false, ['encrypt']),
|
||||
{ name: 'NotSupportedError' });
|
||||
await assert.rejects(subtle.importKey('raw-secret', data, 'Argon2\u0131d',
|
||||
false, ['deriveBits']),
|
||||
{ name: 'NotSupportedError' });
|
||||
})().then(common.mustCall());
|
||||
Reference in new issue
Block a user