Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add comment, adjust pbkdf2 limits in Node crypto #737

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/node/internal/internal_assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function createAssertionError(
return error;
}

// Note: Intentionally not exported, use assert.ok() instead.
function assert(actual: unknown, message?: string | Error): asserts actual {
if (arguments.length === 0) {
throw new AssertionError({
Expand Down
9 changes: 7 additions & 2 deletions src/workerd/api/node/crypto_pbkdf2.c++
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ namespace workerd::api::node {
kj::Array<kj::byte> CryptoImpl::getPbkdf(kj::Array<kj::byte> password,
kj::Array<kj::byte> salt, uint32_t num_iterations, uint32_t keylen, kj::String name) {
// Should not be needed based on current memory limits, still good to have
JSG_REQUIRE(password.size() < INT32_MAX, RangeError, "Pbkdf2 failed: password is too large");
JSG_REQUIRE(salt.size() < INT32_MAX, RangeError, "Pbkdf2 failed: salt is too large");
JSG_REQUIRE(password.size() <= INT32_MAX, RangeError, "Pbkdf2 failed: password is too large");
JSG_REQUIRE(salt.size() <= INT32_MAX, RangeError, "Pbkdf2 failed: salt is too large");
// Note: The user could DoS us by selecting a very high iteration count. As with the Web Crypto
// API, intentionally limit the maximum iteration count.
JSG_REQUIRE(num_iterations <= 100000, DOMNotSupportedError,
"Pbkdf2 failed: iteration counts above 100000 are not supported (requested ",
num_iterations, ").");

const EVP_MD* digest = EVP_get_digestbyname(name.begin());
JSG_REQUIRE(digest != nullptr, TypeError, "Invalid Pbkdf2 digest: ", name,
Expand Down