Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! crypto: validate this in all webcrypto methods and getters
  • Loading branch information
panva committed Apr 22, 2022
commit af7273bce4102d40edc6fb739daaca1dbf93657a
6 changes: 3 additions & 3 deletions lib/internal/crypto/webcrypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ async function deriveKey(
throw lazyDOMException('Unrecognized name.');
}

return this.importKey('raw', bits, derivedKeyAlgorithm, extractable, keyUsages);
return importKey.call(this, 'raw', bits, derivedKeyAlgorithm, extractable, keyUsages);
Comment thread
panva marked this conversation as resolved.
Outdated
}

async function exportKeySpki(key) {
Expand Down Expand Up @@ -574,7 +574,7 @@ async function importKey(
async function wrapKey(format, key, wrappingKey, algorithm) {
if (this !== subtle) throw new ERR_INVALID_THIS('SubtleCrypto');
algorithm = normalizeAlgorithm(algorithm);
let keyData = await this.exportKey(format, key);
let keyData = await exportKey.call(this, format, key);

if (format === 'jwk') {
if (keyData == null || typeof keyData !== 'object')
Expand Down Expand Up @@ -624,7 +624,7 @@ async function unwrapKey(
}
}

return this.importKey(format, keyData, unwrappedKeyAlgo, extractable, keyUsages);
return importKey.call(this, format, keyData, unwrappedKeyAlgo, extractable, keyUsages);
}

function signVerify(algorithm, key, data, signature) {
Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-webcrypto-constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,23 @@ const notSubtle = Reflect.construct(function() {}, [], SubtleCrypto);
name: 'TypeError', code: 'ERR_INVALID_THIS',
}).then(common.mustCall());
}

{
crypto.subtle.importKey(
'raw',
crypto.getRandomValues(new Uint8Array(4)),
'PBKDF2',
false,
['deriveKey']).then(key => {
crypto.subtle.importKey = common.mustNotCall();
return crypto.subtle.deriveKey({
name: 'PBKDF2',
hash: 'SHA-512',
salt: crypto.getRandomValues(new Uint8Array()),
iterations: 5
}, key, {
name: 'AES-GCM',
length: 256
}, true, ['encrypt', 'decrypt']);
}).then(common.mustCall());
}