Skip to content

Fix OpenSSL object leaks on error paths in key conversion - #220

Open
djw8605 wants to merge 1 commit into
scitokens:masterfrom
djw8605:fix/openssl-error-leaks
Open

Fix OpenSSL object leaks on error paths in key conversion#220
djw8605 wants to merge 1 commit into
scitokens:masterfrom
djw8605:fix/openssl-error-leaks

Conversation

@djw8605

@djw8605 djw8605 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Problem

In the OpenSSL 3.x code paths of es256_from_coords(), rs256_from_coords(), and store_public_ec_key(), several objects were held as raw pointers and freed only on the success path:

  • the EVP_PKEY produced by EVP_PKEY_fromdata,
  • the OSSL_PARAM array from OSSL_PARAM_BLD_to_param / EVP_PKEY_todata,
  • the buffer allocated by EC_POINT_point2buf.

Every intervening failure throws UnsupportedKeyException — parameter-build failure, EVP_PKEY_fromdata failure, 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_ptr with 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

  • ctest unit, env_config, and monitoring suites pass (the suites exercise both the ES256 and RS256 conversion paths via the keycache tests).

🤖 Generated with Claude Code

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>
@djw8605 djw8605 added the ai-gen label Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant