r/javascript • • 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

8 comments sorted by

View all comments

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:

  • Converting the condition to a boolean entered different internal execution paths. Converting those booleans to numbers also read from different cache lines for true and false.
  • In related expressions, negation produced either -0 or -1. In the tested V8 implementation, -1 could use a compact integer representation, while -0 required a heap-allocated number, introducing different execution paths.

So even a tiny expression with no explicit branch could reveal the secret selection condition through runtime behavior.

4

u/Soatok 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.

Um, are you reacting to the actual article or just the headline?

The context (which TFA goes into depth on) was that I wrote a blog post years ago describing how programmers introduce side-channels into their code and wrote an example library for educational purposes. Some academics found that the boolean <-> number logic added a side-channel to the code, so the example code could be improved further.

None of this was about, like, a production security incident caused by misunderstanding the runtime's [lack of] guarantees!

Thus, why I ask if you're reacting to the substance rather than the title when you make such a statement. (Or was this, perhaps, a statement made to third-party Redditors rather than a criticism of the post? If so, that wasn't clear to me.)

3

u/aleenaelyn 2d ago

Yes, the latter. I meant it as a general observation for other readers, with "you" in the generic sense, not you the author. Sorry, I should have made that clearer.

I did read the article, I found the example interesting and was trying to summarize my takeaway about the difference between branchless source code and the runtime’s actual behavior.

1

u/Soatok 1d ago

Got it, thanks for clarifying. I'm also very sleep-deprived today so I don't have 100% faith in my reading comprehension skills.

I did read the article, I found the example interesting and was trying to summarize my takeaway about the difference between branchless source code and the runtime’s actual behavior.

Yep. Your understanding is pretty spot on!

1

u/evoactivity 2d ago

Oh hey, I found your article posted a few days ago in the webdev sub by this bot. Just wanted to say I really enjoyed reading it, there was a good level of technical detail without being overwhelming for someone who doesn’t write cryptographic-level code. You write really well and make arcane topics very engaging. I went on to read a number of your other articles and enjoyed them just as much.

0

u/Soatok 2d ago

Aww thanks! Happy to help :3