denoland/deno · error · ERR_OUT_OF_RANGE

ERR_OUT_OF_RANGE

ERR_OUT_OF_RANGE

Error message

The value of "info" is out of range. It must be must not contain more than 1024 bytes. Received ${received}

What it means

crypto.hkdf/hkdfSync validate the 'info' (context) parameter before derivation and reject it when it exceeds 1024 bytes (ext/node/polyfills/internal/crypto/hkdf.ts:85-91). This mirrors Node's HKDF guard, which exists because the OpenSSL-backed HKDF implementation feeds info into the HMAC in fixed-size chunks and Node fixes that chunk at 1024. salt is unbounded; only info carries this limit.

Source

Thrown at ext/node/polyfills/internal/crypto/hkdf.ts:86

  }
  // For strings / other BinaryLike, keep existing semantics (UTF-8 etc.)
  return Buffer.from(toBuf(x as unknown as string));
}

const validateParameters = hideStackFrames(
  (hash, key, salt, info, length) => {
    validateString(hash, "digest");
    key = prepareKey(key);
    validateByteSource(salt, "salt");
    validateByteSource(info, "info");

    salt = toRawBytes(toBuf(salt));
    info = toRawBytes(toBuf(info));

    validateInteger(length, "length", 0, kMaxLength);

    if (TypedArrayPrototypeGetByteLength(info) > 1024) {
      throw new ERR_OUT_OF_RANGE(
        "info",
        "must not contain more than 1024 bytes",
        TypedArrayPrototypeGetByteLength(info),
      );
    }

    validateAlgorithm(hash);

    const size = op_node_get_hash_size(hash);
    if (typeof size === "number" && size * 255 < length) {
      throw new ERR_CRYPTO_INVALID_KEYLEN();
    }

    return {
      hash,
      key,
      salt,
      info,

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Trim or shrink info to 1024 bytes or fewer - domain separation usually needs only a few bytes.
  2. Hash long context data first and pass its digest as info (e.g. info = createHash('sha256').update(bigContext).digest()).
  3. Move the overflow bytes into salt, which has no size limit, if they do not need to be authenticated as info.
  4. If you truly need unbounded context, pre-hash the context and bind it via the key material instead.

Example fix

// before
const info = Buffer.alloc(2048, 1);
crypto.hkdfSync('sha256', ikm, salt, info, 32); // ERR_OUT_OF_RANGE: info > 1024 bytes

// after
const info = Buffer.alloc(1024, 1);             // <= 1024 bytes
crypto.hkdfSync('sha256', ikm, salt, info, 32);
// or compress long context:
const info2 = crypto.createHash('sha256').update(longContext).digest();
Defensive patterns

Strategy: validation

Validate before calling

function assertHkdfInfo(info) {
  const bytes = Buffer.byteLength(
    typeof info === 'string' ? info : Buffer.from(info.buffer ?? info),
  );
  if (bytes > 1024) {
    throw new RangeError(`hkdf info must be <= 1024 bytes, got ${bytes}`);
  }
}
assertHkdfInfo(info);
crypto.hkdfSync('sha256', ikm, salt, info, 32);

Try / catch

try {
  okm = crypto.hkdfSync('sha256', ikm, salt, info, 32);
} catch (e) {
  if (e.code === 'ERR_OUT_OF_RANGE' && /info/.test(e.message)) {
    info = crypto.createHash('sha256').update(info).digest(); // compress context
    okm = crypto.hkdfSync('sha256', ikm, salt, info, 32);
  } else throw e;
}

Prevention

When it happens

Trigger: crypto.hkdfSync('sha256', ikm, salt, Buffer.alloc(1025), 32); passing a large context/label blob (e.g. a serialized object or certificate) as info; the same call via the async crypto.hkdf(...) with an oversized info buffer.

Common situations: Stuffing application metadata, nonces, or JWT-like claims into info; deriving keys from templates that concatenate domain-separation strings until they exceed 1 KiB; porting HKDF code from Go (golang.org/x/crypto/hkdf has no info limit) or from WebCrypto deriveBits (also no such limit).

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/a7f87c87b712b846. Report an issue: GitHub.