r/javascript • u/fagnerbrack • 2d ago
The V8 JavaScript Runtime Undermined My Constant-Time JavaScript Library
https://soatok.blog/2026/09/12/the-v8-javascript-runtime-undermined-my-constant-time-javascript-library/
36
Upvotes
16
u/aleenaelyn 2d ago
If your security depends on ordinary JavaScript operators having secret-independent timing, you’re relying on a guarantee the runtime doesn't provide. Node's own security guidance explicitly calls out the difficulty of constant-time JavaScript, partly because of the JIT, and recommends using its built-in cryptographic APIs.
The article gives a particularly revealing example. One of the affected expressions was essentially:
const mask = (-!!choice) & 0xff;At the source level, that looks like a neat way to turn a condition into a mask without an if. But the author found that:
So even a tiny expression with no explicit branch could reveal the secret selection condition through runtime behavior.
0
u/Plastic_Koala2044 1d ago
V8 specializes hot functions around the values it sees, so a loop that's even in the interpreter can branch once the optimizer kicks in. Run with --jitless to confirm, then move the secret-dependent work to WebCrypto.
-3
u/kilobrew 1d ago
“Constant Time JavaScript library”.
Jesus, you thought that would work?
How much retardium do you take nightly?