Fix OpenSSL object leaks on error paths in key conversion - #220
Open
djw8605 wants to merge 1 commit into
Open
Conversation
In the OpenSSL 3.x code paths of es256_from_coords(), rs256_from_coords(), and store_public_ec_key(), the EVP_PKEY, OSSL_PARAM array, and point2buf buffer were raw pointers freed only on the success path. Any of the intervening failures that throw UnsupportedKeyException (parameter build failure, EVP_PKEY_fromdata failure, PEM serialization failure, EC point conversion failure) leaked them. These paths are reachable with malformed JWKS input, so a hostile or buggy issuer could leak memory on every validation attempt. Hold each object in a unique_ptr with the appropriate OpenSSL deleter, matching the style already used for the surrounding objects. No behavior change on the success path. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In the OpenSSL 3.x code paths of
es256_from_coords(),rs256_from_coords(), andstore_public_ec_key(), several objects were held as raw pointers and freed only on the success path:EVP_PKEYproduced byEVP_PKEY_fromdata,OSSL_PARAMarray fromOSSL_PARAM_BLD_to_param/EVP_PKEY_todata,EC_POINT_point2buf.Every intervening failure throws
UnsupportedKeyException— parameter-build failure,EVP_PKEY_fromdatafailure, PEM serialization failure, EC point conversion failure — and leaks whatever had been allocated up to that point. These paths are reachable with malformed JWKS content, so a hostile or buggy issuer can leak memory on every validation attempt.Fix
Hold each object in a
unique_ptrwith the appropriate OpenSSL deleter (EVP_PKEY_free,OSSL_PARAM_free,OPENSSL_free), matching the RAII style already used for the surrounding objects (EC_GROUP,EC_POINT,OSSL_PARAM_BLD,BIGNUMs). No behavior change on the success path; OpenSSL 1.x paths untouched.Testing
ctestunit, env_config, and monitoring suites pass (the suites exercise both the ES256 and RS256 conversion paths via the keycache tests).🤖 Generated with Claude Code