Skip to content

bigint is large

bigintIsLarge is a built‑in scan rule that detects bigint values whose bit‑length exceeds a conservative structural safety threshold.

It computes the bit‑length of the value by converting it to a binary string. When the observed bit‑length exceeds 2048 bits, the rule emits a warn‑level bigint.is.large scan event containing the measured and allowed bit‑length. If the value is not a bigint or does not exceed the threshold, no events are emitted.

Signature

export const bigintIsLarge: ScanRule (raw: unknown, path: FieldPath) => JaneEvent[]

Events

Event code Description
bigint.is.large bigint bit‑length exceeded the safe threshold.

Design rationale

  • Detects extremely large bigint values that may indicate malformed or adversarial input.
  • Uses a binary string conversion to compute bit‑length deterministically.
  • Emits a warning when the bit‑length exceeds the conservative limit (2048 bits).
  • Helps prevent downstream serializers, parsers, or validators from encountering oversized numeric values.
  • Provides size metadata ({ bitLength, maxBits }) for policy and analysis.
  • Performs no mutation or transformation of the input.

Invoke

bigintIsLarge runs automatically whenever the scan stage is enabled.

Activation methods:

  • Enable scan explicitly: jane.value(input).scan().
  • Use a mode that enables scan:
  • strict() enables scan by default.
  • moderate() and lax() do not enable scan unless .scan() is called.
  • Enable scan with policy: jane.value(input).withPolicy({ mode: 'strict' }).

If scan is not enabled or the value is not a bigint, bigintIsLarge does not run and no bit‑length detection occurs.

Examples

Large bigint detected

const huge = 2n ** 3000n;
const result = bigintIsLarge(huge, "$");
// → [ JaneEvent{ kind: "warn", code: "bigint.is.large", ... } ]

Bigint within safe bit‑length

const result = bigintIsLarge(123n, "$");
// → []

Non‑bigint value

const result = bigintIsLarge("123", "$");
// → []