Replies: 3 comments
-
Beta Was this translation helpful? Give feedback.
This comment was marked as spam.
This comment was marked as spam.
-
|
I think Option B (Version-stamped caching) is much more robust for the long run, especially if Node.js decides to support more dynamic OpenSSL provider loading in the future. Removing the cache entirely might cause performance regressions if someone calls getCiphers() inside heavy loops, so version-stamping strikes the perfect balance. By the way, I've been experimenting with high-performance cryptography core structures and alternative setups that combine C++ native execution with crypto-js and python environments to handle data masking without hitting these environment-specific caching limits. If anyone wants to take a look at how I structured the cloud-optimized computation flow, feel free to check out my repo: Would love to see a version-stamped cache PR merged for this issue! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
The
crypto.getCiphers(),crypto.getHashes(), andcrypto.getCurves()functions use acachedResult()wrapper fromlib/internal/util.jsthat caches results permanently after the first call. This means that if the OpenSSL state changes (viacrypto.setFips(),crypto.setEngine(), or loading OpenSSL providers), subsequent calls return stale, incorrect data.The Problem
In
lib/internal/crypto/util.js, these are defined as:And
cachedResult()is a simple one-shot memoizer:Once
resultis populated, it never refreshes, even when the underlying OpenSSL state has changed.Reproduction
Proposed Solution
Add an invalidation mechanism to
cachedResult(), and call it fromsetFips()andsetEngine():Option A: Add a
reset()method tocachedResult()Then in
setEngine()/ the FIPS setter:Option B: Version-stamped caching (more robust)
Questions for the Community
reset()vs. version-stamped caching vs. just removing the cache entirely?setFips()andsetEngine()that should trigger cache invalidation?Context
I discovered this while investigating the crypto internals. I'm happy to submit a PR with the fix if there's consensus on the approach.
Affected APIs:
crypto.getCiphers()crypto.getHashes()crypto.getCurves()Root cause location:
lib/internal/util.js#L348-L355—cachedResult()implementationlib/internal/crypto/util.js#L126-L128— usage ofcachedResult()Beta Was this translation helpful? Give feedback.
All reactions