Replies: 2 comments
-
Beta Was this translation helpful? Give feedback.
0 replies
This comment was marked as spam.
This comment was marked as spam.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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