Skip to content

Commit 052be0b

Browse files
authored
2 parents 6bbdc35 + bd01ab3 commit 052be0b

File tree

5 files changed

+45
-19
lines changed

5 files changed

+45
-19
lines changed

.iyarc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
GHSA-3gc7-fjrx-p6mg
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Added a lightweight runtime guard for BigInt<->Buffer conversions in @bitgo/sdk-coin-sol (bigint-buffer-guard.ts) to validate input lengths and reduce misuse risk.
2+
// It's purpose is to enforce input type/length checks around BigInt buffer operations; imported it so validations run at module load
3+
4+
try {
5+
const mod = require('bigint-buffer');
6+
const le = typeof mod.toBigIntLE === 'function' ? mod.toBigIntLE : undefined;
7+
const be = typeof mod.toBigIntBE === 'function' ? mod.toBigIntBE : undefined;
8+
9+
const isBufferLike = (b: unknown) => (typeof Buffer !== 'undefined' && Buffer.isBuffer(b)) || b instanceof Uint8Array;
10+
11+
const byteLen = (b: any) =>
12+
typeof Buffer !== 'undefined' && Buffer.isBuffer(b) ? b.length : (b as Uint8Array).byteLength;
13+
14+
const assertBuf = (b: unknown) => {
15+
if (!isBufferLike(b)) throw new TypeError('toBigInt*: input must be Buffer/Uint8Array');
16+
if (byteLen(b as any) > 1_000_000) throw new RangeError('toBigInt*: buffer too large');
17+
};
18+
19+
if (le)
20+
mod.toBigIntLE = (buf: Buffer | Uint8Array) => {
21+
assertBuf(buf);
22+
return le(buf);
23+
};
24+
if (be)
25+
mod.toBigIntBE = (buf: Buffer | Uint8Array) => {
26+
assertBuf(buf);
27+
return be(buf);
28+
};
29+
} catch {
30+
/* noop */
31+
}

modules/sdk-coin-sol/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import './bigint-buffer-guard';
12
export * from './lib';
23
export * from './sol';
34
export * from './solToken';

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
"**/swarm-js/**/ws": "5.2.4",
100100
"serialize-javascript": "^6.0.2",
101101
"@grpc/grpc-js": "^1.12.6",
102+
"bigint-buffer": "npm:@trufflesuite/[email protected]",
102103
"request": "npm:@cypress/[email protected]",
103104
"**/avalanche/store2": "2.14.4",
104105
"webpack-dev-server": "5.2.1"
@@ -141,7 +142,8 @@
141142
"dependencies": {
142143
"axios": "^1.12.0",
143144
"terser": "^5.14.2",
144-
"tmp": "^0.2.3"
145+
"tmp": "^0.2.3",
146+
"bigint-buffer": "npm:@trufflesuite/[email protected]"
145147
},
146148
"packageManager": "[email protected]"
147149
}

yarn.lock

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7723,12 +7723,12 @@ [email protected], bigi@^1.1.0, bigi@^1.4.2:
77237723
resolved "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz"
77247724
integrity sha512-ddkU+dFIuEIW8lE7ZwdIAf2UPoM90eaprg5m3YXAVVTmKlqV/9BX4A2M8BOK2yOq6/VgZFVhK6QAxJebhlbhzw==
77257725

7726-
bigint-buffer@^1.1.5:
7727-
version "1.1.5"
7728-
resolved "https://registry.npmjs.org/bigint-buffer/-/bigint-buffer-1.1.5.tgz"
7729-
integrity sha512-trfYco6AoZ+rKhKnxA0hgX0HAbVP/s808/EuDSe2JDzUnCp/xAsli35Orvk67UrTEcwuxZqYZDmfA2RXJgxVvA==
7726+
bigint-buffer@^1.1.5, "bigint-buffer@npm:@trufflesuite/[email protected]":
7727+
version "1.1.10"
7728+
resolved "https://registry.npmjs.org/@trufflesuite/bigint-buffer/-/bigint-buffer-1.1.10.tgz#a1d9ca22d3cad1a138b78baaf15543637a3e1692"
7729+
integrity sha512-pYIQC5EcMmID74t26GCC67946mgTJFiLXOT/BYozgrd4UEY2JHEGLhWi9cMiQCt5BSqFEvKkCHNnoj82SRjiEw==
77307730
dependencies:
7731-
bindings "^1.3.0"
7731+
node-gyp-build "4.4.0"
77327732

77337733
77347734
version "3.1.4"
@@ -7784,13 +7784,6 @@ binaryextensions@^4.16.0:
77847784
resolved "https://registry.npmjs.org/binaryextensions/-/binaryextensions-4.19.0.tgz"
77857785
integrity sha512-DRxnVbOi/1OgA5pA9EDiRT8gvVYeqfuN7TmPfLyt6cyho3KbHCi3EtDQf39TTmGDrR5dZ9CspdXhPkL/j/WGbg==
77867786

7787-
bindings@^1.3.0:
7788-
version "1.5.0"
7789-
resolved "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz"
7790-
integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==
7791-
dependencies:
7792-
file-uri-to-path "1.0.0"
7793-
77947787
bip174@=2.1.1, bip174@^2.1.1:
77957788
version "2.1.1"
77967789
resolved "https://registry.npmjs.org/bip174/-/bip174-2.1.1.tgz"
@@ -11694,11 +11687,6 @@ file-loader@^6.2.0:
1169411687
loader-utils "^2.0.0"
1169511688
schema-utils "^3.0.0"
1169611689

11697-
11698-
version "1.0.0"
11699-
resolved "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz"
11700-
integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==
11701-
1170211690
filelist@^1.0.4:
1170311691
version "1.0.4"
1170411692
resolved "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz"
@@ -15742,6 +15730,11 @@ [email protected]:
1574215730
dependencies:
1574315731
detect-libc "^2.0.1"
1574415732

15733+
15734+
version "4.4.0"
15735+
resolved "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.4.0.tgz#42e99687ce87ddeaf3a10b99dc06abc11021f3f4"
15736+
integrity sha512-amJnQCcgtRVw9SvoebO3BKGESClrfXGCUTX9hSn1OuGQTQBOZmVd0Z0OlecpuRksKvbsUqALE8jls/ErClAPuQ==
15737+
1574515738
node-gyp-build@^4.2.0, node-gyp-build@^4.3.0:
1574615739
version "4.8.4"
1574715740
resolved "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.4.tgz"

0 commit comments

Comments
 (0)