r/netsec • u/fagnerbrack • 6d 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/
60
Upvotes
9
u/ef4 6d ago
IMO trying to maintain constant time behavior in a high level interpreted language is a fools errand. It’s hard enough in lower level languages, where the compiler may still fight you over it if you aren’t really careful.
6
u/SirensToGo 6d ago
I don't think what the author is trying to do is even possible today.
Even if you're able to convince the runtime to execute your JS without branching against secrets, etc., this does not bind the hardware. Intel CPUs require you set DOITM and ARM requires setting DIT, otherwise the hardware is free to use optimizations which may make classically "safe" integer operations (i.e.
b = a & 1) have data-depending latency.To make this work, I think you'd need an extension to JavaScript which lets you write constant-time code. This would give you some sort of contract with the runtime that it won't make certain unsafe transformations and that the runtime will set any applicable hardware bits. This would get messy though as DOITM, DIT, and whatever RISC-V/random other ISAs have cooked up are not exactly one-to-one and so what is safe is kinda...hard to determine.
1
u/grumpy_pcap 6d ago
TIL in V8 even true and false don't share a cache line, and "stop using booleans" is the most JavaScript sentence ever written about cryptography. The scary part is the load instruction is identical and only the data address differs, so an instruction-trace checker would have happily stamped this constant-time.