Skip to content

v2.23.1 - #1784

Merged
prafull-opensignlabs merged 1 commit into
stagingfrom
updates-15419310132
Jun 3, 2025
Merged

v2.23.1#1784
prafull-opensignlabs merged 1 commit into
stagingfrom
updates-15419310132

Conversation

@nxglabs

@nxglabs nxglabs commented Jun 3, 2025

Copy link
Copy Markdown
Collaborator

Enable widget placement on click in desktop view
Disable signature types not working
Change icon of agreement sign checkbox
Disable Notify on Signature not working
Update dependencies

Enable widget placement on click in desktop view
Disable signature types not working
Change icon of agreement sign checkbox
Update dependencies
@vercel

vercel Bot commented Jun 3, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
open-sign ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 3, 2025 1:56pm

const raw = randomBytes[0]; // 0 … 4 294 967 295

// 2. Collapse into a 90 000 000-wide band (0…89 999 999), then shift to 10 000 000…99 999 999
const eightDigit = 10_000_000 + (raw % 90_000_000);

Check failure

Code scanning / CodeQL

Creating biased random numbers from a cryptographically secure source

Using modulo on a [cryptographically secure random number](1) produces biased results.

Copilot Autofix

AI about 1 year ago

To fix the issue, we need to ensure that the random ID generation is unbiased. This can be achieved by discarding values that would introduce bias, as demonstrated in the background example. Specifically, we will discard any random value greater than or equal to the largest multiple of the divisor (90,000,000) that fits within the range of raw (4,294,967,295). This ensures that the modulo operation is applied to a uniformly distributed range.

The fix involves modifying the randomId function to include a loop that discards biased values and only uses unbiased random values for the modulo operation. No new dependencies are required, as the existing crypto.getRandomValues API is sufficient.


Suggested changeset 1
apps/OpenSign/src/constant/Utils.jsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/apps/OpenSign/src/constant/Utils.jsx b/apps/OpenSign/src/constant/Utils.jsx
--- a/apps/OpenSign/src/constant/Utils.jsx
+++ b/apps/OpenSign/src/constant/Utils.jsx
@@ -685,8 +685,14 @@
 export const randomId = () => {
-  // 1. Grab a cryptographically-secure 32-bit random value
-  const randomBytes = crypto.getRandomValues(new Uint32Array(1));
-  const raw = randomBytes[0];          // 0 … 4 294 967 295
+  const divisor = 90_000_000;
+  const rangeLimit = Math.floor(4_294_967_295 / divisor) * divisor; // Largest multiple of divisor within range
+  let raw;
 
-  // 2. Collapse into a 90 000 000-wide band (0…89 999 999), then shift to 10 000 000…99 999 999
-  const eightDigit = 10_000_000 + (raw % 90_000_000);
+  // Loop until we get an unbiased random value
+  do {
+    const randomBytes = crypto.getRandomValues(new Uint32Array(1));
+    raw = randomBytes[0];
+  } while (raw >= rangeLimit);
+
+  // Collapse into a 90 000 000-wide band (0…89 999 999), then shift to 10 000 000…99 999 999
+  const eightDigit = 10_000_000 + (raw % divisor);
 
EOF
@@ -685,8 +685,14 @@
export const randomId = () => {
// 1. Grab a cryptographically-secure 32-bit random value
const randomBytes = crypto.getRandomValues(new Uint32Array(1));
const raw = randomBytes[0]; // 0 … 4 294 967 295
const divisor = 90_000_000;
const rangeLimit = Math.floor(4_294_967_295 / divisor) * divisor; // Largest multiple of divisor within range
let raw;

// 2. Collapse into a 90 000 000-wide band (0…89 999 999), then shift to 10 000 000…99 999 999
const eightDigit = 10_000_000 + (raw % 90_000_000);
// Loop until we get an unbiased random value
do {
const randomBytes = crypto.getRandomValues(new Uint32Array(1));
raw = randomBytes[0];
} while (raw >= rangeLimit);

// Collapse into a 90 000 000-wide band (0…89 999 999), then shift to 10 000 000…99 999 999
const eightDigit = 10_000_000 + (raw % divisor);

Copilot is powered by AI and may make mistakes. Always verify output.
@prafull-opensignlabs
prafull-opensignlabs merged commit dcbde2b into staging Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants