mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
fix(crypto): hkdf callback should pass null (not undefined) on success (#23216)
## Summary
- Fixed crypto.hkdf callback to pass `null` instead of `undefined` for
the error parameter on success
- Added regression test to verify the fix
## Details
Fixes #23211
Node.js convention requires crypto callbacks to receive `null` as the
error parameter on success, but Bun was passing `undefined`. This caused
compatibility issues with code that relies on strict null checks (e.g.,
[matter.js](fdbec2cf88/packages/general/src/crypto/NodeJsStyleCrypto.ts (L169))).
### Changes
- Updated `CryptoHkdf.cpp` to pass `jsNull()` instead of `jsUndefined()`
for the error parameter in the success callback
- Added regression test in `test/regression/issue/23211.test.ts`
## Test plan
- [x] Added regression test that verifies callback receives `null` on
success
- [x] Test passes with the fix
- [x] Ran existing crypto tests (no failures)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
This commit is contained in:
@@ -97,7 +97,7 @@ void HkdfJobCtx::runFromJS(JSGlobalObject* lexicalGlobalObject, JSValue callback
|
||||
Bun__EventLoop__runCallback2(lexicalGlobalObject,
|
||||
JSValue::encode(callback),
|
||||
JSValue::encode(jsUndefined()),
|
||||
JSValue::encode(jsUndefined()),
|
||||
JSValue::encode(jsNull()),
|
||||
JSValue::encode(JSArrayBuffer::create(vm, globalObject->arrayBufferStructure(), buf.releaseNonNull())));
|
||||
}
|
||||
|
||||
|
||||
23
test/js/node/crypto/hkdf-callback-null.test.ts
Normal file
23
test/js/node/crypto/hkdf-callback-null.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import crypto from "node:crypto";
|
||||
|
||||
// Test that callback receives null (not undefined) for error on success
|
||||
// https://github.com/oven-sh/bun/issues/23211
|
||||
test("crypto.hkdf callback should pass null (not undefined) on success", async () => {
|
||||
const secret = new Uint8Array([7, 158, 216, 197, 25, 77, 201, 5, 73, 119]);
|
||||
const salt = new Uint8Array([0, 0, 0, 0, 0, 0, 0, 1]);
|
||||
const info = new Uint8Array([67, 111, 109, 112, 114, 101, 115, 115, 101, 100]);
|
||||
const length = 8;
|
||||
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
crypto.hkdf("sha256", secret, salt, info, length, (error, key) => {
|
||||
// Node.js passes null for error on success, not undefined
|
||||
expect(error).toBeNull();
|
||||
expect(error).not.toBeUndefined();
|
||||
expect(key).toBeInstanceOf(ArrayBuffer);
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
|
||||
await promise;
|
||||
});
|
||||
@@ -1,8 +1,7 @@
|
||||
// https://github.com/oven-sh/bun/issues/23183
|
||||
// Test that accessing process.title doesn't crash on Windows
|
||||
import { test, expect } from "bun:test";
|
||||
import { bunExe, bunEnv, isWindows } from "harness";
|
||||
import { join } from "path";
|
||||
import { expect, test } from "bun:test";
|
||||
import { bunEnv, bunExe, isWindows } from "harness";
|
||||
|
||||
test("process.title should not crash on Windows", async () => {
|
||||
const proc = Bun.spawn({
|
||||
|
||||
Reference in New Issue
Block a user